JavaScript:通过角度和距离计算出Y点 [英] JavaScript: figure out point Y by angle and distance

查看:163
本文介绍了JavaScript:通过角度和距离计算出Y点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我想画一条从X点到Y点的线。

In my project, I would like to draw a line from point X to point Y.

虽然我知道X点的位置,但我只知道角度和点Y的距离。

While I know the position of point X, I only know the angle and the distance of point Y.

所以我的问题是通过角度(从点X)和距离得到点Y的坐标。

So my problem is to get the coordinates of point Y by the angle (from point X) and the distance.

我在这个项目中使用JavaScript而不想使用任何图形库。

I am using JavaScript for this project and don't want to use any graphical library.

例如:


  • 点X(10; 20)

  • point X (10;20)

指向Y(距离X点10°和200px)

point Y (10° & 200px from point X)

它可能很漂亮基本数学,但我不知道怎么做。

It is probably pretty basic math, but I have no clue how to do it.

推荐答案

js> Math.cos(10*Math.PI/180) * 200 + 10
206.9615506024416
js> Math.sin(10*Math.PI/180) * 200 + 20
54.729635533386066

Y 位于(207,55)。

Y is at (207, 55).

这篇关于JavaScript:通过角度和距离计算出Y点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