Nabble removed Mailing-list integration from the Forum.
This killed the Forum. This is now an ARCHIVE.
It is likely Nabble will shutdown in the future.

So basically the Forum is now out of date, we are looking into migrating the history.

OpenSCAD support is now provided by the Mailing List.
See the first pinned post here for instructions on subscribing to the mailing list.

Rounded Polygon

classic Classic list List threaded Threaded
184 messages Options
12345 ... 10
Reply | Threaded
Open this post in threaded view
|

Re: Rounded Polygon

adrianv
The round-anything library includes this, which rounds inside and outside
corners independently with separate rounding radii.  You can set IR or OR to
zero as desired if you want only internal or external rounding.  Looks short
and elegant to me.  Does this have some shortcomings I'm overlooking
compared to the other versions?  

module round2d(OR=3,IR=1){
  offset(OR){
    offset(-IR-OR){
      offset(IR){
        children();
      }
    }
  }
}

So this is nice for the cases that it addresses, but it doesn't address the
problem that the more general polyround does, with the possibility of
rounding only some corners, and rounding different corners by different
amounts, and doing the rounding to a point list that can be input to sweep
type operations.    



--
Sent from: http://forum.openscad.org/

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

Re: Rounded Polygon

William Adams-2
Would it be possible to use this tool to get rounding as is done in some industrial designs?


If not, could someone suggest a suitable technique to achieve this?

William


On Tue, Mar 12, 2019 at 9:40 AM adrianv <[hidden email]> wrote:
The round-anything library includes this, which rounds inside and outside
corners independently with separate rounding radii.  You can set IR or OR to
zero as desired if you want only internal or external rounding.  Looks short
and elegant to me.  Does this have some shortcomings I'm overlooking
compared to the other versions? 

module round2d(OR=3,IR=1){
  offset(OR){
    offset(-IR-OR){
      offset(IR){
        children();
      }
    }
  }
}

So this is nice for the cases that it addresses, but it doesn't address the
problem that the more general polyround does, with the possibility of
rounding only some corners, and rounding different corners by different
amounts, and doing the rounding to a point list that can be input to sweep
type operations.   



--
Sent from: http://forum.openscad.org/

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

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

Re: Rounded Polygon

nophead
I don't thinks so because all the rounding discussed so far uses circular arcs that meet straight lines tangentially. That is continuous in gradient but has a discontinuity of curvature. Possibly Bezier splines would do the job?

On Tue, 12 Mar 2019 at 14:27, William Adams <[hidden email]> wrote:
Would it be possible to use this tool to get rounding as is done in some industrial designs?


If not, could someone suggest a suitable technique to achieve this?

William


On Tue, Mar 12, 2019 at 9:40 AM adrianv <[hidden email]> wrote:
The round-anything library includes this, which rounds inside and outside
corners independently with separate rounding radii.  You can set IR or OR to
zero as desired if you want only internal or external rounding.  Looks short
and elegant to me.  Does this have some shortcomings I'm overlooking
compared to the other versions? 

module round2d(OR=3,IR=1){
  offset(OR){
    offset(-IR-OR){
      offset(IR){
        children();
      }
    }
  }
}

So this is nice for the cases that it addresses, but it doesn't address the
problem that the more general polyround does, with the possibility of
rounding only some corners, and rounding different corners by different
amounts, and doing the rounding to a point list that can be input to sweep
type operations.   



--
Sent from: http://forum.openscad.org/

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

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

Re: Rounded Polygon

rew
On Tue, Mar 12, 2019 at 03:06:43PM +0000, nop head wrote:
> I don't thinks so because all the rounding discussed so far uses circular
> arcs that meet straight lines tangentially. That is continuous in gradient
> but has a discontinuity of curvature. Possibly Bezier splines would do the
> job?

I would REALLY like to have bezier curves in openscad. The $fn parameter
would determine how many interpolation points would be used to convert the
spline to triangles.

