Sketcher: Bezier curves

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Sketcher: Bezier curves

Post by Chris_G »

I think that the main difficulty with BSplineCurves is that you have a lot parameters available :

- you can move the poles to sculpt the curve ( that is probably the most important feature )
- you can raise or lower the degree ( making the influence of the poles more local or global )
- you can change the knot vector ( it changes the curve shape, but it doesn't have a visual and instinctive meaning, so I think that some softwares hide or don't expose this feature )
- you can change the weight of the poles ( rational curve ). From what I read, this should not be considered as a main editing feature, but as an extra tweaking tool, to refine a curve when you don't get exactly what you want with the pole-editing method.
- you can change the multiplicity of the knots

IMHO, the first 2 points are important and should be enough to sculpt a curve to one's desire.

About the max degree, OCC goes up to 25, I think, but I am not sure it is very useful to go that high.
I don't know how sketcher is implemented, but I think Bspline curves, in Coin3D, are limited to degree 8.

I bought the Nurbs Book some time ago. Very interesting reading. If you are interested, PM me you address, and it will be my pleasure to send it to you.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Sketcher: Bezier curves

Post by microelly2 »

The main problem is to fight against the mass of data (poles,knots, multiplicities).

At the moment I work on a special case, I call it needle with only two BSpline base objects - a rib model and a backbone model
To get the parameters manageable I put them into a spreadsheet and connect methods into the spreadsheet.
My idea is to add stepwise a 3D view based editor to change the parameters in a way that the user can feel what he does.
as written in the nurbs book the main task is to manage the poles
for most cases degree 3 will be good enough. here a band of 3 pole rows is enough to get the required continuities

https://www.youtube.com/watch?v=DpMPDCnm8-I

https://www.youtube.com/watch?v=Sfn-K3vz3Lg
https://www.youtube.com/watch?v=f-6I7SRBDvs
https://www.youtube.com/watch?v=jxyuS9JiYTQ
https://www.youtube.com/watch?v=MZt3IdFyQgc

on the way from the needle to the full nurbs the amount of data become to large to manage it as single numbers.
then a good 3d editor is needed and the possibility to add powerful methods to curb the data.

The power of the Draft-Tools and the Sketcher are to weak to achieve this.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Bezier curves

Post by abdullah »

I have finish my crash curse on polynomial functions and functions of polynomial segments. My head is full of information I still have to digest.

Thank you very much to everybody that commented above. I have studied every piece of information given. B-splines do not seem complicated (although the underlying math is not precisely straightforward, but we, together, have managed similar situations), or at least, providing a good UI interface to B-splines is indeed what is demanding. An UI fit to purpose. Because I see that B-splines can be used in many different ways, and all of them maybe do not fit the use case scenario meant for in the Sketcher.

I go replying to all of you, and then I will try to make sense, surely somebody will correct me if I am just wrong (which is likely). I am still digesting it as I said.
wmayer wrote:I would only go for B-Spline curves and completely ignore Bezier curves
I think there are "two" possible approaches:
a) go for a rational B-Spline (union of several rational single curves segments, several parabolas or cubics or higher depending on the grade).
b) go for the approach initially indicated by DeepSOIC (support a single segment), then use special solver constraints to attach them so as to form a B-Spline (continuity at different degrees). This segment should have n multiplicity of start and stop knots, where n is the grade so that they go through the endpoints.
or
c) go for a model in which the sketcher decomposes a B-Spline as in a) into individual segments as in b) to access a simplified solver approach (It is an OCC BSpline at Sketcher level, a bunch of segments at solver level).

In principle I favour a) or c), but I see merit in b), specially when implementing it in the constraint solver.

