discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: Bezier curves, Bezier surfaces, b-splines, NURBS

JB
Jordan Brown
Fri, Sep 2, 2022 7:25 PM

Libraries are a fine answer.  There's no need for them to be built in,
and little or no advantage to having them built in.

Probably the strongest is BOSL2, which has a substantial list of Bézier
curve and patch functions:
https://github.com/revarbat/BOSL2/wiki/beziers.scad

It isn't clear to me what happens when you transform Bézier control
points, versus transforming the resulting curve.  Nothing bad happens
when you transform the resulting curve.  It transforms, just like any
other points do.  I don't know what happens when you transform the
control points and then make the curve.  (Adrian?)

(Aw, geez, now I'm going to have to go do some experiments.)

Anyhow, take a look at the BOSL2 functions.  I think they'll do most
everything one might want to do with Bézier curves.

Libraries are a fine answer.  There's no need for them to be built in, and little or no advantage to having them built in. Probably the strongest is BOSL2, which has a substantial list of Bézier curve and patch functions: https://github.com/revarbat/BOSL2/wiki/beziers.scad It isn't clear to me what happens when you transform Bézier control points, versus transforming the resulting curve.  Nothing bad happens when you transform the resulting curve.  It transforms, just like any other points do.  I don't know what happens when you transform the control points and *then* make the curve.  (Adrian?) (Aw, geez, now I'm going to have to go do some experiments.) Anyhow, take a look at the BOSL2 functions.  I think they'll do most everything one might want to do with Bézier curves.
AM
Adrian Mariano
Fri, Sep 2, 2022 9:14 PM

A linear translation of a bezier curve control points gives the
transformation of the curve.  In fact, BOSL2 will apply linear operators on
bezier control point lists.

The real difficulty with beziers isn't making the curves, though there is
some subtlety.  I spent a lot of time optimizing the computation of beziers
for BOSL2 and found that using a matrix representation is substantially
faster.  This matters when you have lots of points on a 3d surface and
you're doing previews, not renders.

No, the real difficulty is in how you make a 3d bezier curve that
represents the desired shape, and BOSL2 doesn't provide any powerful
generic way to do that in 3d.  (We don't know how to do it!  Suggestions
welcome.)  There are some modules that use beziers for specific rounding
operations that you can see in
https://github.com/revarbat/BOSL2/wiki/rounding.scad and you may notice
that I have an interesting in continuous curvature rounding which shows up
in several places.

On Fri, Sep 2, 2022 at 3:26 PM Jordan Brown openscad@jordan.maileater.net
wrote:

Libraries are a fine answer.  There's no need for them to be built in, and
little or no advantage to having them built in.

Probably the strongest is BOSL2, which has a substantial list of Bézier
curve and patch functions:
https://github.com/revarbat/BOSL2/wiki/beziers.scad

It isn't clear to me what happens when you transform Bézier control
points, versus transforming the resulting curve.  Nothing bad happens when
you transform the resulting curve.  It transforms, just like any other
points do.  I don't know what happens when you transform the control points
and then make the curve.  (Adrian?)

(Aw, geez, now I'm going to have to go do some experiments.)

Anyhow, take a look at the BOSL2 functions.  I think they'll do most
everything one might want to do with Bézier curves.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

A linear translation of a bezier curve control points gives the transformation of the curve. In fact, BOSL2 will apply linear operators on bezier control point lists. The real difficulty with beziers isn't making the curves, though there is some subtlety. I spent a lot of time optimizing the computation of beziers for BOSL2 and found that using a matrix representation is substantially faster. This matters when you have lots of points on a 3d surface and you're doing previews, not renders. No, the real difficulty is in how you make a 3d bezier curve that represents the desired shape, and BOSL2 doesn't provide any powerful generic way to do that in 3d. (We don't know how to do it! Suggestions welcome.) There are some modules that use beziers for specific rounding operations that you can see in https://github.com/revarbat/BOSL2/wiki/rounding.scad and you may notice that I have an interesting in continuous curvature rounding which shows up in several places. On Fri, Sep 2, 2022 at 3:26 PM Jordan Brown <openscad@jordan.maileater.net> wrote: > Libraries are a fine answer. There's no need for them to be built in, and > little or no advantage to having them built in. > > Probably the strongest is BOSL2, which has a substantial list of Bézier > curve and patch functions: > https://github.com/revarbat/BOSL2/wiki/beziers.scad > > It isn't clear to me what happens when you transform Bézier control > points, versus transforming the resulting curve. Nothing bad happens when > you transform the resulting curve. It transforms, just like any other > points do. I don't know what happens when you transform the control points > and *then* make the curve. (Adrian?) > > (Aw, geez, now I'm going to have to go do some experiments.) > > Anyhow, take a look at the BOSL2 functions. I think they'll do most > everything one might want to do with Bézier curves. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Fri, Sep 2, 2022 10:26 PM

