get the angle (x,y,z) from the center of a line in 3d (vector)?

This topic is 3825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I search for the mathematical expression to get the rotation angles (x,y,z) from a point on a line in 3d. I create a line with begin point (x,y,z) and end point (x,y,z) in 3d space. Then i position a cylinder always on that line and in the half of the lenght of that line. begin point = bp end point = ep middle point = mp Xmp = (Xbp + Xep) / 2 Ymp = (Ybp + Yep) / 2 Zmp = (Zbp + Zep) / 2 Now i can position always the cylinder on the line and in the middle of the line. But i have to get also the rotation angles (x,y,z) from the line for the correct rotation of these cylinder. So that the begin point of that cylinder is always looking to the begin point from the line and the end point of that cylinder is always looking to the end point from the line. How to do these? Thanks for ideas, sollutions, ... I hope you understand my bad explanation but i am not good in math. :(

Share on other sites
Since you're working with cylinders, I'll assume that roll around the line doesn't matter (if it does then we can calculate that later).

You first need the vector from the start point to the end point, v = (end - start). From that you can calculate pitch and yaw:

yaw = atan2(v.y, v.x);
pitch = atan2(v.z, sqrt((v.x*v.x) + (v.y*v.y)));

The 'atan2' function is specific to C++, but in general what it does is find the arctangent while also disambiguating the quadrant based on the signs of the inputs, handle division-by-zero cases, etc. You can always write your own if you're working in a different language.

Finally, take those values and plug them into a rotation matrix, or find the axis-angle rotation for a quaternion, etc.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×