10

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.

Nick Udell
  • 2,306
  • 5
  • 41
  • 81
  • What does 'rotation in x, rotation in y' mean? You can't rotate in one dimension - in two dimensions there's only 1 plane of rotation, and in 3D there are just 2 planes of rotation. – Kirk Broadhurst Jan 10 '11 at 00:28
  • @Kirk is right. Think this way: for representing a point in 3D you need 3 scalars (numbers). But you have 4 (3 angles and a distance). Something is superfluous ... – Dr. belisarius Jan 10 '11 at 00:34
  • Apologies, I'm still new to 3D coordinate systems. I have angles through these axes, as in Yaw(Y), Pitch(X) and Roll(Z). I should have made that cleared. – Nick Udell Jan 10 '11 at 13:47

3 Answers3

10

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)

Kris Van Bael
  • 2,812
  • 1
  • 16
  • 19
4

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

John Alexiou
  • 23,931
  • 6
  • 67
  • 123
2

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.

Sven Marnach
  • 483,142
  • 107
  • 864
  • 776