The problem is a bit how to integrate the splines with the rest of
openscad: all primitives are 3D OBJECTS and splines usually define a
surface (in 3D if required).

We already can create an object from arbitrary 3D points, right?
(or is this only possible for 2D objects? Ah! I should know this: I
designed pyramids from 5 vertices with my niece this weekend, Duh!).

So it would suffice if a function could return a list of points (*)
corresponding to a definition of an object defined by bezier surfaces.

On the other hand, the "define bezier primitive" could internally
build on the polyhedron function: building the list-of-vertices and
faces as it processes its own input...

I think the "create bezier object" primitve would have very similar
arguments as the polyhedron primitve: A list of vertices and a list of
faces. To define a bezier patch you need precisely 16 vertices for
each patch.


        Roger.


(*) Not sure if such a function can return a complex object in the
current implementation: both the list-of-points and the
list-of-vertices that define the triangles. That's be nice.


>
> On Tue, 12 Mar 2019 at 14:27, William Adams <[hidden email]> wrote:
>
> > Would it be possible to use this tool to get rounding as is done in some
> > industrial designs?
> >
> >
> > https://hackernoon.com/apples-icons-have-that-shape-for-a-very-good-reason-720d4e7c8a14
> >
> > If not, could someone suggest a suitable technique to achieve this?
> >
> > William
> >
> >
> > On Tue, Mar 12, 2019 at 9:40 AM adrianv <[hidden email]> wrote:
> >
> >> The round-anything library includes this, which rounds inside and outside
> >> corners independently with separate rounding radii.  You can set IR or OR
> >> to
> >> zero as desired if you want only internal or external rounding.  Looks
> >> short
> >> and elegant to me.  Does this have some shortcomings I'm overlooking
> >> compared to the other versions?
> >>
> >> module round2d(OR=3,IR=1){
> >>   offset(OR){
> >>     offset(-IR-OR){
> >>       offset(IR){
> >>         children();
> >>       }
> >>     }
> >>   }
> >> }
> >>
> >> So this is nice for the cases that it addresses, but it doesn't address
> >> the
> >> problem that the more general polyround does, with the possibility of
> >> rounding only some corners, and rounding different corners by different
> >> amounts, and doing the rounding to a point list that can be input to sweep
> >> type operations.
> >>
> >>
> >>
> >> --
> >> Sent from: http://forum.openscad.org/
> >>
> >> _______________________________________________
> >> OpenSCAD mailing list
> >> [hidden email]
> >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> >>
> > _______________________________________________
> > OpenSCAD mailing list
> > [hidden email]
> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> >

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


--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might 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: Rounded Polygon

JordanBrown
On 3/12/2019 10:55 AM, Rogier Wolff wrote:
(*) Not sure if such a function can return a complex object in the current implementation: both the list-of-points and the list-of-vertices that define the triangles. That's be nice.


Sure.  Just return a vector, the first element of which is a vector of points and the second element of which is a vector of vertices.


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

Re: Rounded Polygon

adrianv
In reply to this post by nophead
Definitely none of the rounding code I've seen does this directly.  Thanks
for bringing this to my attention.  I'm actually interested in mplementing
this myself.  Does it make sense to use tangent circles to define the
location of the curved section and then fit a bezier instead of a circular
arc into the space?  Or is there some better way to define the space where
the curve should go at a given corner?  Like perhaps a setback distance
along the edge from the corner?  


nophead wrote
> I don't thinks so because all the rounding discussed so far uses circular
> arcs that meet straight lines tangentially. That is continuous in gradient
> but has a discontinuity of curvature. Possibly Bezier splines would do the
> job?
>
> On Tue, 12 Mar 2019 at 14:27, William Adams &lt;

> will.adams@

> &gt; wrote:
>
>> Would it be possible to use this tool to get rounding as is done in some
>> industrial designs?
>>
>>
>> https://hackernoon.com/apples-icons-have-that-shape-for-a-very-good-reason-720d4e7c8a14
>>
>> If not, could someone suggest a suitable technique to achieve this?
>>
>> William
>>





