{calculating BSpline?} Solved

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

{calculating BSpline?} Solved

Post by JoshM »

I need the functionality of the Draft.makeBSpline([points,]), minus drawing the object. I am looping through a Sliced Face, Discretizing the edges into Points, and creating points offset relative to the discretized points. Drawing the BSplines sequentially adds significant time.

I've looked a bit at Yorik's code in Draft module's BSpline class, and I think the bulk of what I need is in:

Code: Select all

    def parameterization (self, pts, a, closed):
        # Computes a knot Sequence for a set of points
        # fac (0-1) : parameterization factor
        # fac=0 -> Uniform / fac=0.5 -> Centripetal / fac=1.0 -> Chord-Length
        if closed: # we need to add the first point as the end point
            pts.append(pts[0])
        params = [0]
        for i in range(1,len(pts)):
            p = pts[i].sub(pts[i-1])
            pl = pow(p.Length,a)
            params.append(params[-1] + pl)
        return params
Any help appreciated.

I got it once I found wmayer's [url = https://forum.freecadweb.org/viewtopic.php?t=741[/url]URL post :

Code: Select all

def CalculateSpline(points_list):
	spline=Part.BSplineCurve()
	points=[]
	for i in points_list:
	points.append(i)

	spline.interpolate(points)
	spline.toShape()
	return spline


Post Reply