c# - 在坐标系中旋转一条线
问题描述
我想以随机角度 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);
我认为计算实际上是正确的,但是计算是以弧度为单位的,我不知道如何将其放在度数级别。
解决方案
推荐阅读
- javascript - e.stopPropagation 不适用于 mouseenter 事件
- google-cloud-platform - 了解 Google Cloud IAM 政策 - 它不仅仅是一个额外的层
- android - Android Kotlin Pusher Chatkit 未在回收站视图中加载所有房间
- javascript - html2cavas 呈现几乎不可见的图像
- apache-kafka - 使用超级账本结构上的 kafka 排序服务创建通道的奇怪行为
- angular - Angular 8 调用 Rest Api - 资源加载需要很长时间
- php - 当我将其与 writehtml() 一起使用时,TCPDF 图像未在刷新时显示
- matlab - 删除图像中两个对象之间的连接
- javascript - Angular 8中的图像映射动态调整大小
- javascript - 如何通过 React Router Link 将功能组件中的值传递到另一个功能组件?