# 3D Vectors

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 08-12-2003
Azmeos
3D Vectors
Here's what I'm doing:

Moving a space ship from one point in space to another point in space at a constant speed.

Here's my question:

How do I calculate the per-second vector components of the x, y, and z directions? Ei. How do I know how much the spaceship moves in a direction(x,y, or z) per second? I know how to calculate the magnitude of the vector, but I am lost beyond that.
• 08-12-2003
FillYourBrain
if you know the angles you can do some trig, however you should probably use the translation vector with the magnitude in it multiplied by a (directional) rotation matrix.
• 08-12-2003
Azmeos
I guess I have to calculate the angles? I am given three pieces of information: The current coordinates, the desination coordinates, and the speed. For now, direction of the spaceship does not matter (assume it's a standard circular UFO).
• 08-12-2003
FillYourBrain
well then another method could be to calculate the unit vector in that direction. Then you just multiply that by the magnitude you're going to jump. That's probably a lot simpler for this purpose.
• 08-12-2003
confuted
A completely vector based system will work fine.

<newx,newy,newz>=<x2-x1,y2-y1,z2-z1>
Then normalize the new vector, and add it to the current position.

If, for some reason, you want to find the angle between the vector representing the direction it is going, and the vector representing some other direction, use a dot product.
• 08-12-2003
Azmeos
black - by normalizing do you mean to take the cross product?

fib - I don't quite catch what you mean. Could you explain a little furthur?
• 08-12-2003
Perspective
Quote:

Originally posted by Azmeos
black - by normalizing do you mean to take the cross product?
normalize means make the magnitude == 1. This can be done by dividing each component by the current magnatude.

magnitude = sqrt( x^2 + y^2 + z^2 )
• 08-12-2003
Azmeos
Hrm, I still don't quite understand. What am I dividing it by? Please explain a bit more.
• 08-12-2003
confuted
To normalize:

Code:

```magnitude = sqrt(x^2+y^2+z^2); x/=magnitude; y/=magnitude; z/=magnitude;```
This will ensure that the total length of the vector == 1.
• 08-12-2003
JaWiB
Wait a sec...who are you!? Stop confuting me!
• 08-12-2003
confuted
Confuted == (Blackrat && a_name_change)

Still the same great (lousy) help.
• 08-12-2003
Azmeos
I see. So, then I just multiply (or do I add??) those new values to the current coordinates? And we still have to deal with the issue of the speed. How does that come in? Just a multiplication? And what if the destination coord < current coord, negative values?

black/confuted - By the way, I'm a fellow Michigander, from Grand Rapids.
• 08-13-2003
confuted
add the normalized direction vector to the current position. It will work even for negative directions.

Speed will be constant with the namralized vector, regardless of direction. If you want to change this speed, add the normalized vector multiplied by an arbitrary constant k to the current coordinates.
• 08-13-2003
Azmeos
Ok, so

magnitude = sqrt(x^2+y^2+z^2);

where x, y and z are really x1-x2, y1-y2, and z1-z2 ?
• 08-13-2003
confuted
yes.