点绕圆心旋转公式

1、旋转点计算公式
点p1绕旋转中心点c逆时针转angle角,求旋转后点p2的公式:

public static Point CalculateRotatePoint(Point p1, Point c, double angle)
{
	double r = angle / 180.0 * Math.PI;
	double x = (p1.X - c.X) * Math.Cos(r) - (p1.Y - c.Y) * Math.Sin(r) + c.X;
	double y = (p1.X - c.X) * Math.Sin(r) + (p1.Y - c.Y) * Math.Cos(r) + c.Y;
	return new Point(x, y);
}

2、旋转中心计算公式
点p1逆时针旋转angle角度到点p2,求旋转中心点c的公式:

public static Point CalculateRotateCenter(Point p1, Point p2, double angle)
{
	double r = angle / 180.0 * Math.PI;
	double x = 0.5 * ((p2.Y - p1.Y) * Math.Sin(r) + (p2.X + p1.X) * Math.Cos(r) - (p2.X + p1.X)) / (Math.Cos(r) - 1.0);
	double y = 0.5 * ((p2.Y + p1.Y) * Math.Cos(r) - (p2.X - p1.X) * Math.Sin(r) - (p2.Y + p1.Y)) / (Math.Cos(r) - 1.0);
	return new Point(x, y);
}

你可能感兴趣的:(算法,算法)