This course teaches how to install and configure Windows Server 2012 R2. It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Should be a simple 500 points for the geometry geeks in here.

I have a point located at a vector in 3D space. (X,Y,Z)

I have a "direction" for that vector kept in degrees/radians another vector (A,B,C)

I have a second point located in the distance (D,E,F)

I need the formulas to do the following:

1.) What is the distance between XYZ & DEF?

2.) What is the find the "angle" between XYZ and DEF (and thus define ABC so that XYZ is facing DEF).

3.) What is the formula to "move" the point XYZ "forward" a set amount (N) based on it's current "direction" (ABC)?

These aren't for school. I'm trying to do a simple 3D game, and sucked at Geometry 15 years ago. More will no doubt follow.

-Javin

I have a point located at a vector in 3D space. (X,Y,Z)

I have a "direction" for that vector kept in degrees/radians another vector (A,B,C)

I have a second point located in the distance (D,E,F)

I need the formulas to do the following:

1.) What is the distance between XYZ & DEF?

2.) What is the find the "angle" between XYZ and DEF (and thus define ABC so that XYZ is facing DEF).

3.) What is the formula to "move" the point XYZ "forward" a set amount (N) based on it's current "direction" (ABC)?

These aren't for school. I'm trying to do a simple 3D game, and sucked at Geometry 15 years ago. More will no doubt follow.

-Javin

The 'angle between' can be expressed as the vector <D-X, E-Y, F-Z>

So let's say the speed is 5 units per iteration. Then dist/5 gives the number of iterations that should be required so <X,Y,Z> at iteration 1 becomes <X + (D-X)*5/dist, Y + (E-Y)*5/dist, Z + (F-Z)*5/dist>

"Distance uses Euclid's formula dist = sqrt( (X-D)^2 + (Y-E)^2 + (Z-F)^2 )"

So the formula is:

D = Sqrt( (X-D)^2 + (Y-E)^2 + (Z-F)^2 )

I assume this is derived from the Pythagorean theorem? (A^2 + B^2 = C^2)

2.) What is the find the "angle" between XYZ and DEF (and thus define ABC so that XYZ is facing DEF).

"The 'angle between' can be expressed as the vector <D-X, E-Y, F-Z>"

That's not what I need. I need the angle of ABC to be in Degrees or Radians, as I stated here:

"I have a "direction" for that vector kept in degrees/radians another vector (A,B,C)"

Thus, the formula that follows wouldn't quite work. Though I'd imagine there's some quick conversion formulas that can take the ABC (in rad/deg, which means C isn't really important, since it's the "roll" angle) and convert it to a vector?

3.) What is the formula to "move" the point XYZ "forward" a set amount (N) based on it's current "direction" (ABC)?

"So let's say the speed is 5 units per iteration. Then dist/5 gives the number of iterations that should be..."

I'm pretty lost on this one.

Assuming I have my point of origin: XYZ

Assuming I have my current angel in Rad/Deg: ABC

Assuming I have a Speed: S

Assuming I have a "Time" traveled: T

What is the formula to find my new point: DEF

I made it easier for you. Trying to express a 3D angle requires two angles, the angle in the xy plane and the angle above the plane. Then you have complex trigonometry to get the angle and to get the movements.

Forget ABC. You have:

Point of origin (X,Y,Z)

Travel vector <D-X, E-Y, F-Z>

Speed S

Time T

Your new point will be (X + (D-X)*S*T/dist, Y + (E-Y)*S*T/dist, Z + (F-Z)*S*T/dist)

At some point during the travel, the rotation of, say, the X axis may change. If it changes, I no longer know what my "look at" point is with your method.

Travel vector <D-X, E-Y, F-Z> is simply expressing the angle in Cartesian coordinates instead of spherical

coordinates.

However, if you want it in spherical coordinates, here goes. Angle in xy plane (theta) is arctan((E-Y)/(D-X)). Angle above xy axis (phi) is arctan( (F-Z)/sqrt( (D-X)^2 + (E-Y)^2 ) )

