Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this