从圆上的 3 个点检索正角或负角
本文关键字:点检索 | 更新日期: 2023-09-27 17:56:53
我有 3 个点和所有 3 个点和 X,Y 坐标
- 其中一个点是圆心
- 另外两个点在这个圆上移动
正在尝试查找移动时钟的方向或顺时针方向,我尝试使用矢量和此链接。
我总是在这个坐标上得到正角度:
- P1>>>>>> P2 的时钟中心 (-1.236,6.937)P1 (1113.749,3070.335)P2 (2094.251,2504.242)
顺时针 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);
让我们的中心点是(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)