How can I create a simple 2D NURBS using XAML?

坚强是说给别人听的谎言 提交于 2019-12-06 00:28:55
Shay Erlichmen

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.

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:

 BezierSegment Point1="1,2" Point2="2,1" Point3="3,3"

 BezierSegment Point1="4,5" Point2="5,2" Point3="6,3" 

 BezierSegment Point1="7,4" Point2="8,1.75" Point3="9,2.5" 

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:

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!