--
Sent from: http://forum.openscad.org/

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

Re: Rounded Polygon

adrianv
In reply to this post by rew
rew wrote

> On Tue, Mar 12, 2019 at 03:06:43PM +0000, nop head wrote:
>> I don't thinks so because all the rounding discussed so far uses circular
>> arcs that meet straight lines tangentially. That is continuous in
>> gradient
>> but has a discontinuity of curvature. Possibly Bezier splines would do
>> the
>> job?
>
> I would REALLY like to have bezier curves in openscad. The $fn parameter
> would determine how many interpolation points would be used to convert the
> spline to triangles.

Does it need to be in the base language for some reason?  Bezier curves have
been implemented several times.  Here are three examples:

https://github.com/revarbat/BOSL/wiki/beziers.scad
https://www.thingiverse.com/thing:8483/attribution_is_important
https://github.com/JustinSDK/dotSCAD

And actually that third one has a bezier_smooth function that maybe does the
smooth curvature smoothing that was requested.  




--
Sent from: http://forum.openscad.org/

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

Re: Rounded Polygon

nophead
In reply to this post by adrianv
I don't have an artistic bone in my body, so to me circles meeting tangents are fine. I don't have any Apple products and probably never will as they are just a waste of money. They look nice but are very unreliable and locked in.

If I could see a need for avoiding discontinuities in curvature I am sure I could work something out with Bezier splines but life is too short. I use Bezier splines to approximate minimum energy curves to model bent strips. 2D Bezier curves are easy in OpenSCAD, and 3D Bezier curves are certainly possible with polyhedron. I don't think new primitives are needed.

On Tue, 12 Mar 2019 at 23:15, adrianv <[hidden email]> wrote:
Definitely none of the rounding code I've seen does this directly.  Thanks
for bringing this to my attention.  I'm actually interested in mplementing
this myself.  Does it make sense to use tangent circles to define the
location of the curved section and then fit a bezier instead of a circular
arc into the space?  Or is there some better way to define the space where
the curve should go at a given corner?  Like perhaps a setback distance
along the edge from the corner? 


nophead wrote
> I don't thinks so because all the rounding discussed so far uses circular
> arcs that meet straight lines tangentially. That is continuous in gradient
> but has a discontinuity of curvature. Possibly Bezier splines would do the
> job?
>
> On Tue, 12 Mar 2019 at 14:27, William Adams &lt;

> will.adams@

> &gt; wrote:
>
>> Would it be possible to use this tool to get rounding as is done in some
>> industrial designs?
>>
>>
>> https://hackernoon.com/apples-icons-have-that-shape-for-a-very-good-reason-720d4e7c8a14
>>
>> If not, could someone suggest a suitable technique to achieve this?
>>
>> William
>>





--
Sent from: http://forum.openscad.org/

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

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

Re: Rounded Polygon

rew
On Tue, Mar 12, 2019 at 11:28:24PM +0000, nop head wrote:

> I don't have an artistic bone in my body, so to me circles meeting tangents
> are fine. I don't have any Apple products and probably never will as they
> are just a waste of money. They look nice but are very unreliable and
> locked in.
>
> If I could see a need for avoiding discontinuities in curvature I am sure I
> could work something out with Bezier splines but life is too short. I use
> Bezier splines to approximate minimum energy curves to model bent strips.
> 2D Bezier curves are easy in OpenSCAD, and 3D Bezier curves are certainly
> possible with polyhedron. I don't think new primitives are needed.

At first I didn't think so, then I did, now I do....

It would be VERY nice if a recursive bezier module could be built. But
that requires returning "patches" that will build up to the sides of a
polyhedron. Writing out the recursion by hand and implementing the
stack on an array is very tedious. It's like on the first day of work
you new boss points at an actual Turing machine, and says: "that's
just as turing-complete as that windows machine over there, you can
use the turing machine."

