1. ## 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.

2. 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.

3. 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).

4. 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.

5. 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.

6. 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?

7. 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 )

8. Hrm, I still don't quite understand. What am I dividing it by? Please explain a bit more.

9. 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.

10. Wait a sec...who are you!? Stop confuting me!

11. Confuted == (Blackrat && a_name_change)

Still the same great (lousy) help.

12. 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.

13. 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.

14. Ok, so

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

where x, y and z are really x1-x2, y1-y2, and z1-z2 ?

15. yes.