CAD Forums => CAD General => Topic started by: labaneseren on September 21, 2019, 11:10:51 AM

Title: B-Splines
Post by: labaneseren on September 21, 2019, 11:10:51 AM
I'm writing a script that produces a STEP AP203 that contains solid geometry.
I've noticed that almost all non-simple surfaces and curves are described in the STEP format by B Splines using the b_spline_curve/surface_with_knots functions.

Lets say I have a parametrically defined curve or surface. Well it looks like STEP won't let me describe it as that, and that I need to approximate it with a B Spline.

Do I need to write my own code from scratch that calculates the control points and knots that best approximates my curve, or it this functionality somehow available out there?
I've looked at stepcode and stepmod, but I cant figure out their exact usage. Did any of you use these?

Basically, right now I just need some code where I can input a set of coordinates that I want to lie on the curve/surface, and which then outputs the control points and knots that I need to define the proper B Spline.
Title: Re: B-Splines
Post by: labaneseren on October 25, 2019, 10:44:07 AM
Hi. Just wanted to share my solution with you guys.

I picked up the book "Curves and Surfaces for Computer Graphics" by David Salomon and read the sections on Bezier curves and B Splines. After reading this wonderfully crisp and clear description of splines, it was only a bit of math to get what I needed.

Basically, STEP files mostly use NURBS when defining curves. But the "b_spline_curve_with_knots" command allows for uniform b splines too. It does not discern between the two.
Although an approximating NURBS curve (such as least squares approximation) would be the superior solution for a best fit to a given number of points, it is mathematically much more sophisticated, and therefore not within my grasp right now. So I went with a simple interpolating B Spline, where each spline segment ends at my given points. For my current purpose it is sufficient.

STEP files almost only use "open b splines", which means the curve starts and ends at the first and last control points. So the task was to find the control points in between, which there are n-1 of. But there are only n-3 interpolating points, so I input the last two equations as the tangents at the start and end. This is now a linear system of n-1 vector equations, which is easily solved.

The figure here is my spline, where the 4 interpolating points are the black dots on the curve, and the 6 blue control points are the control points that make the curve pass through the 4 black points :) The tangents are also show as dotted lines.