Math little problem

Started by
4 comments, last by jakaita 17 years, 9 months ago
Hello, I'm reviewing my math for the moment, but I'm stuck on this simple problem. The data at my disposal : My location inside a vector called Location. My direction inside a vector called Direction. The distance of the move called Distance How can I compute my new location based on those data : NewLocation = Location where I apply a move of Distance unit in the direction Direction. I know it's quite easy, but I really don't know how to do it :( Tx you for your help !
Advertisement
Is distance a scalar?

If so, the equation is exactly as you described:

NewLocation = location + distance * direction.
If you don't want to overload the + and * operators, it would be
for(int i=0;i<2;i++) NewLocation = Location + Distance * Direction;
Tx you for your help !

I suppose that my Direction vector must by normalized for working ?

Yes... assuming your vectors use floats. If they are ints, a normalized direction vector won't work too good.
If you're going to just multiply the distance by the Direction vector, yes, it must be normalized.

This topic is closed to new replies.

Advertisement