gpt4 book ai didi

wpf - 旋转几何路径

转载 作者:行者123 更新时间:2023-12-01 13:00:27 24 4
gpt4 key购买 nike

我最近正在使用 Streamgeometry绘制一个简单的箭头。现在我需要将箭头转到指定的角度。但是如何旋转这个几何图形呢?

Dim pt1 As New Point(X1, Me.Y1) 'left point
Dim pt2 As New Point(_X2, Me.Y2) 'right point

Dim pt3 As New Point(_X2 + (HeadWidth * cost - HeadHeight * sint), Y2 + (HeadWidth * sint + HeadHeight * cost)) 'arrow line down
Dim pt4 As New Point(_X2 + (HeadWidth * cost + HeadHeight * sint), Y2 - (HeadHeight * cost - HeadWidth * sint)) 'arrow line up

context.BeginFigure(pt1, True, False)
context.LineTo(pt2, True, True)
context.LineTo(pt3, True, True)
context.LineTo(pt2, True, True)
context.LineTo(pt4, True, True)

最佳答案

如果旋转仅用于展示(即您不关心原始几何数据仍然是指向原始方向的箭头),那么您可以应用 transform

在绘制上下文后,只需将转换应用于原始 StreamGeometry 对象(C# 中的代码,但它也适用于 VB.NET):

var geo = new StreamGeometry();
using (var ctx = geo.Open())
{
ctx.BeginFigure(new Point(0, 20), false, false);
ctx.LineTo(new Point(100, 20), true, true);
ctx.LineTo(new Point(80, 40), true, true);
ctx.LineTo(new Point(80, 0), true, true);
ctx.LineTo(new Point(100, 20), true, true);
}
geo.Transform = new RotateTransform(45);
var drawing = new GeometryDrawing(Brushes.Transparent, new Pen(Brushes.Black, 1), geo);
image1.Source = new DrawingImage(drawing);

上面的代码将在名为 image1Image 控件上绘制一个向下/向右的箭头。

关于wpf - 旋转几何路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6385350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com