Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Did I phrase the subject right? What I need is a formula to computer the velocity of an object given a two-dimensional vector. An object is going +2 in the x direction and +3 in the y direction. How fast is it actually going with the x speed and y speed combined?

The unit of motion is not really relevant. It's actually a dot moving across a grid squares on a form. We can call it pixels per second, but I don't think it matters. I just need the formula for total velocity.

I'm thinking it has to do with the Pythagorean theorem somehow the same way distance is measured, but I can't figure it out. My best guess is
VB
V = Sqr((x^2) + (y^2))

Can someone confirm that for me? Thanks in advance.
Posted

Well, you need relative move (distance) and divide it by time:

Sqrt((x − x0)2 + (y − y0)2)/time

By definition, speed is a distance divided by time. :-)

You can always consider all the dynamics separately for any orthogonal coordinates like x and y (hope they are orthogonal) if you project all forces, coordinates, speeds and accelerations on these axis.

—SA
 
Share this answer
 
Comments
Kevnar 10-Jan-12 14:59pm    
So this is the same as I suggested above, assuming (x - x0) equates to the factor of 2, I'd given and (y - y0) equates to the factor of 3. The time component would be simply 1.
Sergey Alexandrovich Kryukov 10-Jan-12 16:36pm    
Sure, why not?
Now, you can just consider accepting the answer formally (green button); you can accept more then one -- thanks.
--SA
Sergey Alexandrovich Kryukov 10-Jan-12 22:15pm    
I mean... what? What am I talking about? time = 1 is absurd, unless you do it in some very exotic space. It the speed would be rather be 1. Just think about it. If the distance is 1 sm, speed is 1, of 10 sm, the speed is 10. Now, (drums....) the paradox: a point travels 5 sm, then another 5 sm. The speed is 5 on both segments, but now the distance = (5 + 5) sm = 10 sm, but according your "formula", the speed is 10, so 10 == 5, the proof complete.

Shame on you, back to school, big fat 1, failure.

Sorry!
--SA
Since there is no time component, you are looking for the magnitude of the vector. You can get it as follows:
VB.NET
M = Math.Sqrt(dx * dx + dy * dy)

"dx" stands for "delta x", or the x component of the vector. "dy" is "delta y". You can compute dx given any two x points:
VB.NET
dx = x1 - x2

Same goes for dy. If you really want a speed (not a velocity, as velocity is really just speed and direction), you divide the "M" (magnitude) by the amount of time it took to travel that distance.
 
Share this answer
 
Comments
Kevnar 10-Jan-12 14:55pm    
Isn't this the same as I suggested above? I'm just assuming the time is "1", as in 1 tick of the program's clock.

And yes, the velocity is inherent in the vector. (2 pixels / second on the x axis, and 3 pixels / second on the y). By this formula the velocity would be 3.60, no?
AspDotNetDev 10-Jan-12 16:06pm    
Not velocity... speed. If you wanted the velocity, you could multiply the speed by a unit vector derived from the original vector (that product would result in the original vector, but separating them out makes the speed and direction more clear).

And yes, this is the same as you had above, with some variables and terms renamed and clarified.
Sergey Alexandrovich Kryukov 10-Jan-12 16:38pm    
Difference between 'speed' and 'velocity' is just casuistic. You can consider vector speeds/accelerations of scalar, it depends on application; for example, friction force is defined by scalar speed, and conservative field like electrostatic or gravity -- the vector acceleration.
--SA
AspDotNetDev 10-Jan-12 16:56pm    
Yeah, vectors have lots of uses, but speed and velocity are well defined uses of vectors. They are different, and the difference is important, although perhaps the terminology is not strictly important to the OP (neither of us know that).
Kevnar 10-Jan-12 18:57pm    
Since the answers were pretty much the same, I accepted them both. Thanks for your help. The gravity and inertia have been implemented. Now I just have to figure out why the particles are getting flung out into space instead of falling into orbit around a source of gravity. ...Or maybe that's exactly what they're supposed to do. :-/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900