knots and direction of B-Spline
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
knots and direction of B-Spline
I have just started to work with B-Splines and wonder if there is an easy way to walk along a B-Spline, find all knots and their direction (probably their derivative). Your help will be much appreciated
thanks
thanks
-
- Veteran
- Posts: 3182
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: knots and direction of B-Spline
Easy is in the eye of the beholder.
Create a single B-Spline in Sketcher and close. Select it and send to the python console with ctrl-shift-P.
bsp is your BSpline object. Command completion will give you the Properties and methods - like bsp.KnotSequence or bsp.getPolesAndWeights()
Unfortunately help(bsp) is truncated, but
Create a single B-Spline in Sketcher and close. Select it and send to the python console with ctrl-shift-P.
Code: Select all
bsp = sub.Curve
Unfortunately help(bsp) is truncated, but
Code: Select all
def fullhelp(obj):
list = [(getattr(obj, d), d) for d in obj.__dir__() if d[0] != '_' and not d[0].isupper()]
[help(l[0]) for l in sorted(list, key = lambda s: s[1])]
fullhelp(bsp)
[code]
gets the internal documentation.
Re: knots and direction of B-Spline
There are methods in OCCT that do that, named D0, D1 etc. I'm pretty sure they are exposed in Part::Geometry as well.
-
- Veteran
- Posts: 3182
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: knots and direction of B-Spline
Some properties of the <BSplineCurve object>
Code: Select all
Help on built-in function getD0:
getD0(...) method of Part.BSplineCurve instance
Returns the point of given parameter
Help on built-in function getD1:
getD1(...) method of Part.BSplineCurve instance
Returns the point and first derivative of given parameter
Help on built-in function getD2:
getD2(...) method of Part.BSplineCurve instance
Returns the point, first and second derivatives
Help on built-in function getD3:
getD3(...) method of Part.BSplineCurve instance
Returns the point, first, second and third derivatives
Help on built-in function getDN:
getDN(...) method of Part.BSplineCurve instance
Returns the n-th derivative
Re: knots and direction of B-Spline
That is an annoying limitation of the FreeCAD Gui. FreeCADCmd will give you the full help, however:
Code: Select all
bin/FreeCADCmd
FreeCAD 0.21.0, Libs: 0.21.0R33238 (Git)
(c) Juergen Riegel, Werner Mayer, Yorik van Havre and others 2001-2023
FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.
FreeCAD wouldn't be possible without FreeCAD community.
##### #### ### ####
# # # # # #
# ## #### #### # # # # #
#### # # # # # # # ##### # #
# # #### #### # # # # #
# # # # # # # # # ## ## ##
# # #### #### ### # # #### ## ## ##
[FreeCAD Console mode <Use Ctrl-D (i.e. EOF) to exit.>]
>>> import Part
>>> import readline
>>> help(Part.BSplineCurve)
Cheers,
Markus
Markus
Re: knots and direction of B-Spline
thanks for your input, that helped me.
However, I could not find anything what kind of parameter is require when calling D0 or D1. I want to call the points (D0) and their derivative D1.
I do get the points directly without any parameters using BSP03.Shape.Curve.NbPoles
However, I could not find anything what kind of parameter is require when calling D0 or D1. I want to call the points (D0) and their derivative D1.
I do get the points directly without any parameters using BSP03.Shape.Curve.NbPoles
-
- Veteran
- Posts: 3182
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: knots and direction of B-Spline
BSP03.Shape.Curve.NbPoles is an integer - the number of Poles of the BSpline.
In FreeCAD every Curve that describes the geometry on an Edge is defined parametrically by equations. For instance, a circle at the origin, of radius R in the XY-Plane is
Code: Select all
x(t) = R * cos(t)
y(t) = R * sin(t)
z(t) = 0
Straight lines, conics etc. likewise, are defined by an algebraic parameterization. You find a point on the curve with parameter t with
Code: Select all
edge.Curve.value(t)
Code: Select all
p, t = edge.Curve.getD1(t)
Moving on to BSplines. A BSpline curve bsp is parameterized by a sequence of polynomials of degree bsp.Degree. The entire parameterization is divided into intervals t0 <= t1 <= t2 <= ..... <=tn given by bsp.KnotSequence (aka a knot vector). In each interval, there is a different polynomial whose values are influenced by neighboring Poles (aka control points), given by bsp.getPoles(). In the sketcher, it's the poles/control points you move around. They are the handles in Adobe Illustrator.
By manipulating the multiplicities (equality of neighboring t values in the knot vector), you can force a BSpline to go through the corresponding control point, but only at the cost of smoothness at the connection point. This is typically always done at the end-points of the BSpline, and can be done at interior points.
Freya Holmer made an awesome video about Bezier Curves (which are a particular kind of BSpline), showing how they work. https://www.youtube.com/watch?v=aVwxzDHniEw Do some googling, there's lots out there about BSplines. I have a 300 page book about them!
If you have a specific thing you want to do with your BSpline, we can likely point you at the method that does the job.
Re: knots and direction of B-Spline
thanks for your clear explanation and your references (video). This helped me a lot. I have never been in contact with B-Splines in the past.
Seems to be a great tool
Seems to be a great tool