More on handling degrees, multiplicities,... below.
wmayer wrote:as mentioned above a B-Spline with the knot vector [0,...,0, 1, ...,1] where the multiplicity of the 0's and 1's is degree + 1 is also a Bezier curve
I can not currently see why I would like to use a Bezier if I can have a BSpline. However, if it would be needed, it can be handled as you indicate, for example by creating it with a separate geometry creation command that stablishes such a knot vector.
DeepSOIC wrote:I'm interested for playing with optics. I think it might be possible to construct a custom lens to achieve a certain distribution of light, by just using sketcher.
NormandC wrote:B-Splines are heavily used in product design. That interest didn't stop 3 years ago, it's still frequently requested. And BSplines in the Draft workbench are hard to use and edit.

Look at any consumer product from everyday life: toasters, shampoo bottles, guitars, (not mentioning cars!) and you can be sure B-Splines were used to design them.

IMHO support for B-Splines in the Sketcher is the essential first step for an eventual Surface Design workbench.

All low to mid-range CAD software I've used or tested had B-Spline support.
Point taken. It is totally necessary. Understood.
NormandC wrote:I haven't worked much with B-Splines, nor have I done many complex shape projects. I believe product designers will tweak B-Splines to get an appealing curve, I'm not aware if others more on the engineering side would use math. It would not be easy, because most CAD programs I know of don't reveal the math side of B-Splines to the end user. Personally, once I've tweaked a curve to my "liking", I want to constrain it so it will be locked.
Chris_G wrote:Hi,

DeepSOIC wrote:
But the ability to hand-tweak is absolutely essential, IMO, because they are going to be useful for visually appealing designs.

I agree with that.
Also understood. We have to define the level of hand-tweak needed. More below.
Chris_G wrote:Maybe, another interesting feature would be to offer a G2 ( or even G3 ) continuity between connected curves.
Nice Video. In it, if I understand it correctly, there is a G2-G4 constraint between the "connection curve segment that is inserted" and each of the preexisting ones. I do not have an absolute clear view of this at this time, but if we manage the rest, it does not sound like too complex to me... today.
Chris_G wrote: wmayer wrote:
Is G2 (or G3) continuity sufficient or do we also need C2 (or C3) continuity?

IMHO, the 'C' continuity is totally useless. This is just special case of the 'G' continuity, but I don't think it adds any "real life" value.
Maybe I did not get the concept ok. What I understood is:
1) When forcing C1, you get G1 (equal first derivative vectors)
2) When forcing C2, you get G2 (equal second derivative vectors)

Basically what I understood is that C is enforcing a Vector with direction, while enforcing G is enforcing the magnitude, slope, curvatura and that enforcing C is easier than enforcing G... but as I said, I did not arrive to digest this bit yet and I may be absolutely off here...
DeepSOIC wrote: wmayer wrote:
I think there should be two modes: you can drag the control points or you can drag points lying on the curve. For the latter this means an interpolation needs to be done and OCC has an algorithm for it but it looks like it's limited to the degree of 3.

If we do all the constraint math, the dragging will be a matter of adding temporary point-on-object constraint. Or I would maybe prefer a Value constraint (or, U-constraint), which will probably be in the root of point-on-object constraint implementation.
I think one thing is creation and another subsequent enforcement of constraints. It is similar to the two construction modes in the Ellipse. In principle I am rather decided to draw the control point polyline on creation, at least at first, and leave constraints do the magic where needed. Point on Object seems like a requirement to support. An inferior alternative solution would be not to implement point on object, making a BSpline an object just supporting endpoint constraining (when referring to interacting with other objects, of course with control points and knots internal alignment constraints as points, and other constrains when referring to constraints applied exclusively to the object). This would lead to a "block that is tweaked rather independently" (the BSpline) and the rest of the Sketcher geometry that would just adapt to any tangency, coincident on the start and end points of the BSpline. This would mean though, no point on BSpline (Point on Object) and no tangency to BSpline.
NormandC wrote:Usually you'll click the starting point, then the control points, and end with the end point. Next you'll edit the B-Spline by dragging the control points or those lying on the curve. Then you constrain it, which is not always easy if it contains many points.