It's theoretically possible, but WAY more convenient if there is some
language support.

        Roger.


--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might 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: Rounded Polygon

nophead
Isn't it just some for loops and list comprehension? I don't think it is much harder than sweep if you want a regular array of surface points.

On Wed, 13 Mar 2019, 11:00 Rogier Wolff <[hidden email] wrote:
On Tue, Mar 12, 2019 at 11:28:24PM +0000, nop head wrote:
> I don't have an artistic bone in my body, so to me circles meeting tangents
> are fine. I don't have any Apple products and probably never will as they
> are just a waste of money. They look nice but are very unreliable and
> locked in.
>
> If I could see a need for avoiding discontinuities in curvature I am sure I
> could work something out with Bezier splines but life is too short. I use
> Bezier splines to approximate minimum energy curves to model bent strips.
> 2D Bezier curves are easy in OpenSCAD, and 3D Bezier curves are certainly
> possible with polyhedron. I don't think new primitives are needed.

At first I didn't think so, then I did, now I do....

It would be VERY nice if a recursive bezier module could be built. But
that requires returning "patches" that will build up to the sides of a
polyhedron. Writing out the recursion by hand and implementing the
stack on an array is very tedious. It's like on the first day of work
you new boss points at an actual Turing machine, and says: "that's
just as turing-complete as that windows machine over there, you can
use the turing machine."

It's theoretically possible, but WAY more convenient if there is some
language support.

        Roger.


--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.

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

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

Re: Rounded Polygon

rew
On Wed, Mar 13, 2019 at 11:41:30AM +0000, nop head wrote:
> Isn't it just some for loops and list comprehension? I don't think it is
> much harder than sweep if you want a regular array of surface points.

Hmm.. Ok. Maybe it's doable... I'll give it a go later on. Maybe this
weekend. Feel free to remind me. I might forget.

(I already wrote the first test-control-points and the call of the
module, and the level zero approximation.... )

        Roger.


>
> On Wed, 13 Mar 2019, 11:00 Rogier Wolff <[hidden email] wrote:
>
> > On Tue, Mar 12, 2019 at 11:28:24PM +0000, nop head wrote:
> > > I don't have an artistic bone in my body, so to me circles meeting
> > tangents
> > > are fine. I don't have any Apple products and probably never will as they
> > > are just a waste of money. They look nice but are very unreliable and
> > > locked in.
> > >
> > > If I could see a need for avoiding discontinuities in curvature I am
> > sure I
> > > could work something out with Bezier splines but life is too short. I use
> > > Bezier splines to approximate minimum energy curves to model bent strips.
> > > 2D Bezier curves are easy in OpenSCAD, and 3D Bezier curves are certainly
> > > possible with polyhedron. I don't think new primitives are needed.
> >
> > At first I didn't think so, then I did, now I do....
> >
> > It would be VERY nice if a recursive bezier module could be built. But
> > that requires returning "patches" that will build up to the sides of a
> > polyhedron. Writing out the recursion by hand and implementing the
> > stack on an array is very tedious. It's like on the first day of work
> > you new boss points at an actual Turing machine, and says: "that's
> > just as turing-complete as that windows machine over there, you can
> > use the turing machine."
> >
> > It's theoretically possible, but WAY more convenient if there is some
> > language support.
> >
> >         Roger.
> >
> >
> > --
> > ** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110
> > **
> > **    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
> > The plan was simple, like my brother-in-law Phil. But unlike
> > Phil, this plan just might work.
> >
> > _______________________________________________
> > OpenSCAD mailing list
> > [hidden email]
> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> >

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


--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might 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: Rounded Polygon

adrianv
In reply to this post by rew
rew wrote