On 9/2/2022 2:14 PM, Adrian Mariano wrote:

No, the real difficulty is in how you make a 3d bezier curve that
represents the desired shape, and BOSL2 doesn't provide any powerful
generic way to do that in 3d.  (We don't know how to do it! 
Suggestions welcome.)

Best idea I can think of is to use the Customizer to let you play with
the coordinates of the control points until you get the shape you like. 
But yes.  I tried to reverse engineer the "Gumbo
https://en.wikipedia.org/wiki/B%C3%A9zier_surface#/media/File:Bicubic_Patches.png"
Bézier-surface model, and didn't get very far.

One other thing that might be steal-able from 2D drawing programs is in
how you join curves (and presumably surfaces) together.  At the junction
they usually have "cusps", where the two line segments pointing at the
control points are totally independent, "smooth", where they are 180°
apart but of independent lengths, and "symmetric", where they are 180°
apart and the same length.  Those restrictions make for useful shapes at
the transition.

I think you and I talked a little a while back about how that concept
might be applied to a sequence of Bézier curves, but I don't remember
whether we ever came up with anything solid and I'm pretty sure we
didn't extend it to surfaces.

On 9/2/2022 2:14 PM, Adrian Mariano wrote: > No, the real difficulty is in how you make a 3d bezier curve that > represents the desired shape, and BOSL2 doesn't provide any powerful > generic way to do that in 3d.  (We don't know how to do it!  > Suggestions welcome.) Best idea I can think of is to use the Customizer to let you play with the coordinates of the control points until you get the shape you like.  But yes.  I tried to reverse engineer the "Gumbo <https://en.wikipedia.org/wiki/B%C3%A9zier_surface#/media/File:Bicubic_Patches.png>" Bézier-surface model, and didn't get very far. One other thing that might be steal-able from 2D drawing programs is in how you join curves (and presumably surfaces) together.  At the junction they usually have "cusps", where the two line segments pointing at the control points are totally independent, "smooth", where they are 180° apart but of independent lengths, and "symmetric", where they are 180° apart and the same length.  Those restrictions make for useful shapes at the transition. I think you and I talked a little a while back about how that concept might be applied to a sequence of Bézier curves, but I don't remember whether we ever came up with anything solid and I'm pretty sure we didn't extend it to surfaces.
JB
Jordan Brown
Sat, Sep 3, 2022 2:07 AM

On 9/2/2022 3:26 PM, Jordan Brown wrote:

On 9/2/2022 2:14 PM, Adrian Mariano wrote:

No, the real difficulty is in how you make a 3d bezier curve that
represents the desired shape, and BOSL2 doesn't provide any powerful
generic way to do that in 3d.  (We don't know how to do it! 
Suggestions welcome.)

I thought it was hard to come up with a generic mechanism.

After a couple of private messages with Adrian, I have revised my opinion.

I now think that it is Very Hard.

Any one patch is not awful.  Trying to stitch patches together into 3D
objects is clearly possible, because people do it, but I don't see how.

On 9/2/2022 3:26 PM, Jordan Brown wrote: > On 9/2/2022 2:14 PM, Adrian Mariano wrote: >> No, the real difficulty is in how you make a 3d bezier curve that >> represents the desired shape, and BOSL2 doesn't provide any powerful >> generic way to do that in 3d.  (We don't know how to do it!  >> Suggestions welcome.) > I thought it was hard to come up with a generic mechanism. After a couple of private messages with Adrian, I have revised my opinion. I now think that it is Very Hard. Any one patch is not awful.  Trying to stitch patches together into 3D objects is clearly possible, because people do it, but I don't see how.
AG
andrew goh
Sat, Sep 3, 2022 5:13 AM

On 03/09/2022 10:07, Jordan Brown wrote:

On 9/2/2022 3:26 PM, Jordan Brown wrote:

On 9/2/2022 2:14 PM, Adrian Mariano wrote:

No, the real difficulty is in how you make a 3d bezier curve that
represents the desired shape, and BOSL2 doesn't provide any powerful
generic way to do that in 3d. (We don't know how to do it! 
Suggestions welcome.)

I thought it was hard to come up with a generic mechanism.