There is also often a tool to simplify a B-Spline (reduce its number of points), which can also raise its number of points.

If you want, I can search for relevant videos on B-Spline creation in major CAD programs, if needed I could record one with the software I use at work.

And now, I really need to go out and shovel the 25 to 50 cm of snow we got last night!
Oh thanks! I mean, thank you but no recording needed at this point. And thank you for the indication of the tool. I was thinking on having a tool for degree, more detail below, but yes, I do understand it should be possible to modify increase/decrease the number of control points without destroying the constraining of the first and last points. That is though advanced support at this point.

(shovelling snow I am thankful not to have to do it).
triplus wrote:We briefly talked about JS.sketcher (web-cad) not that long ago:

viewtopic.php?f=8&t=19418

http://web-cad.org/

Insert plane and select it (face) -> Sketch command -> Bezier Curve

Something like that i guess would/could be a nice start
Thanks! It was very useful to get a quick first hand insight.
triplus wrote:And some BSpline theory i remembered:

viewtopic.php?f=3&t=16473&start=30#p133110

Hopefully some of this gives you some useful ideas on if and how and what to tackle first
This link to microelly's thread is awesome. From there I managed to the blog and to the script, so I was able to play. Thanks to both!!
Chris_G wrote:I think that the main difficulty with BSplineCurves is that you have a lot parameters available :

- you can move the poles to sculpt the curve ( that is probably the most important feature )
- you can raise or lower the degree ( making the influence of the poles more local or global )
- you can change the knot vector ( it changes the curve shape, but it doesn't have a visual and instinctive meaning, so I think that some softwares hide or don't expose this feature )
- you can change the weight of the poles ( rational curve ). From what I read, this should not be considered as a main editing feature, but as an extra tweaking tool, to refine a curve when you don't get exactly what you want with the pole-editing method.
- you can change the multiplicity of the knots
Thanks for this. It is a very concise overall description of user requirements. My take:

Poles (control points): This should not be a problem whatever method we decide to implement. I already see them as internal geometry of the BSpline with a relatively easy handling of the constraining in the solver.

Degree: Whatever the method, I see this as an internal alignment constraint with single GeoId and a value, adimensional, the degree, which proper rendering of the constraint to indicate the degree of the BSpline.

Knot vector: Big ?? One possibility is to show internal geometry points, but I am not sure how to constraint them (MicroElly's script shows what you can do with it, which is basically extending one rational curve segment at the expense of the adjacent ones), leaving the alternative you mention, hide them. It would be great to unveil a way of handle this.

Weights of poles: I see here an Internal alignment constraint GeoIds the poly and the control point and using an adimensional value, the (normalized) pole weight. I think it is a pity not to implement this, as it allows for much more shaping capabilities. It would be just great to provide a dragging control to regulate the value and a locking mechanism.

Multiplicity: This is real issue for a good support. In DeepSOICs approach, I think this is obviated, as there is a single segment, so no reason for multiplicity, other than the endpoint multiplicity to make the line pass thru. An extension to the other two approaches would be to force the user to make separate BSplines and connect them with the appropriate constraint, as to force corners (if that is the reason for the multiple poles), or as to align them is that is the reason for it (for example to approximate a quarter of circle by a quadratic spline segment). An alternative would be to introduce an internal alignment constraint with GeoIDs the BSpline and the control point and using the value as an adimensional integer to mark the multiplicity. It requires the user to know what is the multiplicity used for, but I think we can not "automate" this.
microelly2 wrote:The main problem is to fight against the mass of data (poles,knots, multiplicities).
From a UI perspective, yes it is indeed. You did quite an inspiring work with your script I mention above. Thanks!
microelly2 wrote:At the moment I work on a special case, I call it needle with only two BSpline base objects - a rib model and a backbone model
I do like it a lot. It is a "simplified" 3D construction method, definitely a great tool and addition to FC. BTW, I love the Banana, I am not sure how it does approximate to the model you bought in the supermarket, but it really does look like one. :)
microelly2 wrote:for most cases degree 3 will be good enough. here a band of 3 pole rows is enough to get the required continuities
I have the same impression, however, it is always nice to make the option available. I am sure somebody will use it... eventually (and probably misuse it at the beginning).
microelly2 wrote:The power of the Draft-Tools and the Sketcher are to weak to achieve this.
Sure, at least for the Sketcher. A 2D Sketcher is not meant for that. However, there are applications, see DeepSOIC's for example, that would take a greater advantage from a 2D limited BSpline support, due to its symmetry than from a more complex and versatile 3D tool.

