最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to convert a X and Y Velocity to one Velocity - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论