首页 > 解决方案 > 在坐标系中旋转一条线

问题描述

我想以随机角度 alpha 旋转一条线。

所以我得到了线的坐标:例如(10,20 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);

我认为计算实际上是正确的,但是计算是以弧度为单位的,我不知道如何将其放在度数级别。

标签: c#graphicsrotation2d

解决方案


推荐阅读