Nonetheless, very nice tool!

I have written quite a lot. If you see issues in my reasoning, I am listening. I intend to start coding as soon as I have some time available.

Thanks to all for your comments and support. Let's have some nice BSpline support. We all make FreeCAD :)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher: Bezier curves

Post by DeepSOIC »

abdullah wrote:1) When forcing C1, you get G1 (equal first derivative vectors)
2) When forcing C2, you get G2 (equal second derivative vectors)
Not necessarily. If the magnitude of first derivative is zero at the connection point, forcing C1 will not yield G1 (most likely one will get G0). But for most cases, this won't be a problem.

EDIT: as far as I understand, C continuity is continuity of parametrization. G continuity is geometric continuity of the actual curve, regardless of parametrization.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher: Bezier curves

Post by DeepSOIC »

abdullah wrote:I think there are "two" possible approaches:
a) go for a rational B-Spline (union of several rational single curves segments, several parabolas or cubics or higher depending on the grade).
b) go for the approach initially indicated by DeepSOIC (support a single segment), then use special solver constraints to attach them so as to form a B-Spline (continuity at different degrees). This segment should have n multiplicity of start and stop knots, where n is the grade so that they go through the endpoints.
c) go for a model in which the sketcher decomposes a B-Spline as in a) into individual segments as in b) to access a simplified solver approach (It is an OCC BSpline at Sketcher level, a bunch of segments at solver level).
I don't see any advantage in option c). The aim of b) was to reduce the complexity of the interface programming, and convert the highly technical knot vector and multiplicity stuff to less technical continuity connections (like, go to the very roots of BSpline definition).

Adding the whole multisegment BSpline as one big solver entity shouldn't be that big of a deal, I think. Probably even less of a deal than the attempts to represent a bspline by its segments for solver.

So, if you want to make support of multisegment BSplines, I'd suggest to go for option a).
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher: Bezier curves

Post by DeepSOIC »

abdullah wrote:Point on Object seems like a requirement to support.
Point on object shouldn't be hard at all. In contrast, tangent, perpendicularity and angles are much trickier, since the framework I established for conics, where tangent can be easily calculated given x-y of point, doesn't work here. For that, we'll need to know the parameter value, and obtaining it from x-y coordinates involves numerical solving, so takes orders of magnitude more CPU cycles.

We can leave out most of constraints to curve for first merge, I think, because applying constraints to poles already gives a lot of freedom.
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Sketcher: Bezier curves

Post by Chris_G »

Hi,
Maybe I did not get the concept ok. What I understood is:
1) When forcing C1, you get G1 (equal first derivative vectors)
2) When forcing C2, you get G2 (equal second derivative vectors)

Basically what I understood is that C is enforcing a Vector with direction, while enforcing G is enforcing the magnitude, slope, curvatura and that enforcing C is easier than enforcing G... but as I said, I did not arrive to digest this bit yet and I may be absolutely off here...
C continuity has a mathematical meaning : equality of the derivatives
I read the definition of G continuity some time ago, but I'm afraid I won't be able to find the link again. It said :
"A curve A is Gn continuous to a curve B, when it can be reparametrized to be Cn continuous with B"

