正如评论所说,包含函数中的计算很好:旋转点按预期计算(负角表示顺时针旋转)。您所追求的是基于极坐标系的旋转点的定义,这必须在稍后阶段完成。“Desired”中描述的参考系统与“默认参考系统”有 +90 度的差距,因此您只需在为此类系统执行的计算中添加 +90。
您所追求的角度可以通过以下函数来计算:
public static double angleFromPoint(Point inputPoint, Point centerPoint)
{
double varX1 = Math.Abs(inputPoint.X - centerPoint.X);
double varY1 = Math.Abs(inputPoint.Y - centerPoint.Y);
double outAngle = 180 * Math.Atan(varY1 / varX1) / Math.PI; //Angle from 0 to 90 which has to be updated on account of the quadrant it is in and the chosen syst
int curQuadrant = determineQuadrant(inputPoint, centerPoint);
//Modifications to account for the default system of reference
if (curQuadrant == 1)
{
outAngle = 180 - outAngle;
}
else if (curQuadrant == 3)
{
outAngle = 360 - outAngle;
}
else if (curQuadrant == 4)
{
outAngle = 180 + outAngle;
}
//Over-modification to account for the system of reference "Desired", +90 the default system of reference
outAngle = outAngle + 90;
if (outAngle > 360)
{
outAngle = outAngle - 360;
}
return outAngle;
}
//Moving clockwisely, the first quadrant is located between 180 and 90 degrees in the default system of reference
public static int determineQuadrant(Point inputPoint, Point centerPoint)
{
int curQuadrant = 0;
if (inputPoint.X < centerPoint.X && inputPoint.Y >= centerPoint.Y)
{
//Default system of reference -> 180 to 90
curQuadrant = 1;
}
else if (inputPoint.X >= centerPoint.X && inputPoint.Y >= centerPoint.Y)
{
//Default system of reference -> 90 to 0/360
curQuadrant = 2;
}
else if (inputPoint.X >= centerPoint.X && inputPoint.Y < centerPoint.Y)
{
//Default system of reference -> 0/360 to 270
curQuadrant = 3;
}
else if (inputPoint.X < centerPoint.X && inputPoint.Y < centerPoint.Y)
{
//Default system of reference -> 270 to 180
curQuadrant = 4;
}
return curQuadrant;
}
在那里,您可以看到基于“默认参考系统”的逐步清晰的计算以及随后转换为您想要的系统。计算基于 ArcTangent(仅提供 0-90 角)并根据给定的“象限”(基于默认系统,即 -90 所需系统)进行更新;计算出的角度+90 可提供您想要的结果。
因此,您必须首先计算旋转点的坐标,然后计算相关的角度:
Point rotatedPoint = RotatePoint(curPointnew, centerPoint, rotationAngle);
double angleRotatedPoint = angleFromPoint(rotatedPoint, centerPoint);