C# 将一组点旋转到原点

C# 将一组点旋转到原点,c#,C#,我有一个包含页面x和y位置的点列表。我想在所有这些点上应用相对于页面任何轴心点的旋转(目前假设其中心) var points=新列表(); 增加(1,1)点; 增加(15,18); 增加(25,2); 增加(160175); 增加(150,97); 常数int pageHeight=300; 常量int pageWidth=400; var pivotPoint=新点(200150)//居中 变量角度=45;//这是在程度上。 //应用旋转。 我需要一些公式吗?如果你把一个点(x,y)绕着点(

我有一个包含页面x和y位置的点列表。我想在所有这些点上应用相对于页面任何轴心点的旋转(目前假设其中心)

var points=新列表();
增加(1,1)点;
增加(15,18);
增加(25,2);
增加(160175);
增加(150,97);
常数int pageHeight=300;
常量int pageWidth=400;
var pivotPoint=新点(200150)//居中
变量角度=45;//这是在程度上。
//应用旋转。
我需要一些公式吗?

如果你把一个点(x,y)绕着点(x1,y1)旋转一个角度,那么你需要一个公式

public static Point Rotate(Point point, Point pivot, double angleDegree)
{
    double angle = angleDegree * Math.PI / 180;
    double cos = Math.Cos(angle);
    double sin = Math.Sin(angle);
    int dx = point.X - pivot.X;
    int dy = point.Y - pivot.Y;
    double x = cos * dx - sin * dy + pivot.X;
    double y = sin * dx + cos * dy + pivot.X;

    Point rotated = new Point((int)Math.Round(x), (int)Math.Round(y));
    return rotated;
}
static void Main(string[] args)
{
    Console.WriteLine(Rotate(new Point(1, 1), new Point(0, 0), 45));
}
x2 = cos(a) * (x-x1) - sin(a) * (y-y1) + x1
y2 = sin(a) * (x-x1) + cos(a) * (y-y1) + y1
Point newRotatedPoint = new Point(x2,y2)

如果要旋转的点很多,可能需要预计算旋转矩阵

[C  -S  U]
[S   C  V]
[0   0  1]
…在哪里

C = cos(θ)
S = sin(θ)
U = (1 - C) * pivot.x + S * pivot.y
V = (1 - C) * pivot.y - S * pivot.x
translate([x y]) = [1 0 x]
                   [0 1 y]
                   [0 0 1]

rotate(θ) = [cos(θ) -sin(θ) 0]
            [sin(θ)  cos(θ) 0]
            [  0       0    1]
然后按如下方式旋转每个点:

rotated.x = C * original.x - S * original.y + U;
rotated.x = S * original.x + C * original.y + V;

以上公式是三种变换组合的结果

rotated = translate(pivot) * rotate(θ) * translate(-pivot) * original
…在哪里

C = cos(θ)
S = sin(θ)
U = (1 - C) * pivot.x + S * pivot.y
V = (1 - C) * pivot.y - S * pivot.x
translate([x y]) = [1 0 x]
                   [0 1 y]
                   [0 0 1]

rotate(θ) = [cos(θ) -sin(θ) 0]
            [sin(θ)  cos(θ) 0]
            [  0       0    1]

或者使用一个矩阵类。是的,你需要一个关于这条线的公式:double y=sin*dx+cos*dy+pivot.X;你的意思是:双y=sin*dx+cos*dy+pivot.y?