And you just do than in reverse to get the travel vector back to plug into the equation for movement.

So for question 1 we have the same dist as before.

For question 2 we get the unit vector to face XYZ toward DEF.

<A,B,C> = <(D-X)/dist, (E-Y)/dist, (F-Z)/dist>

Now you just rotate <A,B,C> and (X,Y,Z) with your axis.

Question 3 then is that the position at time T with speed S is

(X + A*S*T, Y + B*S*T, Z + C*S*T)

theta = arctan((E-Y)/(D-X))

phi = arctan( (F-Z)/sqrt( (D-X)^2 + (E-Y)^2 ) )

I'm with OZO,

there are multiple ways of representing directions in 3-d.

We need to find out which representation will be most effective for Javin.

It sounds like this is some sort of flying game or first person shooter game?

We need a broader context to help more effectively.

Can any of the axes rotate? (i. x and y only like a land base game with shooting up as a possibility even jumping on buildings or ii. the z axis rotate like a flying game)

Will the origin be shifting also?

To start to answer your question #2.

"I have a "direction" for that vector kept in degrees"

and

"radians another vector (A,B,C)"

isn't really clear what you mean.

Apparently, (A, B, C) is a different kind of object than <D, E, F> or <X, Y, Z>

Considering this we need a different notation for (A, B, C) type objects to prevent confusion with vectors. I'm using < > for vectors and ( ) for A, B, C type objects.

The question is what kind of object is <A, B, C>?

In 3 dimensions, two angles are necessary and sufficient to represent direction.

Typically, one angle represents rotation in the xy plane. (A for example)

And another angle represnts lift. (B for example)

Then the length of the vector could be C. (or dropped entirely if the length is not important)

This is the spherical coordinates Tommy mentioned.

Interpretation: Direction Cosines #2

http://en.wikipedia.org/wiki/Direction_cosine

"More generally, direction cosine refers to the cosine of the angle between any two vectors."

This seems more likely what you're looking for based on

"I have a "direction" for that vector kept in degrees

radians another vector (A,B,C)"

In this interpretation, all 3 of A, B, C are angles.

On that page, x, y, z are used to represent i, j, k.

V = <v1, v2, v3> is much more akin to our

Q = <D, E, F> - <X, Y, Z> = < D-X, E - Y, Z - F>

The square root on the bottom is the distance calculated in question 1.

Looking strictly at "I have a "direction" for that vector kept in degrees or

radians another vector (A,B,C)"

makes me wonder if you're using "unitized" direction vectors.

Unitized means the length is 1.

i, j, k are standard unit vectors, but any vector with length 1 can be a direction vector.

Imagine a sphere with radius 1. And vectors which start at the center(not necessarily at the origin, in fact in our case, most likely centered at <X, Y, Z>) and ends somewhere on the sphere. These "direction vectors" will be direction vectors. Is this what your talking about?

In this case, C represents the angle of declination from the vertical. k= <0, 0, 1> in a vertical plane containing Q.

B represents angle from <0, 1, 0> to Q in plane containing Q and the y-axis.

A represents angle from <1, 0, 0> to Q in plane containing Q and the x-axis.

Compensating for the fact that Q is not intended to start from the origin needs to be another comment.

Realize that to use direction cosines effectively, you need to keep in mind the planes I just mentioned are based on Q and NOT the xy plane, yz plane or xz plane.

(At least as far as I can remember)

Also, consider an outside resource like

"Calculus and Analytic Geometry" by Stein & Barcellos.

I have fifth edition, which should be inexpensive. It's got a whole a chapter (plus) on 3 dimensional topics. I particularly like it because it starts with a section on drawing 3-d spheres, graphs, etc.

For what you're doing projections may be particularly important.

To project Q first onto an xy plane or yz plane, then calculate the angles may ultimately be simpler and more useful to work with.

Please, let us know if where on the right track.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

So it has arrived. Of course your program will round or truncate to the nearest integer when it goes to display, but store the vectors as doubles for the calculations so you don't get cumulative rounding error.