简体   繁体   English

如何以一定角度移动物体?

[英]How to move an Object with an Angle?

I wont to move my Object(has {x:10,y:15}) with an angle off 20° Exmaple PIC: https://cdn.discordapp.com/attachments/591642374376259593/602618211040493568/unknown.png 我不会以偏离20°角度的角度移动我的对象(具有{x:10,y:15})例如: https//cdn.discordapp.com/attachments/591642374376259593/602618211040493568/unknown.png

let plus = {
   x: Math.cos(this.angel),
   y: Math.sin(this.angel)
}
this.x += plus.x
this.y += plus.y

I expect an velocity like {x:2.5,y:3} 我期望速度像{x:2.5,y:3}

let angle = 20;

You need to convert angle into radians 您需要将角度转换为弧度

let radians = angle * (Math.PI / 180);

Then use that to find x and y 然后使用它来找到x和y

let plus = {
   x: Math.cos(radians),
   y: Math.sin(radians)
}

this.x += plus.x
this.y += plus.y

The angle 0 degree is at 3 o'clock and 90 degree is 6 o'clock and so on. 角度0度是3点,而90度是6点,依此类推。

If you want the angle in the drawing then 如果您想在工程图中绘制角度

let angle = 90 - 20;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM