Advice regards curve fitting - splines?

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Advice regards curve fitting - splines?

Gadgetmind
Hello all,

Following hot on the heels of my Thunderbird 1 design, I'm now wanting
to tackle a Fireflash.

http://gmart364.blogspot.co.uk/2012/07/fireflash-just-gorgeous-streamlined.html

Getting its curves right is going to be essential and I don't think I
can use distorted cones and ellipses this time.

I can get a number of points on the surface using drawings and calipers,
and I was then thinking of using splines through these to get me curved
lines running along the body. I could then use a closed spline through
points on these lines to create the geometry for the body.

Is this vaguely sensible?

Which spline or Bezier library is best?

I've had a *very* quick play with nSpline, which I like initially as I'm
happy with everything being in vectors with as many entries as I'm going
for facets for that particular preview/render.

https://www.thingiverse.com/thing:1208001

Thoughts?

Ian

(And yes, the end result will all be free and on Thingiverse!)




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Gadgetmind
On 2017-05-30 11:32, Ian Oliver wrote:
> Getting its curves right is going to be essential and I don't think I
> can use distorted cones and ellipses this time.

Ah, but I can use Super Ellipses and use splines to get dimensions,
locations and roundness/squareness parameters.

https://en.wikipedia.org/wiki/Superellipse

That should work.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Eric Buijs
The Bézier library of Caterpillar is well documented, so maybe that's an alternative to nSpline. You can find it here: https://openhome.cc/eGossip/OpenSCAD/BezierSurface.html

BTW: Your Thunderbird 1 looks nice.
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

caterpillar
In reply to this post by Gadgetmind
My library is located at https://github.com/JustinSDK/dotSCAD

The bezier_surface function and examples are demonstrated here:
https://openhome.cc/eGossip/OpenSCAD/lib-bezier_surface.html



I used it to create a wave base:
https://www.thingiverse.com/thing:2316887



BTW, I used the bezier_curve function to create a face several days ago:
https://www.thingiverse.com/thing:2350992



It's a proof of concept. Hope it can provide some ideas for how to design your thing.
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Gadgetmind
In reply to this post by Eric Buijs
On 2017-05-30 20:55, Eric Buijs wrote:
> The Bézier library of Caterpillar is well documented, so maybe that's an
> alternative to nSpline. You can find it here:

Many thanks. I'll play with that and see where it takes me.

> BTW: Your Thunderbird 1 looks nice.

Thanks, I'm very pleased with how the 3D model came out. I'm hoping
someone prints it and does a better finishing job than I did!

BTW I played with some linear sweeps of size and superellipse
roundness/squareness last night and got the attached out of some pretty
simple code. I should be able to use this to generate a vector
containing all of my body "slices", use a modified sweep function to
skin this as a polyhedron, but also then access the points data from
other code to generate spline control points for attaching tail/wings etc.

This one is going to be a long slog and I don't expect to have anything
close to printable for months!



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

