0
\$\begingroup\$

In a 3D environment I have an object with a displacement x that I know I need to traverse in a given time interval. I have the object's heading and elevation and I want to figure out the distance the object needs to travel on the x/y/z axis to move x units in the given direction. How can I calculate this? Are there two distinct ways to calculate it (using trigonometry or linear algebra)? Which way is the best in what scenarios?

EDIT: To clarify, I will make an analogy to a simple 2D scenario that is similar to the 3D scenario I'm working with. Let's say the object has an angle of 35 degrees from the x-axis. Making a right triangle, let's say we know that the hypotenuse (or displacement of the object) is 10 units. Now to figure out the x and y deltas to get from the object's current position to the object's new position 10 units away at a 35 degree angle, you simply do:

x = 10 * cos(35) 
y = 10 * sin(35)

I simply need to solve the same problem except in 3 dimensions.

\$\endgroup\$
7
  • \$\begingroup\$ Can you clarify what you're looking for? If you have the displacement from one object to another, that is the distance between them. \$\endgroup\$ Commented Sep 7, 2011 at 22:24
  • \$\begingroup\$ It would help greatly if you could draw a quick image in bitmap or something. Right now it's really hard to see what you want to calculate. \$\endgroup\$
    – TravisG
    Commented Sep 7, 2011 at 22:27
  • \$\begingroup\$ object's heading should be a vector, you only have to normalize it and then multiply it by whatever value you want your object to move. the result will be delta x/y/z \$\endgroup\$
    – Ali1S232
    Commented Sep 7, 2011 at 22:50
  • \$\begingroup\$ Because of spam prevention I cannot add a picture to the main post but here is a link to a picture that will hopefully clarify (@chaosTechinician and @heishe) screensnapr.com/e/rDZ95Y.png. @chaosTechnician the displacement is from the object's current position to a new position (which is known), I just need to figure out the distance that needs to be traveled on the x/y/z axis to get to the new position from the current. \$\endgroup\$
    – Matt
    Commented Sep 7, 2011 at 23:15
  • \$\begingroup\$ Axes are separable in classical mechanics and you can work with the x axis velocity independently of YZ. It's entirely possible I don't understand your entire problem, however. \$\endgroup\$ Commented Sep 7, 2011 at 23:25

4 Answers 4

3
\$\begingroup\$

Ok, I think I get what you're asking now...

If you have the 3D position of the target object (B) and your own position (A), the vector B - A is the 3D displacement to the target.

If you only have a bearing and an elevation to the target, you can get a vector that points at it but you can't determine how far away it is with only those angles. The components for that vector would be: x = cos(bearing) * cos(elevation); y = sin(bearing) * cos(elevation); z = sin(elevation); You may need to convert between degrees and radians and may need to add a constant to your bearing and/or elevation to properly line them up with the world axes.

If you have the bearing, elevation, and distance, multiply the vector components above by that distance.

\$\endgroup\$
5
  • \$\begingroup\$ This is probably what I was looking for but I something that you said allows me to explain exactly what I'm looking for. I don't actually have the 3D position of the "target object" (in the scenario I presented it's the single object's new position, but the math is the same). I want to be able to find the position (vector) of B and or the 3D displacement by using the known values of the bearing, elevation, and 2D displacement. \$\endgroup\$
    – Matt
    Commented Sep 8, 2011 at 1:00
  • \$\begingroup\$ What plane is the 2D displacement (distance) on? The XY plane? \$\endgroup\$ Commented Sep 8, 2011 at 1:01
  • \$\begingroup\$ Sorry I messed that up there, it's technically 1D displacement, it's just a distance in units from one position to the target position. So it isn't on any plane. \$\endgroup\$
    – Matt
    Commented Sep 8, 2011 at 1:16
  • \$\begingroup\$ So you have the bearing, elevation, and distance between them? The last sentence in my answer addresses that. \$\endgroup\$ Commented Sep 8, 2011 at 1:21
  • \$\begingroup\$ @Matt: I made a final edit to the calculations above. To get an accurate distance, the elevation is needed in the x and y calculations. \$\endgroup\$ Commented Sep 8, 2011 at 3:01
