# calculating relative position in 3d space

#### jickso

So basically (as I understood), you're trying to find coordinates of cannon's tip, based on its roll, pitch, yaw and butt (serving as center of rotation)?

#### S33K3R

jickso said:
So basically (as I understood), you're trying to find coordinates of cannon's tip, based on its roll, pitch, yaw and butt (serving as center of rotation)?
Correct.

skipjack said:
Why don't you give the start position of the tip of the cannon's barrel as well as the start position of its butt?
Because that is the point in space I am trying to find -- it is the unknown.

The previous mention about the cannon was just an analogy to describe getting the coordinates of a fixed distance (D) away from for a fixed point in space (cannons butt) pointing in the direction (pitch,yaw,roll) that the cannon is looking. The formula would yield the coordinates (of the cannons tip). If this was a problem in a textbook it would probably read something like:

If a 10 meter cannon was suspending in mid air with the butt of the cannon sitting at coordinates (x1,y1,z1), and it was facing the angles pitch, yaw, roll (a,b,c) what would be the formula you would use to find the position of the cannons tip (x2,y2,z2)?

#### jickso

I see. :-D Well, it's a bit complicated, because of the relativity of the problem. First thing I observed is that roll doesn't actually change the position of the tip? It just rotates the "barrel" of the cannon around itself? Pitch would move tip up and down and yaw would move tip left and right? Now, what skipjack is trying to say is that (even if you don't know the position of the tip), you should set it as a fixed point first. When you run the application, or something. For example, set the butt of the cannon in (0,0,0) and tip of the cannon in (10,0,0). Then it's easier to observe rotation of the tip. Now, there are simple matrices for rotation, but it's easier to observe when the butt is in (0,0,0). Even if it isn't we can translate both tip and butt so that butt is (0,0,0), rotate tip around (0,0,0), then translate the cannon back. And yes, it should be simple to calculate using only sin, cos and Pythagoras's theorem. I will try to find a satisfactory formula in a few days (if skipjack doesn't do it first ), any further explanation would help.

#### jickso

I think it's something like this. If $$\displaystyle \alpha$$ is pitch and $$\displaystyle \beta$$ is yaw, then:

$$\displaystyle \begin{eqnarray*} \sin{\alpha}=\frac{z_t-z_b}{10},\\ \sin{\beta}=\frac{y_t-y_b}{10},\\ \tan{\beta}=\frac{y_t-y_b}{x_t-x_b}, \end{eqnarray*}$$

where $$\displaystyle (x_b,y_b,z_b)$$ are coordinates of the butt of the cannon, and $$\displaystyle (x_t,y_t,z_t)$$ are coordinates of the tip of the cannon. Hope this works, didn't check much if it was correct.

#### skipjack

Forum Staff
The problem seems similar to that of finding Cartesian coordinates for a point on the Earth's surface given by three angles. Why use three angles when, say, latitude and longitude (two angles) suffice? Of course, one isn't forced to choose those particular two angles.

#### jickso

Honestly, I have no idea what the third angle should represent. That's why I think roll is obsolete.

And I think my formulae aren't correct; I think that I forgot to translate the points back... I'll have to evaluate it again, but the reasoning is the same.

#### Raziel

Hi, I'm with a similar problem. How The autor manager this problem, anyone have a sugestion? I want to shift a 3d point, based on The roll, pitch and Yaw angles. Actually I have a 3d point where X and y are a 2d position, like latitude and longitude, and z is The height. I hhave this point, but i want to Project this point on The ground, based on roll, pitch and Yaw angles.