我有3个点,所有3个点的X,Y坐标
我试图找到移动时钟的方向或顺时针方向我尝试使用向量和link。
我总是在这个坐标上得到正面的角度:
顺时针P3>>>> P4 中心(-1.236,6.937) P3(2479.926,1439.437) P4(1988.959,2067.846)
public static double AngleFrom3PointsInDegrees(double Xc, double Yc, double Xa, double Ya, double Xb, double Yb)
{
/* double Xc = centerPoint.X;
double Yc = centerPoint.Y;
double Xb = oldPoint.X;
double Yb = oldPoint.Y;
double Xa = newPoint.X;
double Ya = newPoint.Y;
*/
double c2 = (Math.Pow(Xb - Xa, 2) + Math.Pow(Yb - Ya, 2));
double a2 = (Math.Pow(Xb - Xc, 2) + Math.Pow(Yb - Yc, 2));
double b2 = (Math.Pow(Xa - Xc, 2) + Math.Pow(Ya - Yc, 2));
double a = Math.Sqrt(a2);
double b = Math.Sqrt(b2);
double val = (a2 + b2 - c2) / (2 * a * b);
double angle = Math.Acos(val);
return angle = angle > Math.PI ? angle - 2 * Math.PI : angle;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
double Case1= AngleFrom3PointsInDegrees(-1.236,6.937,1113.749,3070.335,2094.251,2504.242);
double Case2 = AngleFrom3PointsInDegrees(-1.236, 6.937, 247.926, 1439.437, 1988.959, 2067.846);
MessageBox.Show("Angle = " + Case1);
MessageBox.Show("Angle = " + Case2);
答案 0 :(得分:0)
设中心点是(xc,yc),圆上的两个点是(xa,ya)和(xb,yb),所以矢量
CA = (xa-xc, ya-yc), CB = (xb-xc, yb-yc)
然后这些矢量之间的符号角是
Angle = atan2(VectorProduct(CA, CB), ScalarProduct(CA, CB)) =
atan2(CA.x*CB.y-CA.y*CB.x, CA.x*CB.x+CA.y*CB.y)