discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Bezier functions in OpenSCAD

DE
David Eccles (gringer)
Wed, Apr 1, 2015 10:49 AM

I found a bezier curve library that looks somewhat reasonable, in that it
doesn't have any hard-coded values or iteration limitations:

http://www.thingiverse.com/download:98926

Compare with this library, which suffers from "I need to write a different
function for different arguments" syndrome:

https://github.com/chadkirby/BezierScad/blob/master/BezierScad.scad

Is there any chance of adding at least the bezier functions to OpenSCAD:

/*
Bernstein Basis Functions

For Bezier curves, these functions give the weights per control point.

/
function BEZ03(u) = pow((1-u), 3);
function BEZ13(u) = 3
u*(pow((1-u),2));
function BEZ23(u) = 3*(pow(u,2))*(1-u);
function BEZ33(u) = pow(u,3);

// Calculate a singe point along a cubic bezier curve
// Given a set of 4 control points, and a parameter 0 <= 'u' <= 1
// These functions will return the exact point on the curve
function PointOnBezCubic2D(p0, p1, p2, p3, u) = [
BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0],
BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1]];

function PointOnBezCubic3D(p0, p1, p2, p3, u) = [
BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0],
BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1],
BEZ03(u)*p0[2]+BEZ13(u)*p1[2]+BEZ23(u)*p2[2]+BEZ33(u)*p3[2]];

The modules need a bit of work, because they're generating duplicate
points at the focal location, instead of combining the triangles into a
single polygon.

I found a bezier curve library that looks somewhat reasonable, in that it doesn't have any hard-coded values or iteration limitations: http://www.thingiverse.com/download:98926 Compare with this library, which suffers from "I need to write a different function for different arguments" syndrome: https://github.com/chadkirby/BezierScad/blob/master/BezierScad.scad Is there any chance of adding at least the bezier functions to OpenSCAD: /* Bernstein Basis Functions For Bezier curves, these functions give the weights per control point. */ function BEZ03(u) = pow((1-u), 3); function BEZ13(u) = 3*u*(pow((1-u),2)); function BEZ23(u) = 3*(pow(u,2))*(1-u); function BEZ33(u) = pow(u,3); // Calculate a singe point along a cubic bezier curve // Given a set of 4 control points, and a parameter 0 <= 'u' <= 1 // These functions will return the exact point on the curve function PointOnBezCubic2D(p0, p1, p2, p3, u) = [ BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0], BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1]]; function PointOnBezCubic3D(p0, p1, p2, p3, u) = [ BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0], BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1], BEZ03(u)*p0[2]+BEZ13(u)*p1[2]+BEZ23(u)*p2[2]+BEZ33(u)*p3[2]]; The modules need a bit of work, because they're generating duplicate points at the focal location, instead of combining the triangles into a single polygon.
PF
Peter Falke
Wed, Apr 1, 2015 2:13 PM

These functions only give a point vector.
The real work is to stitch a solid from this. (And if you can stitch the
solid, then you probably can write your own
Bezier function, too.)
Is there a a general way to generate a Bezier-solid ?
Maybe a pie-cylinder with the outside curve beeing a Bezier curve.
If yes, I would support it, as designs nowadays go more and more to organic
forms.

2015-04-01 12:49 GMT+02:00 David Eccles (gringer) <
bioinformatics@gringene.org>:

I found a bezier curve library that looks somewhat reasonable, in that it
doesn't have any hard-coded values or iteration limitations:

http://www.thingiverse.com/download:98926

Compare with this library, which suffers from "I need to write a different
function for different arguments" syndrome:

https://github.com/chadkirby/BezierScad/blob/master/BezierScad.scad

Is there any chance of adding at least the bezier functions to OpenSCAD:

/*
Bernstein Basis Functions

     For Bezier curves, these functions give the weights per control

point.

/
function BEZ03(u) = pow((1-u), 3);
function BEZ13(u) = 3
u*(pow((1-u),2));
function BEZ23(u) = 3*(pow(u,2))*(1-u);
function BEZ33(u) = pow(u,3);

// Calculate a singe point along a cubic bezier curve
// Given a set of 4 control points, and a parameter 0 <= 'u' <= 1
// These functions will return the exact point on the curve
function PointOnBezCubic2D(p0, p1, p2, p3, u) = [
BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0],
BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1]];

function PointOnBezCubic3D(p0, p1, p2, p3, u) = [
BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0],
BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1],
BEZ03(u)*p0[2]+BEZ13(u)*p1[2]+BEZ23(u)*p2[2]+BEZ33(u)*p3[2]];

The modules need a bit of work, because they're generating duplicate
points at the focal location, instead of combining the triangles into a
single polygon.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

These functions only give a point vector. The real work is to stitch a solid from this. (And if you can stitch the solid, then you probably can write your own Bezier function, too.) Is there a a general way to generate a Bezier-solid ? Maybe a pie-cylinder with the outside curve beeing a Bezier curve. If yes, I would support it, as designs nowadays go more and more to organic forms. 2015-04-01 12:49 GMT+02:00 David Eccles (gringer) < bioinformatics@gringene.org>: > I found a bezier curve library that looks somewhat reasonable, in that it > doesn't have any hard-coded values or iteration limitations: > > http://www.thingiverse.com/download:98926 > > Compare with this library, which suffers from "I need to write a different > function for different arguments" syndrome: > > https://github.com/chadkirby/BezierScad/blob/master/BezierScad.scad > > Is there any chance of adding at least the bezier functions to OpenSCAD: > > /* > Bernstein Basis Functions > > For Bezier curves, these functions give the weights per control > point. > > */ > function BEZ03(u) = pow((1-u), 3); > function BEZ13(u) = 3*u*(pow((1-u),2)); > function BEZ23(u) = 3*(pow(u,2))*(1-u); > function BEZ33(u) = pow(u,3); > > // Calculate a singe point along a cubic bezier curve > // Given a set of 4 control points, and a parameter 0 <= 'u' <= 1 > // These functions will return the exact point on the curve > function PointOnBezCubic2D(p0, p1, p2, p3, u) = [ > BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0], > BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1]]; > > function PointOnBezCubic3D(p0, p1, p2, p3, u) = [ > BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0], > BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1], > BEZ03(u)*p0[2]+BEZ13(u)*p1[2]+BEZ23(u)*p2[2]+BEZ33(u)*p3[2]]; > > The modules need a bit of work, because they're generating duplicate > points at the focal location, instead of combining the triangles into a > single polygon. > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > -- stempeldergeschichte@googlemail.com <karsten@rohrbach.de> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more. Enjoy!