05-08-2018 09:59 AM
I have a project that needs me to build a crystalline network structures, I've built the code for placing the atoms at different distances based on the atom radius, now I need to create the plane based on the atoms coordinates. As such, I thought of using a cylinder, with a small radius and a height deducted from the 2 atoms it wants to unite in order to create a plane, I have to use translations to move the cylinder in between them and apply a rotation based on the X, Y and Z axis.
To explain the process, Lets say we have two points P1(1,1,1) and P2(3,3,3); First of all we find all the angles: x/square root(x^2+y^2) ; y/square root(y^2+z^2) and z/square root(z^2+x^2), we apply them and then we translate the object. When I've used the Rotate Z/X/Y axis vi 's they do rotate the object, but it turns out it comes back to the original rotation (I've rotated first then translated the position, also I've used relative coordinates);
Since I saw it didn't work, I thought why not try a different formula, and only spin on 2 axis, I've used something like Alpha = arc cos (x/square root(x^2+y^2)) and Beta = arc cos (square root(x^2+y^2)/square root(x^2+y^2+z^2)); Tho it did work for a few pairs of numbers, it was only because I've noticed the third rotation it needed was 0, for any other value it wouldn't rotate properly.
Also, I had to pay attention to the order I was spinning the objects, since the Cylinder is at first parallel with the OZ axis.
I've tried to find examples of how to use rotations in Lab view but I only managed to find basic examples, as of the formulas, I've tried to figure them out using basic trigonometry knowledge.
I would appreciate if somebody could explain how to properly rotate an object and how to find the angles from 2 points in 3D space.
I've attached a few snippets down bellow.
05-08-2018 09:02 PM
Oh, boy, Rotation Matrices! The only things that are more fun are Rotation Vectors and Quaternions!
Do you know how matrices work? In 3D, a matrix is generally written as a 3x3 Array, and "operates" on a Vector (written as a 3x1, or "column", array). Mathematicians write "Matrix M operates on Vector V" as M x V. The rules for Matrix multiplication are a little strange, and I won't go into it here, but this is the Matrix that rotates a Vector about the X axis:
| 1 0 0 |
M(a) = | 0 cos(a) sin(a) |
| 0 -sin(a) cos(a) |
It can easily be shown that M(a) will rotate a Vector about the X axis by the angle "a". There are similar rotation matrices M(b) and M(c) that rotate V about the Y and Z axes. Now, what happens when you rotate first about X, then about Y, then about Z? Work out M(b) * M(a), and notice it is not the same as M(a) * M(b). So the order you do rotations matters.
Note that all of these rotations are about the origin. What if you want to rotate about a different point, say about the point (x, y, z)? [Note -- I'm writing (column) vectors as rows as a convenience ...]. Simple, subtract (x, y, z) from the point you want to rotate (moving the point of rotation back to the Origin), rotate, then add (x, y, z) back to move back to where it began, but now rotated.
Lots of fun math. Lots to play with, experiment with, and learn. A few years/Versions ago, LabVIEW introduced a Matrix type which simplifies Matrix math (I think multiplication uses the Matrix Multiplication rules, so you don't have to worry so much about it). Think about what you want to do, use Matrix Math to do it for you.
Bob Schor
05-09-2018 02:17 AM
Thank you for your response, I will try to implement the rotations based on the rotation matrix. I'll comment back later when it'll be done.