2
\$\begingroup\$

accoring to your changes I can assume you have two angles, one that I call theta which is just like the one you have in 2d plane and has some value between -pi -> +pi. and you have a second angle called (let's call this one phi) and it has some value between -pi/2 -> pi/2. you can see in the picture what are these angles exactly specifying.

enter image description here

using these 2 angles you can compute normal 3d vector using this formula :

 x = cos(theta) * cos(phi);
 y = sin(theta) * cos(phi);
 z = sin(phi);
\$\endgroup\$
0
\$\begingroup\$

Things simplify considerably if you're willing to use quaternions.

In this case you have to simply store a "direction" unit vector(D) and an "upside" unit vector(U). Optionally you can store the "right" unit vector that points to the right direction (R) or you can compute doing the cross product (D x U).

When you want to change your pitch or bearing or orientation you simply have to construct a quaternion using the right vector and multiply the other two for that quaternion.

With this strategy you can store a "direction" vector that even points where you are going and rotate without the problem you may encounter if you touch some nasty rotation pole.

[EDIT]

Quaternions are 4-tuple of real numbers that represent a real part and the coefficients for tree orthogonal imaginary parts i, j, k. A quaterion may be write as (s,v) where s is the real part and v is the imaginary 3D vector.

A point in 3D (p) may be represented as the quaternion (0,p) and the rotation of θ rads about the r unit vector is: q = (s,v) where s = cos(θ/2) and v is r·sin(θ/2).

now p* = q · p · q' is the rotated point where q' is the inverse of q.

The inversion of a unit quaternion equals its conjugate so q' = (s, -v)

The quaternion multiplication shows a little complexity: while the a quaternion can be written as q = w + x i +y j +z k thus p · q is a simple polinomial multiplication, there are the relations so:

complex relations

we can say that a multiplication between quaternion can be written as:

general quaternion multiplication

this lead us to the conclusion that if q1 is the vector Q = [W1, X1, Y1, Z1] then

matrix form

so q1 · q2 = Q · A in term of matrix multiplications.

You can see that a rotation using a quaternion involves 32 multiplications and 24 sums Vs the 9 multiplications and 6 sums for the rotation using the standard matrix rotations.

This difference is due to the fact that a fourth dimension is used to avoid the pole problem that often makes the matrix rotation unviable: the euclideans matrix rotations is not faster, it simply compute less things and you pay this if you pass through a pole.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for the response, I was interested in seeing alternatives to the trigonometry method. When it comes down to pros and cons of each method it would seem that using quaternions simplifies the math and avoids the problem with rotation poles that you mentioned. But I also have to consider the overhead that would come with using the abstraction of a Quaternion class as opposed to accessing an array of precomputed sin values. For simulations that may have thousands of moving objects, would you say that the quaternion method may lose out on computational speed? \$\endgroup\$
    – Matt
    Commented Sep 12, 2011 at 3:08
  • \$\begingroup\$ @matt please see if my edit helps you in this sense \$\endgroup\$
    – FxIII
    Commented Sep 12, 2011 at 11:13
  • \$\begingroup\$ @matt "accessing an array of precomputed sin values" DO NOT use a LUT for basic trig, your cache will hate you. \$\endgroup\$
    – Khlorghaal
    Commented Mar 22, 2016 at 21:24
0
\$\begingroup\$

If you don't want do deal with some nasty trig functions, try parametrizing the movements on each axis. For example, imagine an object moving in a vector (variably scaled) of <1,2,3> for 2 seconds at 3 meters per second. Define the units of each axis as one meter. x=t y=2t z=3t Continue time to find where the object would be at t seconds. To find velocity, differentiate each parametric for a velocity vector. For a projectile, z would usually be something like -9.8t^2+t+20 and that projectile's velocity vector would be scalars for x and y and a linear with t for z. I personally like this better because differentiation is more intuitive, but 3D polars are good for some things too

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .