旋转后获取线的新位置

发布于 2024-11-12 16:52:20 字数 695 浏览 2 评论 0原文

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

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

line.X1 和其他三个属性不会更改。我找到了一些针对矩形等形状的解决方案,但它不适用于线条。 Line 有不同的处理方式。

编辑:感谢您的帮助HB第二种方法正是我一直在寻找的。

解决方案:

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;

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

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 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.

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

SOLUTION:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时模样 2024-11-19 16:52:20

您可以自行转换点:

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

如果您想要永久变换,您可以变换起点和终点并将新值分配给相应的属性。

You can transform points on their own:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文