After a couple of private messages with Adrian, I have revised my opinion.

I now think that it is Very Hard.

Any one patch is not awful.  Trying to stitch patches together into 3D
objects is clearly possible, because people do it, but I don't see how.

We are probably trying to do things that 3D CAD software like Maya
(https://www.autodesk.com.sg/products/maya/overview) and Blender
(https://www.blender.org/) is doing. Maya is commercial, but Blender is
open source. I think those use NURBS which is more elaborate (and
difficult) compared to say cubic 3d bezier curves (and possibly surfaces).

My gripe about those 'huge' software is partly that they are much more
'heavier' compared to OpenSCAD for 'simple things'. But the idea is that
we can use those 'heavy' cad software to make those difficult "organic"
looking  surfaces and objects. Then "import" them preferably just the
control points and integrate those models into OpenSCAD.

Such features likely necessitates similar implementations of Bezier
curves/surfaces and/or NURBS in OpenSCAD. It is especially true for
those Bezier, NURBS surfaces as they are often complex and computation
intensive.

On 03/09/2022 10:07, Jordan Brown wrote: > On 9/2/2022 3:26 PM, Jordan Brown wrote: >> On 9/2/2022 2:14 PM, Adrian Mariano wrote: >>> No, the real difficulty is in how you make a 3d bezier curve that >>> represents the desired shape, and BOSL2 doesn't provide any powerful >>> generic way to do that in 3d. (We don't know how to do it!  >>> Suggestions welcome.) >> > > I thought it was hard to come up with a generic mechanism. > > After a couple of private messages with Adrian, I have revised my opinion. > > I now think that it is Very Hard. > > Any one patch is not awful.  Trying to stitch patches together into 3D > objects is clearly possible, because people do it, but I don't see how. > > We are probably trying to do things that 3D CAD software like Maya (https://www.autodesk.com.sg/products/maya/overview) and Blender (https://www.blender.org/) is doing. Maya is commercial, but Blender is open source. I think those use NURBS which is more elaborate (and difficult) compared to say cubic 3d bezier curves (and possibly surfaces). My gripe about those 'huge' software is partly that they are much more 'heavier' compared to OpenSCAD for 'simple things'. But the idea is that we can use those 'heavy' cad software to make those difficult "organic" looking  surfaces and objects. Then "import" them preferably just the control points and integrate those models into OpenSCAD. Such features likely necessitates similar implementations of Bezier curves/surfaces and/or NURBS in OpenSCAD. It is especially true for those Bezier, NURBS surfaces as they are often complex and computation intensive.
AG
andrew goh
Sat, Sep 3, 2022 6:13 AM

On 03/09/2022 06:26, Jordan Brown wrote:

On 9/2/2022 2:14 PM, Adrian Mariano wrote:

No, the real difficulty is in how you make a 3d bezier curve that
represents the desired shape, and BOSL2 doesn't provide any powerful
generic way to do that in 3d. (We don't know how to do it! 
Suggestions welcome.)

Best idea I can think of is to use the Customizer to let you play with
the coordinates of the control points until you get the shape you
like.  But yes.  I tried to reverse engineer the "Gumbo
https://en.wikipedia.org/wiki/B%C3%A9zier_surface#/media/File:Bicubic_Patches.png"
Bézier-surface model, and didn't get very far.

One other thing that might be steal-able from 2D drawing programs is
in how you join curves (and presumably surfaces) together.  At the
junction they usually have "cusps", where the two line segments
pointing at the control points are totally independent, "smooth",
where they are 180° apart but of independent lengths, and "symmetric",
where they are 180° apart and the same length. Those restrictions make
for useful shapes at the transition.

I think you and I talked a little a while back about how that concept
might be applied to a sequence of Bézier curves, but I don't remember
whether we ever came up with anything solid and I'm pretty sure we
didn't extend it to surfaces.

I'm thinking that NURBS is probably a "better" representation for
"organic" 3d surfaces.

https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline
https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline

NURBS appear simpler to build than do Bezier surfaces and NURBS surfaces
has deliberately designed surface equations / formulas, i.e. it is
intended for that use.
While Bezier surfaces feels more like a 'hack', e.g. one could create
Bezier curves for the x-axis directions then peg control points on this
bezier to make another one on the y-axis. That makes a 'Bezier surface'
kind of, but to tune control points this way is likely more difficult
than do say a 3d NURBS surface equation that is deliberately designed
for purpose. i.e. the 3d NURBS surface is simply a NURBS surface with
its 3d control points defined.

On 03/09/2022 06:26, Jordan Brown wrote: > On 9/2/2022 2:14 PM, Adrian Mariano wrote: >> No, the real difficulty is in how you make a 3d bezier curve that >> represents the desired shape, and BOSL2 doesn't provide any powerful >> generic way to do that in 3d. (We don't know how to do it!  >> Suggestions welcome.) > > Best idea I can think of is to use the Customizer to let you play with > the coordinates of the control points until you get the shape you > like.  But yes.  I tried to reverse engineer the "Gumbo > <https://en.wikipedia.org/wiki/B%C3%A9zier_surface#/media/File:Bicubic_Patches.png>" > Bézier-surface model, and didn't get very far. > > One other thing that might be steal-able from 2D drawing programs is > in how you join curves (and presumably surfaces) together.  At the > junction they usually have "cusps", where the two line segments > pointing at the control points are totally independent, "smooth", > where they are 180° apart but of independent lengths, and "symmetric", > where they are 180° apart and the same length. Those restrictions make > for useful shapes at the transition. > > I think you and I talked a little a while back about how that concept > might be applied to a sequence of Bézier curves, but I don't remember > whether we ever came up with anything solid and I'm pretty sure we > didn't extend it to surfaces. > > I'm thinking that NURBS is probably a "better" representation for "organic" 3d surfaces. https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline <https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline> NURBS appear simpler to build than do Bezier surfaces and NURBS surfaces has deliberately designed surface equations / formulas, i.e. it is intended for that use. While Bezier surfaces feels more like a 'hack', e.g. one could create Bezier curves for the x-axis directions then peg control points on this bezier to make another one on the y-axis. That makes a 'Bezier surface' kind of, but to tune control points this way is likely more difficult than do say a 3d NURBS surface equation that is deliberately designed for purpose. i.e. the 3d NURBS surface is simply a NURBS surface with its 3d control points defined.
AG
andrew goh
Sat, Sep 3, 2022 8:08 AM

