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
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.
本文标签: javascriptHow to convert a X and Y Velocity to one VelocityStack Overflow
版权声明:本文标题:javascript - How to convert a X and Y Velocity to one Velocity - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745223149a2648488.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论