旋转后获取线的新位置

编程入门 行业动态 更新时间:2024-10-25 14:30:50
本文介绍了旋转后获取线的新位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要在一行上使用RotateTransform方法找出旋转后的新线坐标. 例如,在此行之后:

I need to find out new coordinates of line after rotation using RotateTransform method on a line. For example, after this line:

line.RenderTransform = new RotateTransform(25, 0, 0);

line.X1和其他三个属性不变.我已经找到了一些矩形等形状的解决方案,但不适用于直线.线有不同的处理方式.

line.X1 and the three other properties don't change. I have found some solution for shapes like rectangular, but it doesn't work for line. Line has different way how to treat with it.

感谢您的帮助 HB..第二种方法正是我一直在寻找的东西.

Thanks for your help H.B. The second way is exactly what I've been looking for.

解决方案:

Line line = new Line(); line.X1 = 10; line.Y1 = 10; line.X2 = 20; line.Y2 = 30; RotateTransform rotation = new RotateTransform(); Point p1 = rotation.Transform(new Point(line.X1, line.Y1)); Point p2 = rotation.Transform(new Point(line.X2, line.Y2)); line.X1 = p1.X; line.Y1 = p1.Y; line.X2 = p2.X; line.Y2 = p2.Y;

此代码旋转线并为该线的附加属性设置新的坐标值.

This code rotates the line and sets a new values of coordinates to attached properties of this line.

推荐答案

您可以转换本身就是点:

var transform = new RotateTransform(25, 0, 0); var newP1 = transform.Transform(new Point(line.X1,line.Y1)); //...

如果要进行永久转换,可以转换起点和终点并将新值分配给相应的属性.

If you want a permanent transformation you can transform the start and end points and assign the new values to the respective properties.

更多推荐

旋转后获取线的新位置

本文发布于:2023-10-07 23:48:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470883.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!