On 03/09/2022 05:14, Adrian Mariano wrote:

A linear translation of a bezier curve control points gives the
transformation of the curve.  In fact, BOSL2 will apply linear
operators on bezier control point lists.

The real difficulty with beziers isn't making the curves, though there
is some subtlety.  I spent a lot of time optimizing the computation of
beziers for BOSL2 and found that using a matrix representation is
substantially faster.  This matters when you have lots of points on a
3d surface and you're doing previews, not renders.

No, the real difficulty is in how you make a 3d bezier curve that
represents the desired shape, and BOSL2 doesn't provide any powerful
generic way to do that in 3d.  (We don't know how to do it! 
Suggestions welcome.)   There are some modules that use beziers for
specific rounding operations that you can see in
https://github.com/revarbat/BOSL2/wiki/rounding.scad
https://github.com/revarbat/BOSL2/wiki/rounding.scad and you may
notice that I have an interesting in continuous curvature rounding
which shows up in several places.

NURBS


I'm thinking that it could be good to explore NURBS, I'm in no way
'expert' nor familiar with NURBS - the 'technology', its maths etc. But
as like described in Wikipedia,

https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline
https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline

it seemed NURBS is a (significantly) more complex model with more
parameters such as control points, weight vectors, knot vectors, order etc.
we could 'experiment' with OpenSCAD scripts for NURBS representations.

