110,539
社区成员
发帖
与我相关
我的任务
分享
static PointF Rotate(PointF center, PointF point, float angleInDegree)
{
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.Rotate(angleInDegree); // 构造一个逆时针旋转的矩阵
PointF[] points = { new PointF( point.X - center.X, point.Y - center.Y) }; // 把坐标原点移到'那个原点'那里
matrix.TransformPoints( points ); // 旋转
return new PointF(center.X + points[0].X, center.Y + points[0].Y); // 把坐标原点移回去
}
// 原点
double ax = 2, ay = 5;
double bx = 10, by = 15;
// 旋转角度
double dblAngle = 30;
double dblLength = Math.Sqrt((by - ay) * (by - ay) + (bx - ax) * (bx - ax));
double k1 = (by - ay) / (bx - ax);
double angle0 = Math.Atan(k1);
dblAngle = angle0 + dblAngle * Math.PI / 180;
double dblNewX = dblLength * Math.Cos(dblAngle) + ax;
double dblNewY = dblLength * Math.Sin(dblAngle) + ay;
/ X'\ / cos(N) -sin(N) \ / X \
| | = | | | |
\ Y'/ \ sin(N) cos(N) / \ Y /
static PointF Rotate(PointF point, float angleInDegree)
{
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.Rotate(angleInDegree);
PointF[] points = { point };
matrix.TransformPoints( points );
return points[0];
}
public void Test()
{
PointF point = new PointF(1, 0);
PointF p1 = Rotate( point, 45 ); // p1 = {0.7071, 0.7071}
PointF p2 = Rotate( point, 60 ); // p2 = {0.5000, 0.8660}
}