C# 在坐标系中旋转直线

C# 在坐标系中旋转直线,c#,graphics,rotation,2d,C#,Graphics,Rotation,2d,我想以随机角度α旋转一条直线 所以我得到了这条线的坐标:例如(10,20,30)。 并且用户给出一个输入,例如45 请注意,坐标系不是常规坐标系。我的意思是:X轴(水平)像往常一样在正确的方向上是正的。但Y轴(垂直)向下为正值 所以在我的坐标系中,一个通常在(2 |-3)的点就是(2 | 3) 现在应将该线旋转45度。 我的想法是先将直线移动到坐标系的原点,然后旋转它(只需移动不位于原点的点),然后将其移回原来的位置 **// moving the line to the origin of t

我想以随机角度α旋转一条直线

所以我得到了这条线的坐标:例如(10,20,30)。 并且用户给出一个输入,例如45

请注意,坐标系不是常规坐标系。我的意思是:X轴(水平)像往常一样在正确的方向上是正的。但Y轴(垂直)向下为正值

所以在我的坐标系中,一个通常在(2 |-3)的点就是(2 | 3)

现在应将该线旋转45度。 我的想法是先将直线移动到坐标系的原点,然后旋转它(只需移动不位于原点的点),然后将其移回原来的位置

**// moving the line to the origin of the coordinate system**    

int movedX1 = 0;
int movedY1 = 0;
int movedX2;
int movedY2;

if ((movedX2 = x2 - x1)<0)
{
movedX2 *= -1;
};
if ((movedY2 = y2 - y1) < 0)
{
movedY2 *= -1;
};

string newX1 = movedX1.ToString();
string newY1 = movedY1.ToString();
string newX2 = movedX2.ToString();
string newY2 = movedY2.ToString();

GIO.setItemProperty(item, "PointList", "\"" + newX1 + ", " + newY1 + "   " 
+ newX2 + ", " + newY2 + "\"");

MessageBox.Show("Moved Coordinates: "+ newX1 + ", " + newY1 + "   " + 
newX2 + ", " + newY2 );

**// now the Point that is not in the origin should be moved so the line 
// turns X degrees.**

double inputAngle, ind0_0, ind0_1, ind1_0, ind1_1;

inputAngle= Convert.ToDouble(txtWinkel.Text);

ind0_0 = Math.Cos(inputAngle/ Math.PI * 180);
ind0_1 = Math.Sin(inputAngle/ Math.PI * 180);
ind1_0 = Math.Sin(inputAngle/ Math.PI * 180);
ind1_1 = Math.Cos(inputAngle/ Math.PI * 180);

double finalX2 = -(ind0_0 * movedX2 - ind0_1 * movedY2);
double finalY2 = -(ind1_0 * movedX2 + ind1_1 * movedY2);
**//将直线移动到坐标系的原点**
int movedX1=0;
int movedY1=0;
int-movedX2;
int-movedY2;

如果((movedX2=x2-x1)两个旋转一条线,你需要4样东西:由2个点给出的线,一个你旋转的固定点(这是(0;0)吗?)和一个旋转的角度。然后你将你喜欢旋转的点转换成径向坐标(到旋转点的距离和角度),通过添加旋转来修改角度,最后从径向坐标返回笛卡尔坐标。在此过程中,您不需要任何度数。您的目标是什么:Winforms、WPF、ASP..?您应该始终正确标记问题,以便人们可以在问题页上看到它!这是另一个程序,但不是t点。所以我可以把坐标插入那个程序…这不是问题。问题是,如何从输入中计算出水平度…是的,围绕点旋转是(0 | 0)。你的问题是什么?我可以看到三个潜在的问题:
if((movedX2=x2-x1)