简体   繁体   English

从起点计算坐标,所有象限都有距离和角度

[英]Calculate coordinate from starting point, having distance and an angle for all quadrants

I have: 我有:

private double AngleToRadians(double angle)
{
     return (Math.PI / 180) * angle;
}


double x = 30, y = 60;
var dist = 10;
var angle = 120;

x = x + dist * Math.Cos(AngleToRadians(angle));
y = y + dist * Math.Sin(AngleToRadians(angle));

What this does is returns me a new coordinate, 10 points into direction (angle) from (x,y) starting point. 这样做是给我返回一个新坐标,该坐标从(x,y)起点指向方向(角度)10个点。

This works correctly in top-right quadrant, but does not on any of other three. 这可以在右上象限中正常工作,但不能在其他三个象限中工作。

Is there a formula that would work in all 4? 是否有一个适用于所有4种方法的公式?

x = x + dist * Math.Cos(AngleToRadians(angle)); y = y + dist * Math.Sin(AngleToRadians(angle));

It seems you are using the same x and y variables both for central point and for ending point, so coordinates of center are updated every time 看来您在中心点和终点都使用了相同的x和y变量,因此中心坐标每次都会更新

Just use x0, y0 as center and x, y as ending point 只需使用x0, y0作为中心, x, y作为终点

x = x0 + dist * Math.Cos(AngleToRadians(angle));

a (horizontal length), b (vertical length), x (coordinate x), y (coordinate y), r (radius of the sphere), θ (angle), L (distance until the ball stops) are given, find coordinates (X, Y) at which the ball stops. 给出a(水平长度),b(垂直长度),x(坐标x),y(坐标y),r(球半径),θ(角度),L(直到球停止的距离),找到坐标(X,Y)球停在此位置。

Tips: 提示:

If the billiard table is infinitely large and the ball can not reach to wall, then calculated, the coordinates (X, Y) at which the ball stops can be calculated by the following formula. 如果台球桌无限大并且球无法到达墙壁,则可以通过以下公式计算出球停止的坐标(X,Y)。 X = L * cos (θ) + x Y = L * sin (θ) + y X = L * cos(θ)+ x Y = L * sin(θ)+ y

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

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