admin管理员组

文章数量:1415420

How would I go about converting an X and Y Velocity to one Velocity? I don't mean the angle just the velocity.

var velocityX = some velocity;
var velocityY = some velocity;

// Convert the two X and Y velocities to one velocity

How would I go about converting an X and Y Velocity to one Velocity? I don't mean the angle just the velocity.

var velocityX = some velocity;
var velocityY = some velocity;

// Convert the two X and Y velocities to one velocity
Share Improve this question edited Dec 17, 2019 at 22:11 Kenzoid asked Dec 17, 2019 at 22:05 KenzoidKenzoid 2941 silver badge17 bronze badges 1
  • 2 I don't mean the angle just the velocity. What is just the velocity? A vector also contains a direction, not just a length. – tkausl Commented Dec 17, 2019 at 22:10
Add a ment  | 

3 Answers 3

Reset to default 5

Pythagoras would say

var velocity = Math.sqrt(velocityX*velocityX+velocityY*velocityX);

and he would be right.

Some other dude might add:

var angleInDegrees = Math.atan2(velocityX,velocityY)*180/Math.PI;

Just take Math.hypot with all velocities.

newVelocity = Math.hypot(velocityX, velocityY);

Once you drop the direction, then it is just speed which is a scaler, whereas velocity is a vector.

You either are better off sticking with X and Y ponents, or having speed and angle. Or You are better off calling by what it bees, which is speed.

本文标签: javascriptHow to convert a X and Y Velocity to one VelocityStack Overflow