calculating motion from angles

52 Views Asked by At

First, my apologies. This question may have been asked many times before but I do not know the correct terms to search on..... and my school trigonometry is many years ago. Pointing me to an appropriate already-answered question would be an ideal solution for me.

I am writing a program to do 3D view from an observer. I want to calculate motion based upon the direction the observer is looking. I currently define this as angle from directly ahead in two planes. Rotation about the x (left-right) axis gives me elevation (elevationRadians), and rotation about y (up-down) axis gives me left-right. Rotation about z never happens.

I need to calculate the change in cartesian coordinates caused by moving D units in the direction of view.

dx = D * cos(elevationRadians)
dy = D * sin(deflectionRadians)

But I now get two components for dz

dz = D * cos(deflectionRadians)
dz = D * sin(elevationRadians)

How should I combine these terms to give realistic movement? Should I add them, average them, or something else? Part of me thinks that simply adding them will give too large a dz. Could someone confirm, deny, or point me to a good resource for this please.......

Edit: rotation about y gives 'deflection..

My axes: x: left -> right, y: down -> up, z: behind -> in front.

Thanks to Andei's amswer which almost worked (I think our axes differed), I wound up with this:

dx = D cos(elevationRadians) cos(deflectionRadians) dy = D sin(elevationRadians) sin(deflectionRadians) dz = D sin(elevationRadians)

which seems to work a lot better than what I had.

What is the mathematical term for what I am trying to do? I need to read some theory preferably at the simple end of the scale.

2

There are 2 best solutions below

5
On BEST ANSWER

I think you don't define your axes correctly. You have rotation around $z$, and in the next sentence you say it never happens.

I think you should use polar coordinates. If you call $\theta$ the angle from the vertical direction $z$, $\theta=\pi/2-\text{elevationRadians}$, and $\phi=\text{deflectionRadians}$ is the angle that the projection in the horizontal plane makes with the $x$ axis, you have:$$\begin{align}x&=D\sin\theta\cos\phi\\y&=D\sin\theta\sin\phi\\z&=D\cos\theta\end{align}$$

4
On

I would look to solve this using utility methods contained in 3D Vectors. I'm not sure what you're using for creating the application, but I've found Unity 3D's documentation on 3D vector Math to be very easy to follow (regardless of whether you're working in Unity).

https://unity3d.com/learn/tutorials/topics/scripting/vector-maths

For example - in response to your specific question about the size of "dz" I would use the "normalize" method of a Vector3 which gives you a vector unit length of 1 and then scale this vector by whatever magnitude you need.