简体   繁体   English

c# - 如何在c#xamarin形式中使用角度计算两点

[英]How to calculate two points using angle in c# xamarin forms

I have a slider for rotating the line.我有一个用于旋转线条的滑块。 When the slider is slide I want to rotate the line.当滑块滑动时,我想旋转线条。 The slider value is set as an angle.滑块值设置为角度。 When the page initial loading the line shape is placed as horizontal.当页面初始加载时,线条形状被放置为水平。 The slider value is binded from getting the angle.滑块值是从获取角度绑定的。 I have used the below code to calculate the angle between two points.我使用下面的代码来计算两点之间的角度。

const double Rad2Deg = 180.0 / Math.PI;
private double Angle(Point start, Point end)
{
    return Math.Atan2(start.Y - end.Y, end.X - start.X) * Rad2Deg;
}

Now I want to calculate the two points using angle.现在我想用角度来计算这两个点。 Please give me a suggestion.请给我一个建议。

Let's say we have a line beginning in a point (0,0) and ending in point (x,y).假设我们有一条以点 (0,0) 开始并以点 (x,y) 结束的线。 And we want to rotate it to the angle a .我们想将它旋转到角度a So, the (x,y) point will translate into (x', y') point, where因此,(x,y) 点将转化为 (x', y') 点,其中

x' = x*cos(a)-y*sin(a)
y' = x*sin(a)+y*cos(a)

And the whole line will be from (0,0) to (x', y')整行将从 (0,0) 到 (x', y')

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

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