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
3 Answers
Reset to default 5Pythagoras 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745223149a4617342.html
评论列表(0条)