>> If I could see a need for avoiding discontinuities in curvature I am sure
>> I
>> could work something out with Bezier splines but life is too short. I use
>> Bezier splines to approximate minimum energy curves to model bent strips.
>> 2D Bezier curves are easy in OpenSCAD, and 3D Bezier curves are certainly
>> possible with polyhedron. I don't think new primitives are needed.
>
> At first I didn't think so, then I did, now I do....
>
> It would be VERY nice if a recursive bezier module could be built. But
> that requires returning "patches" that will build up to the sides of a
> polyhedron. Writing out the recursion by hand and implementing the
> stack on an array is very tedious. It's like on the first day of work
> you new boss points at an actual Turing machine, and says: "that's
> just as turing-complete as that windows machine over there, you can
> use the turing machine."
>
> It's theoretically possible, but WAY more convenient if there is some
> language support.

If it's "theoretically possible" then after someone does it you can use the
code and you don't really care how hard it was to write.  (How hard is it to
write into OpenSCAD as a primitive?)  OpenSCAD can do recursion, so why
would you want to maintain your own stack?  What is it that you think can't
be done?  Or maybe more to the point, what exactly would your desired module
do?  Maybe we can write it.  




--
Sent from: http://forum.openscad.org/

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

Re: Rounded Polygon

adrianv
In reply to this post by William Adams-2
William Adams-2 wrote
> Would it be possible to use this tool to get rounding as is done in some
> industrial designs?
>
> https://hackernoon.com/apples-icons-have-that-shape-for-a-very-good-reason-720d4e7c8a14
>
> If not, could someone suggest a suitable technique to achieve this?
>
> William

I studied Bezier curves last night (about which I knew nothing) and figured
out how cubic bezier curves can be used to achieve continuous curvature
rounding.  One parameter needs to be specified at each corner.  I'm
wondering what the best way to specify this parameter is.  It could be
specified as the distance to the intersection point of the bezier with the
edge.  Or it could be specified as the distance from the corner tip to the
maximum projection of the curve (e.g. how much is cut off).   Or perhaps
some other way relating to rounding with circular arcs?  

I also wonder if it might be desirable to round in a continuous curvature
fashion but more aggressively using a higher order Bezier.  These roundovers
with the cubic bezier are rather gentle.  Anybody know how to calculate the
curvature at the endpoints of an order 4 (or general order) bezier?  

Here are two examples.  The green line shows the bezier curve fit to the
corner shown in red.  Note how far back it extends before finally
terminating on the linear portion?   It means you need a *long* flat edge to
have room for a fairly modest roundover.  

<http://forum.openscad.org/file/t2477/bez.png>







--
Sent from: http://forum.openscad.org/

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

Re: Rounded Polygon

tp3
I have not looked at the detailed properties, but Catmull–Rom
spline have the nice benefit that they don't need additional
control points. So for "just rounding stuff" that seems to be
quite interesting.

ciao,
   Torsten.

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

Re: Rounded Polygon

adrianv
tp3 wrote
> I have not looked at the detailed properties, but Catmull–Rom
> spline have the nice benefit that they don't need additional
> control points. So for "just rounding stuff" that seems to be
> quite interesting.

I also didn't look in detail, but it's not apparent that these splines have
any nice derivative properties, like even first derivative control.  Having
no control parameters isn't necessary a good thing, as indicated by the
cubic bezier, which I think doesn't produce a curved enough roundover.  

I did a little more analysis and I think a good way to do continuous
curvature roundovers is to use order 4 beziers.  This ends up providing two
parameters.  I'm still not sure of the optimal way to expose these
parameters to the user.  Basically with these beziers you set p0 to one end
point, p4 to the other endpoint, p2 to the point of the corner, and the
remaining p1 and p3 are symmetrically placed on the intervals [p0,p2] and
[p2,p4].   The parameters that need to be chosen are the distance, d,  of p0
and p4 from the corner and the distance a, of p1 and p2 from the corner.  
Choosing a=d gives the maximum roundover, which I think is probably what is
generally desired.  If we consider doing a chamfer by simply connecting p0
and p4 then the roundover that results from a=d will put the tip of the
roundover at 5/8 of the way from the corner point to the chamfer.  Setting
a=0 puts the roundover 1/8 of the way from the corner to the chamfer.  