But that I actually hoping eventually, there could be some native
implementations of NURBS in OpenSCAD, given that these are complicated
(complex) structures.
They should perhaps use similar models, representations say by those
used in Blender (https://www.blender.org/) etc, so that Blender could
perhaps be used as an 'Editor' for those NURBS surfaces and then
'exported' into OpenSCAD scripts.

The idea about the 'native' (i.e. built-in to OpenSCAD) representations
is simply that it is likely more compact to simply store the control
points, knot vectors, weight vectors, order etc as parameters than to
perhaps store a polyhedron representation of it. And it makes it more
adaptable to text editing the control points, knot vectors, weight
vectors etc. afterwards.


Bezier control points affine transforms

As to the translation (or even affine transform) of bezier control
points. I've been wondering how it is done.

I made an attempt to reproduce the cubic bezier paths as is described in
W3C SVG specs

https://www.w3.org/TR/SVG11/paths.html#PathDataCubicBezierCommands

my attempt is posted here earlier, and in the mailing list archive archive:

https://lists.openscad.org/empathy/thread/JFHNH4RTCSKTX5ZJJNOBMZZH3GTEJEZJ

It turns out that how W3C SVG does it is: it treats the 1st control
point as the origin, i.e. 0.0.0. i.e. it makes the (cubic) bezier
locally referenced to the 1st control point.
This is even though the coordinates given in a SVG path statement is
given as absolute coordinates. i.e. the 1st control point (given in
absolute coordinates) is simply treated as the origin and reference
point. In this way, beziers can be affine transformed, scaled, rotated
etc. But I'm not too sure if it'd 'break' the bezier paths (curves) still.

I tried things like to use absolute coordinates in my attempt to
reproduce the W3C SVG specs for the cubic bezier curves. If i used
absolute coordinates, it gives completely different bezier curves that
do not conform to the shapes as published by W3C in the specs

https://www.w3.org/TR/SVG11/images/paths/cubic02.svg

only when i make the 1st control point the origin (locally referenced),
I managed to reproduce this and it look pretty much similar to W3C SVG
specs.

https://lists.openscad.org/empathy/thread/JFHNH4RTCSKTX5ZJJNOBMZZH3GTEJEZJ

On 03/09/2022 05:14, Adrian Mariano wrote: > A linear translation of a bezier curve control points gives the > transformation of the curve.  In fact, BOSL2 will apply linear > operators on bezier control point lists. > > The real difficulty with beziers isn't making the curves, though there > is some subtlety.  I spent a lot of time optimizing the computation of > beziers for BOSL2 and found that using a matrix representation is > substantially faster.  This matters when you have lots of points on a > 3d surface and you're doing previews, not renders. > > No, the real difficulty is in how you make a 3d bezier curve that > represents the desired shape, and BOSL2 doesn't provide any powerful > generic way to do that in 3d.  (We don't know how to do it!  > Suggestions welcome.)   There are some modules that use beziers for > specific rounding operations that you can see in > https://github.com/revarbat/BOSL2/wiki/rounding.scad > <https://github.com/revarbat/BOSL2/wiki/rounding.scad> and you may > notice that I have an interesting in continuous curvature rounding > which shows up in several places. > NURBS ---- I'm thinking that it could be good to explore NURBS, I'm in no way 'expert' nor familiar with NURBS - the 'technology', its maths etc. But as like described in Wikipedia, https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline <https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline> it seemed NURBS is a (significantly) more complex model with more parameters such as control points, weight vectors, knot vectors, order etc. we could 'experiment' with OpenSCAD scripts for NURBS representations. But that I actually hoping eventually, there could be some native implementations of NURBS in OpenSCAD, given that these are complicated (complex) structures. They should perhaps use similar models, representations say by those used in Blender (https://www.blender.org/) etc, so that Blender could perhaps be used as an 'Editor' for those NURBS surfaces and then 'exported' into OpenSCAD scripts. The idea about the 'native' (i.e. built-in to OpenSCAD) representations is simply that it is likely more compact to simply store the control points, knot vectors, weight vectors, order etc as parameters than to perhaps store a polyhedron representation of it. And it makes it more adaptable to text editing the control points, knot vectors, weight vectors etc. afterwards. ----- Bezier control points affine transforms As to the translation (or even affine transform) of bezier control points. I've been wondering how it is done. I made an attempt to reproduce the cubic bezier paths as is described in W3C SVG specs https://www.w3.org/TR/SVG11/paths.html#PathDataCubicBezierCommands my attempt is posted here earlier, and in the mailing list archive archive: https://lists.openscad.org/empathy/thread/JFHNH4RTCSKTX5ZJJNOBMZZH3GTEJEZJ It turns out that how W3C SVG does it is: it treats the 1st control point as the *origin*, i.e. 0.0.0. i.e. it makes the (cubic) bezier *locally referenced* to the 1st control point. This is even though the coordinates given in a SVG path statement is given as absolute coordinates. i.e. the 1st control point (given in absolute coordinates) is simply treated as the origin and reference point. In this way, beziers can be affine transformed, scaled, rotated etc. But I'm not too sure if it'd 'break' the bezier paths (curves) still. I tried things like to use absolute coordinates in my attempt to reproduce the W3C SVG specs for the cubic bezier curves. If i used absolute coordinates, it gives completely different bezier curves that do not conform to the shapes as published by W3C in the specs https://www.w3.org/TR/SVG11/images/paths/cubic02.svg only when i make the 1st control point the origin (locally referenced), I managed to reproduce this and it look pretty much similar to W3C SVG specs. https://lists.openscad.org/empathy/thread/JFHNH4RTCSKTX5ZJJNOBMZZH3GTEJEZJ