The thing to keep in mind ( but I think you already know that ) is that a parametric curve is not the curve that we see. It is the trip of a pen tip within a time interval. But what we care about, in the end, is the trace left by this pen tip.

C1 continuity is the continuity of the displacement of the pen tip at the transition between the 2 curves.
While G1 continuity is the visual continuity of the trace made by the pen tip.

C1 continuity : the pen tip reaches the end of curve A with tangent T and speed S and starts curve B with same tangent T and same speed S. When you look at this moving point, you can't guess where the curves are meeting, the movement is all smooth.
With G1 continuity, the pen tip can reach end of curve A with tangent T and speed S and start curve B with same tangent T and for example DOUBLE speed 2*S. When you look at this moving point, you will guess where the curves are meeting, when the speed of the point will suddenly double.
But we don't really care. We are interested with the trace left by the pen tip, and it is still smooth.

This is why, to me, C continuity is not really used in the CAD software videos I looked at.

C2 continuity is C1 + curvature matching at the meeting point.
G2 continuity is G1 + curvature matching at the meeting point.

Maybe, I've been a bit long, but, as my mathematical studies are pretty far away, it took me some time to get this. :D

Chris
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Sketcher: Bezier curves

Post by looo »

Knot vector: Big ?? One possibility is to show internal geometry points, but I am not sure how to constraint them (MicroElly's script shows what you can do with it, which is basically extending one rational curve segment at the expense of the adjacent ones), leaving the alternative you mention, hide them. It would be great to unveil a way of handle this.

Multiplicity: This is real issue for a good support. In DeepSOICs approach, I think this is obviated, as there is a single segment, so no reason for multiplicity, other than the endpoint multiplicity to make the line pass thru. An extension to the other two approaches would be to force the user to make separate BSplines and connect them with the appropriate constraint, as to force corners (if that is the reason for the multiple poles), or as to align them is that is the reason for it (for example to approximate a quarter of circle by a quadratic spline segment). An alternative would be to introduce an internal alignment constraint with GeoIDs the BSpline and the control point and using the value as an adimensional integer to mark the multiplicity. It requires the user to know what is the multiplicity used for, but I think we can not "automate" this.
To my understanding the multiplicity is directly coupled with the knot vector. Multiplicity could be implemented visual by setting two poles to the same position. The knot vector has the additional information of the distribution of the t-values. But I don't know if a non uniform spline really makes sense for the sketcher. I think the weights are more important then the non-uniformity.

regarding the point on spline problem, I think there are more options for this:
a: set a point to a t value: This way the spline can act as an interpolation, or approximation (if number of points on spline is higher then number of poles). This would add a graphical option of the "second" input form.
b: solve for the t-value: This may make sense if the spline is fully constrained (eg.: all poles are given) To fulfill other constraints the point has to "move" across the spline and the t-value has to change.
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Sketcher: Bezier curves

Post by Chris_G »

But I don't know if a non uniform spline really makes sense for the sketcher. I think the weights are more important then the non-uniformity.
This is not something I am sure to completely understand, but this article ( faculty.cs.tamu.edu/schaefer/research/cr_cad.pdf ) says that centripetal parameterisation guaranties no self-intersecting curves.
This is about Catmull-Rom curves, though. I am not sure it applies to B-splines curves ?
The Draft-Bspline has a Parameterisation property that ranges from 0.0 ( Uniform - Red curve ) to 1.0 ( Cord-length - Cyan ).
The yellow curve is Centripetal (value 0.5)
BSpline.jpeg
BSpline.jpeg (27.22 KiB) Viewed 2448 times
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Sketcher: Bezier curves

Post by Chris_G »

One more thing about G2 continuity ...
In this article ( cagd.cs.byu.edu/~557/text/ch2.pdf ) on page 15 ( formula 2.13 and figure 2.16 ) is showed the relation between the position of the P2 pole and the curvature, in a purely geometric way ... very interesting.
If ever I could find the same kind of formula for G3 ...
Post Reply