我正在做一个
WPF控件(旋钮).我试图找出基于圆圈内的鼠标点击位置计算角度(0到360)的数学.
例如,如果我点击X,Y在图像上的位置,我会有一个点X,Y.我也有中心点,不知道如何获得角度.
我的代码如下:
- internal double GetAngleFromPoint(Point point,Point centerPoint)
- {
- double dy = (point.Y - centerPoint.Y);
- double dx = (point.X - centerPoint.X);
- double theta = Math.atan2(dy,dx);
- double angle = (theta * 180) / Math.PI;
- return angle;
- }
解决方法
你几乎是正确的:
- internal double GetAngleFromPoint(Point point,dx);
- double angle = (90 - ((theta * 180) / Math.PI)) % 360;
- return angle;
- }