RoughBody1.png (76K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Gadgetmind
In reply to this post by caterpillar

On 2017-05-31 09:59, caterpillar wrote:
> My library is located athttps://github.com/JustinSDK/dotSCAD

I've looked at that (in awe!) in the past but haven't yet had an excuse
to play with it. Now might be the time!

> It's a proof of concept. Hope it can provide some ideas for how to design
> your thing.

Great, thanks. I'm currently just after a "reading list" so I can work
through a few approaches and see what shows promise.



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Gadgetmind
In reply to this post by caterpillar
On 2017-05-31 09:59, caterpillar wrote:
> The bezier_surface function and examples are demonstrated here:
> https://openhome.cc/eGossip/OpenSCAD/lib-bezier_surface.html
>
>

I mentioned splines because my understanding (vague/wrong/whatever) is
that these pass through the control points as they have multiple
polynomial components, which is what I think I want for my smooth
interpolation. My plan is to take coordinates from blueprints with
calipers and then use splines (or whatever) to let me generate nice
curves to feed into my supersellipse sweeper thingy.



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Parkinbot
Gadgetmind wrote
My plan is to take coordinates from blueprints with
calipers and then use splines (or whatever) to let me generate nice
curves to feed into my supersellipse sweeper thingy.
Good plan. It will work. The general method is:
1. define a parametrized shape function like superellipse to generate an interpolable cross section
2. find the exact parameters and locations for a couple of "slices" and stuff them properly sequenced into a matrix - one row per slice. It is obviously important to choose "good" slices.
3. use nSpline() to interpolate the rows.
4. define a generator function that interpretes the cross section (superellipse) and the trajectory (e.g. Z axis) from the interpolated data and generates a sequence of polygons in 3D from it.
5. use sweep() from Naca_sweep.scad or skin() to extrude the full shape. skin() also lets you extrude along a series of shapes with an unequal number of points. This might be important for the caps.

reads more complicated than it is.

Here the sceleton as pseudo code:
A = [ ... ];             // define slices as rows of a matrix
IA = nSpline(A,N);  // interpolate between slices
E = gen_dat(IA, n); // generate skin data
sweep(E);  // or skin(E); // extrude the skin

function superellipse(n, ...) = // define a parameterized shape polygon e.g. as [[x1,y1,0], ..., [xn,yn,0]]
function gen_dat(A, n) = // split the rows of A into a shape S_i and trajectory T_i parameter portion. Call superellipse(n, S_i) and map the returned polygons using T_i into 3D.
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Gadgetmind
On 2017-05-31 12:23, Parkinbot wrote:
> 5. use sweep() from Naca_sweep.scad or skin() to extrude the full shape.
> skin() also lets you extrude along a series of shapes with an unequal number
> of points. This might be important for the caps.

Here is what I have now as a proof of concept.

Rot45 = sin(45);
// Generate one slice of the body
function SESlice (SE=1, xs=1, ys=1) = [
     for (t=[0: $fa : 359])
         let (
             x = pow(abs(cos(t)), 2/SE) * sign(cos(t)) ,
             y = pow(abs(sin(t)), 2/SE) * sign(sin(t))
         )
         // Rotate 45 degrees so scaling works properly and then scale
         [ xs * (x * Rot45 - y * Rot45), ys * (y * Rot45 + x * Rot45)]
];

BodySE=1.4;    // 1.4 is in the right ball park for centre
Steps = 100;

     skin([
         for (s=[0 : Steps-1])
             let (
                 sf = s/(Steps-1),
                 // Linear for now, needs a spline/lookup.
                 SE = BodySE + sf*(2-BodySE),
                 xs = 15 + sf*(1-15),
                 ys = 19 + sf*(1-19)
             )
             transform(translation([0,0,s]) * rotation([0,0,s*2]),
SESlice (SE=SE, xs=xs, ys=ys))
     ]);

Output attached and shows scaling working well and superellipse going
from slightly rounded rectangle to circle. That's a lot of flexibility
from some pretty simple code, but I'm glad I didn't have to write skin()
or the transform library!

I'm not sure I need the unequal number of points logic and currently
have it ripped out of my "cut and paste" version of skin (). Let's see.




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

RoughBody2.png (101K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Gadgetmind
On 2017-05-31 12:58, Ian Oliver wrote:
> Here is what I have now as a proof of concept.

Note that I think you were describing using superellipse to generate
some slices and then splines to interpolate (I think). I'm instead
looking to use splines to interpolate the various parameters that are
then used to generate a whole load of slices. I'll probably only need a
handful of spline control points for the whole body.

And then comes fun with wings etc., which I don't have much idea about
currently, but one problem at a time.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Gadgetmind
In reply to this post by Parkinbot
On 2017-05-31 12:23, Parkinbot wrote:
Good plan. It will work.

Yup, 100 lines of code and changing control points (only 4-5 so far) changes shape, roundness, and if you go <1 for superellipse factor, you get rockets for free!



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Gadgetmind
In reply to this post by Parkinbot
On 2017-05-31 12:23, Parkinbot wrote:
3. use nSpline() to interpolate the rows.

nSpline is working well and I'm using it for all of my open Splines. Can it handle closed ones? I have another spline lib (tjw-spline) doing that currently but if I can just use one library ...

I'm now mostly working with big bunches of points that I transform and skin. The tail on this FireFlash is formed from three sets of sixteen control points from a wing profile function, one set of these is then "dropped" onto the body points using a recursive closest point search, I then use nSpline to get many times more points running up the structure, tjw spline to get closed loops, and then skin the lot. Lots of splines, and fair bit of matrix maths/transpositions, and plenty of fun!

Original control from function = red, nSpline interpolated points = white, final skin points = black. This is the low res viewing version.




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Advice regards curve fitting - splines?

Parkinbot
Nice to read that nSpline() is fun to use. Sorry, I have not yet implemented closed splines. Shouldn't be to difficult, but I never found time (and reason) to go into that quite old piece of code again. It was my first serious OpenSCAD project and I remember that I really damned the language design of OpenSCAD functions that time.