如何使用 XAML 创建简单的 2D NURBS?
我需要创建一个具有两个端点和“n”个控制点的样条线。
据我所知,贝塞尔曲线仅允许一个控制点,而贝塞尔样条允许两个控制点。但是,我需要能够添加我认为合适的任意数量的控制点,而不仅限于一两个。
这是我想要实现的示例,有 4 个控制点:
(来源:有关 NURBS 的维基百科文章)
到目前为止,我只能将一系列 BezierSegments 组合在一起,如下所示:
http://img297.imageshack.us/img297/3706/bezierpath.png
<Polyline Stroke="Green" Stretch="Uniform"
Points="0,0 1,2 2,1 3,3 4,3 5,2 6,3 7,2 8,1.75 9,2.5" />
<Path Stroke="Red" Stretch="Uniform">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="0,0">
<PathFigure.Segments>
<PathSegmentCollection>
<BezierSegment Point1="1,2" Point2="2,1" Point3="3,3" />
<BezierSegment Point1="4,3" Point2="5,2" Point3="6,3" />
<BezierSegment Point1="7,2" Point2="8,1.75" Point3="9,2.5" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是开箱即用,但请查看上一个问题,它将向您指出如何使用 C# 绘制 NURBS,然后您可以将代码转换为某种东西,然后实现 PathSegment 在WPF下使用它。
Not out of the box but take a look at this previous question it will point you to how to draw NURBS using c#, you can then turn the code into something then implements PathSegment to used it under WPF.
尽管在标题中您提到了 NURBS,但您似乎正在寻找一种方法来绘制一系列在连接点处平滑的贝塞尔样条线段。
要实现此目的,您需要在第二个线段上设置 point1,以便它将相对于线段之间的连接点(即第一个线段上的 point3)镜像第一个线段上的 point2。
在您的情况下,连接点是 (3,3),第一段上的 point2 是 (2,1),因此您需要在代码中将第二段上的 point1 设置为 (4,5),而不是 (4,3)。
相似性将第三段上的 point1 更改为 (7,4),因此它相对于 (6,3) 镜像 (5,2),最终得到以下段,可以解决您的问题:
现在,如果您不喜欢我改变你的控制点并且真的想要(4,3)和(7,2)作为控制点,添加更多段。请记住,如果您希望与前一段顺利连接,则无需决定 point1 是什么。
注意:
此解决方案将为您提供连接点的第一级平滑度。如果您还想要第二级平滑度 (C2),您可以通过适当设置 point2 来实现。如果您获取前一段的 point1 并将其相对于前一段的 point2 镜像,然后相对于当前段的 point1 镜像结果,您将获得当前段所需的 point2。然后您只需选择您想要的任何点3即可完成。请参阅http://ibiblio.org/e-notes/Splines/B-spline。 htm 了解更多信息。
您从维基百科给出的示例是 NURBS。 NURBS 就像贝塞尔样条线,但它增加了点的权重。据我所知,BezierSegment 文档不支持这一点。
Although in the title you mention NURBS, you seem to be looking for a way to draw a series of Bezier Spline segments that are smooth at the connection points.
To achieve this you need to set the point1 on the second segment so it will mirror point2 on the 1st segment relative to the connection point between the segments (which is point3 on the 1st segment).
In your case the connection point is (3,3) and point2 on the first segment is (2,1) so you need to make point1 on the second segment (4,5) instead of (4,3) in your code.
Similarity change point1 on the 3rd segment to (7,4) so it mirrors (5,2) relative to (6,3) and you end up with the following segments that might solve your problem:
Now, if you don’t like me changing your control points and really want (4,3) and (7,2) to be control points, add more segments. Just remember that you don’t get to decide what point1 is, if you want smooth connectivity with the previous segment.
Notes:
this solution will give you a 1st degree of smothness at the connection points. If you want also a second degree of smothness (C2) you can achieve that by setting up point2 appropritaly. If you take point1 of the previous segment and mirror it relative to point2 of the previous segment and then mirror the result relative to point1 of the current segment you will get the desired point2 of the current segment. Then you simply choose any point3 you desire and you are done. See http://ibiblio.org/e-notes/Splines/B-spline.htm for more on this.
The exmaple you gave from wikipedia is a NURBS. A NURBS is like a bezier spline, but it adds weights to the points. From what I can tell from the documentation BezierSegment does not support that.