Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given start point, angles in each rotational axis and a direction, calculate end point

I have a start point in 3D coordinates, e.g. (0,0,0).

I have the direction I am pointing, represented by three angles - one for each angle of rotation (rotation in X, rotation in Y, rotation in Z) (for the sake of the example let's assume I'm one of those old logo turtles with a pen) and the distance I will travel in the direction I am pointing.

How would I go about calculating the end point coordinates?

I know for a 2D system it would be simple:

new_x = old_x + cos(angle) * distance
new_y = old_y + sin(angle) * distance

but I can't work out how to apply this to 3 dimensions

I suppose another way of thinking about this would be trying to find a point on the surface of a sphere, knowing the direction you're pointing and the sphere's radius.

like image 204
Nick Udell Avatar asked Jan 10 '11 00:01

Nick Udell


3 Answers

First of all, for positioning a point in 3D you only need two angles (just like you only needed one in 2D)

Secondly, for various reasons (slow cos&sin, gimbal lock, ...) you might want to store the direction as a vector in the first place and avoid angles alltogether.

Anyway, Assuming direction is initially z aligned, then rotated around x axis followed by rotation around y axis.

x=x0 + distance * cos (angleZ) * sin (angleY)

Y=y0 + distance * sin (Anglez)

Z=z0 + distance * cos (angleZ) * cos (angleY)

like image 177
Kris Van Bael Avatar answered Sep 18 '22 05:09

Kris Van Bael


Based in the three angles you have to construct the 3x3 rotation matrix. Then each column of the matrix represents the local x, y and z directions. If you have a local direction you want to move by, then multiply the 3x3 rotation with the direction vector to get the result in global coordinates.

I made a little intro to 3D coordinate transformations that I think will answer your question.

3D Coordinates

3D coordinates

like image 28
John Alexiou Avatar answered Sep 20 '22 05:09

John Alexiou


First, it is strange to have three angles to represent the direction -- two would be enough. Second, the result depends on the order in which you turn about the respective axes. Rotations about different axes do not commute.

Possibly you are simply looking for the conversion between spherical and Cartesian coordinates.

like image 23
Sven Marnach Avatar answered Sep 20 '22 05:09

Sven Marnach