So I could have the user specify d (the distance along the line segment to
the start of the roundover curve) or I could have the user specify the
distance to the line between p0 and p4.  And for a I can have the user
specify a value on [0,1] to control the range from 0 to d, or I could have
the user specify something from [1/8 to 5/8]*d---specifying the actual
location of the roundover tip.  

Maybe I'll post some pictures later since I think the above may not be
clear.  




--
Sent from: http://forum.openscad.org/

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

Re: Rounded Polygon

Ronaldo
You are right, a degree 3 Bezier arc would at most be zero curvature at one extreme and tangent continuous at the other. The minimal degree for a zero curvature at each extremes is really 5. However, I would use a degree 6 Bezier arc because you get too restricted setting p2 to the vertex of the polygon. I did a experiment with degree 6 with the following strategy.

pc.PNG
The collinearity of P0, P1 and P2 implies zero curvature of the arc at P0 besides the tangent to segment [C.P0]  (similarly for P5) .
The position of P2 (respect. P3) follows a ratio r0 in the interval (0,1) in the segment [C,P0] (respect. [C,P5]).
The position of P1 (respect. P4) follows a ratio r1 in the interval (0,1) in the segment [P2,P0] (respect. [P3,P5]).
This two ratios give some flexibility to the shape of the curve.

Here is a code that follows that strategy to round a polygon. I haven't tried with non-convex polygons but it should work fine.

// polygon to be rounded
q = [ [0,0], [30,0], [15,20] ];

color("blue")   roundedPoly(q, 20, 1/5);
color("yellow") roundedPoly(q, 20, 1/3);
color("red")    roundedPoly(q, 20, 1/2);

translate([30,0,0]) {
  color("blue")   roundedPoly(q, 20, 1/5, 1/3);
  color("yellow") roundedPoly(q, 20, 1/3, 1/3);
  color("red")    roundedPoly(q, 20, 1/2, 1/3);
}  
  
module roundedPoly(p, n=20, r=1/4, r0=2/3, r1=1/2) {
  assert(len(p)>2, "polygonal has less than 3 points");
  assert(r>0 && r<1, "improper value of argument r");
  l = len(p);
  q = [for(i=[0:l-1]) 
         let( p0 = (1-r)*p[i] + r*p[(i+l-1)%l] ,
              p1 = p[i],
              p2 = (1-r)*p[i] + r*p[(i+1)%l] )
         each BZeroCurvature(p0,p1,p2,n,r0,r1) ];
  line(q, closed=true);
}  
  
// a Bezier arc of degree 5 from p0 to p2, tangent to
// [p0,p1] at p0, tangent to [p1,p2) at p2 and
// with zero curvature at p0 and p2
// n = # of points in the arc
// r0, r1 - form factors in the open interval (0,1) 
function BZeroCurvature(p0,p1,p2,n=20,r0=2/3,r1=1/2) =
  assert(r0>0 && r0<1 && r1>0 && r1<1, "improper value of r0 or r1")
  let( p = [ p0, 
             p0 + r0*(p1-p0)*r1, 
             p0 + r0*(p1-p0), 
             p2 + r0*(p1-p2), 
             p2 + r0*(p1-p2)*r1, 
             p2 ] )
  BezierCurve(p,n);

// p are the curve control points, the curve degree is len(p)-1
function BezierCurve(p, n=10) = 
  [for(i=[0:n-1]) BezierPoint(p, i/(n-1)) ];

function BezierPoint(p, u) =
    (len(p) == 2)? 
        u*p[1] + (1-u)*p[0] :
        u*BezierPoint([for(i=[1:len(p)-1]) p[i] ], u) 
          + (1-u)*BezierPoint([for(i=[0:len(p)-2]) p[i] ], u);

