我有一个任务需要绘制一个特定的图形。作为这个任务的一部分,我需要将一些点旋转45度。
我已经花了两天时间尝试计算公式,但是就是得不到正确的结果。我在各个地方搜索,包括这个特定的网站,我离成功很近了,但还没有到达目标。
这里是我的要求: 我需要绘制4个不同的点。
我有一个特定的公式来计算它们的位置,而这超出了问题的范围,但是这是我的计算结果:
int radius = 576;
int diameter = radius * 2;
Point blueA = new Point(561, 273);
Point greenB = new Point(273, 561);
Point yellowC = new Point (849, 561);
Point redD = new Point (561, 849);
现在我需要将这些圆点旋转45度。我使用以下代码来实现:
double rotationAngle = 45;
double rotationRadians = rotationAngle * (Math.PI / 180);
int center = radius;
result.X = (int)(Math.Cos(rotationRadians) * ((double)result.X - (double)center) - (double)Math.Sin(rotationRadians) * ((double)result.Y - center) + (double)center);
result.Y = (int)(Math.Sin(rotationRadians) * ((double)result.X - (double)center) + (double)Math.Cos(rotationRadians) * ((double)result.Y - center) + (double)center);
但这就是我得到的:
非常感谢任何帮助。
RotatePoint
中的方程吗? - Bryce Guintax=0
,这个公式是Math.Atan2(pointToRotate.Y - centerPoint.Y, centerPoint.X - pointToRotate.Y)
。请注意,常规的 atan 函数不适用于所有象限,因此需要使用 Atan2 函数。 - Bryce Guinta