module line(p,closed=false,w=0.1)
  for(i=[0:len(p)-(closed? 1:2)]){ 
    hull(){ translate(to3d(p[i]))   sphere(w); 
            translate(to3d(p[(i+1)%len(p)])) sphere(w); }
}
function to3d(p) = len(p)==3 ? p : [p.x,p.y,0];

roundedPoly.PNG

I would not expect any good interface for Bezier stuffs could be designed to solve a large set of problems to justify its implementation in the core of OpenSCAD. Each modeling problem requires specific codes to be written and that is easily done in users space if you have the needed mathematical background. Anyway, to work with Bezier curves and surfaces, even using other people good libraries, a minimal mathematical background is necessary.


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

Re: Rounded Polygon

adrianv
In reply to this post by adrianv
So there's an image showing a corner to be smoothed. The control points p0, ..., p4 are located as shown, with p0 and p4 at the base of the bezier curve, p2 at the tip of the corner, and p1 and p3 on the line segment in between somewhere. It takes two parameters to specify the 4th order curve: d, the distance from the corner (p2) to the base control points (p0 and p4) and a, the distance to the secondary control points p1 and p3. The most rounding occurs when a=d, at which point c = (5/8)*h. The least rounding occurs when a=0, at which point c=(1/8)*h. So the user could specify d or h. Which is more natural? For the amount of curvature the user could specify a (which seems not very meaningful) or a/d which is a sort of smoothing factor that ranges on [0,1] c, how much of the corner to "cut off" (but must be in the range [1/8,5/8]*h the amount to cut off as a fraction of h, so a value in the range [1/8, 5/8]

Sent from the OpenSCAD mailing list archive at Nabble.com.

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

Re: Rounded Polygon

Ronaldo
In reply to this post by Ronaldo
I missed to mention that the argument r of roundedPoly() controls how much of the corners are rounded. It has an effect similar to radius when circular arcs are used.

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

Re: Rounded Polygon

adrianv
In reply to this post by Ronaldo
Ronaldo wrote
> You are right, a degree 3 Bezier arc would at most be zero curvature at
> one
> extreme and tangent continuous at the other. The minimal degree for a zero
> curvature at each extremes is really 5. However, I would use a degree 6
> Bezier arc because you get too restricted setting p2 to the vertex of the
> polygon. I did a experiment with degree 6 with the following strategy.

I'm a little puzzled.  Maybe you are using the word degree differently than
I think?  I was thinking a degree 3 Bezier is a cubic polynomial and has 4
control points.  It can be set to zero curvature at both ends but has only
one degree of freedom, which just controls the size of the curve.  That
isn't enough.  It appears to me that degree 4, with 5 control points, is
sufficient.  Yes, you do need to put p2 on the vertex.  This doesn't seem to
cause any undesirable restriction, and it is definitely possible to satisfy
the zero curvature condition.   One parameter remains that controls the
degree of curvature, as I noted in my previous message.  Having fewer
parameters is often better than more, so I'm not sure about what the value
of more degrees of freedom is of going to the case with 6 control points
(which is a 5th degree polynomial).  I did experiment a bit with your code
and you can get some rather sharp cornered results.  It seemed like r1
usually had little effect.  





--
Sent from: http://forum.openscad.org/

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

Re: Rounded Polygon

rew
In reply to this post by rew
On Wed, Mar 13, 2019 at 12:52:07PM +0100, Rogier Wolff wrote:
> On Wed, Mar 13, 2019 at 11:41:30AM +0000, nop head wrote:
> > Isn't it just some for loops and list comprehension? I don't think it is
> > much harder than sweep if you want a regular array of surface points.
>
> Hmm.. Ok. Maybe it's doable... I'll give it a go later on. Maybe this
> weekend. Feel free to remind me. I might forget.

> [... I already wrote .. ]
wrong!

I started over. I now have a bezier curve in 2D. This is at $fn = 15,
the parameter has not yet been added to the function.

        Roger.

--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.

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

bezier2d.png (4K) Download Attachment
12345 ... 10