discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Rounded Polygon

I
irevdev
Sat, Jul 22, 2017 12:35 PM

Hi all,

Just sharing a tool that I think is pretty useful for rounding the points on
a polygon. The idea is that along with the list of coordinates that you
would normally pass to polygon(), a list of radii is also given and they are
used to round the corners at each of the coordinates.

http://forum.openscad.org/file/n21897/PolyRoundexample1.png

code here
https://github.com/Irev-Dev/Round-Anything/blob/master/polyround.scad

I normally design SCAD things mostly with primitives, but I always get
frustrated when it comes to adding fillets later (internal radii in
particular), I'm going to try and design things from now on by extruding
these rounded polygons (where practical).

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Hi all, Just sharing a tool that I think is pretty useful for rounding the points on a polygon. The idea is that along with the list of coordinates that you would normally pass to polygon(), a list of radii is also given and they are used to round the corners at each of the coordinates. <http://forum.openscad.org/file/n21897/PolyRoundexample1.png> code here <https://github.com/Irev-Dev/Round-Anything/blob/master/polyround.scad> I normally design SCAD things mostly with primitives, but I always get frustrated when it comes to adding fillets later (internal radii in particular), I'm going to try and design things from now on by extruding these rounded polygons (where practical). -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897.html Sent from the OpenSCAD mailing list archive at Nabble.com.
T
TLC123
Sat, Jul 22, 2017 2:20 PM

Oh Yes this will be used extensively , i assure you.

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21903.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Oh Yes this will be used extensively , i assure you. -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21903.html Sent from the OpenSCAD mailing list archive at Nabble.com.
I
irevdev
Sat, Jul 22, 2017 9:36 PM

Good to hear :)

I forgot to add, one current issue is that if three consecutive points are
col-linear it breaks :/
It's probably easy to fix, I've just hit a wall in motivation.

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21904.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Good to hear :) I forgot to add, one current issue is that if three consecutive points are col-linear it breaks :/ It's probably easy to fix, I've just hit a wall in motivation. -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21904.html Sent from the OpenSCAD mailing list archive at Nabble.com.
T
TLC123
Sun, Jul 23, 2017 8:21 AM

Yeah i get some runaway error too. Not sure if its the same issue though.
Co-linearity is easily fixed in function round3points.
if more tha 98% collinear just return input back as is.
swap the end of round3points to:

swapout:for:
I think my issue occur when radius for p2 dont fit between p1 -p3.
Maybe that should be left to be expected
or limited so the arc never can go outside the three points?
Also i probably will use [x,y,r], format points in my trials.
Easy enough to separate them before calling polyRound.
Any reason you selected against that?
Thanks again for a great module that will com to much use. Not least with
sweeps.
http://forum.openscad.org/file/n21908/100.jpg

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21908.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Yeah i get some runaway error too. Not sure if its the same issue though. Co-linearity is easily fixed in function round3points. if more tha 98% collinear just return input back as is. swap the end of round3points to: swapout:for: I think my issue occur when radius for p2 dont fit between p1 -p3. Maybe that should be left to be expected or limited so the arc never can go outside the three points? Also i probably will use [x,y,r], format points in my trials. Easy enough to separate them before calling polyRound. Any reason you selected against that? Thanks again for a great module that will com to much use. Not least with sweeps. <http://forum.openscad.org/file/n21908/100.jpg> -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21908.html Sent from the OpenSCAD mailing list archive at Nabble.com.
I
irevdev
Sun, Jul 23, 2017 12:00 PM

TLC123 wrote

Co-linearity is easily fixed in function round3points.
if more tha 98% collinear just return input back as is.
swap the end of round3points to:

swapout:

for:

Thanks for having a look at the co-linearity problem. I've only had a quick
look at your code now before bed so I mightn't understand it properly but I
would think that if you test for co-linearity and the result is true, then
you should return nothing and move onto the next set. My thought experiment
is that if there are 5 points where points 2 , 3 and 4 are co-linear,
processing points 1,2&3 together is fine likewise so is 3,4&5. If we just
skip processing points 2,3&4 it should be fine. Returning the original three
points might cause problems, I'll have a look at it though later.

TLC123 wrote

I think my issue occur when radius for p2 dont fit between p1 -p3.
Maybe that should be left to be expected
or limited so the arc never can go outside the three points?

Your suggestion to limit the arc to stay within the three points, I'm
thinking out loud now, at first I thought I wouldn't work, but now I think
it could potentially work if instead of just processing the list of points
three at a time like it is currently p[i],p[i+1],p[i+2] instead it grabs the
last point from the previous arc so  arcpoints[last point of last
arc],p[i+1],p[i+2]. it would have to do something different on the first and
last iteration of the for loop, but that's seem like a nice simple solution.

TLC123 wrote

Also i probably will use [x,y,r], format points in my trials.

Easy enough to separate them before calling polyRound.
Any reason you selected against that?
Thanks again for a great module that will com to much use. Not least with
sweeps.

In terms of the format [[x,y,r],[x,y,r],etc], I think you're right, I think
it's better. I posted this code as soon at it was mostly working so I
haven't actually used it for anything other than the examples, but trying to
implement it today on an actual project of mine I found it confusing as to
which radius lined up with which point on the polygon. So I think I'll make
this change, but with any of those three things, feel free to make a pull
request.

I'll have a closer look at your code soon, though probably not until
Tuesday, I'm busy tomorrow.

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21909.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

TLC123 wrote > Co-linearity is easily fixed in function round3points. > if more tha 98% collinear just return input back as is. > swap the end of round3points to: > > swapout: > for: Thanks for having a look at the co-linearity problem. I've only had a quick look at your code now before bed so I mightn't understand it properly but I would think that if you test for co-linearity and the result is true, then you should return nothing and move onto the next set. My thought experiment is that if there are 5 points where points 2 , 3 and 4 are co-linear, processing points 1,2&3 together is fine likewise so is 3,4&5. If we just skip processing points 2,3&4 it should be fine. Returning the original three points might cause problems, I'll have a look at it though later. TLC123 wrote > I think my issue occur when radius for p2 dont fit between p1 -p3. > Maybe that should be left to be expected > or limited so the arc never can go outside the three points? Your suggestion to limit the arc to stay within the three points, I'm thinking out loud now, at first I thought I wouldn't work, but now I think it could potentially work if instead of just processing the list of points three at a time like it is currently p[i],p[i+1],p[i+2] instead it grabs the last point from the previous arc so arcpoints[last point of last arc],p[i+1],p[i+2]. it would have to do something different on the first and last iteration of the for loop, but that's seem like a nice simple solution. TLC123 wrote > Also i probably will use [x,y,r], format points in my trials. > > Easy enough to separate them before calling polyRound. > Any reason you selected against that? > Thanks again for a great module that will com to much use. Not least with > sweeps. In terms of the format [[x,y,r],[x,y,r],etc], I think you're right, I think it's better. I posted this code as soon at it was mostly working so I haven't actually used it for anything other than the examples, but trying to implement it today on an actual project of mine I found it confusing as to which radius lined up with which point on the polygon. So I think I'll make this change, but with any of those three things, feel free to make a pull request. I'll have a closer look at your code soon, though probably not until Tuesday, I'm busy tomorrow. -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21909.html Sent from the OpenSCAD mailing list archive at Nabble.com.
D
droftarts
Sun, Jul 23, 2017 2:51 PM

TLC123 wrote

Also i probably will use [x,y,r], format points in my trials.
<br>
Easy enough to separate them before calling polyRound.
<br>
Any reason you selected against that?
<br>

Probably so he could draw the original polygon easily, independently of the
script, for testing.

The main reason I started the other script was to enable CSG export to
FreeCAD and then into Fusion 360, as this couldn't be done using hull (read
the thread  here
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-td16537.html
). This meant that circles and arcs keep their definition, rather than being
broken up into a mesh. Your script does seem to create a mesh, ie arcs are
broken up into straight segments, so it doesn't maintain the geometry of
circles when you import it into FreeCAD.

Unlike the other script, the points don't have to go around in a clockwise
order with yours, which is nice.

Ian

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21910.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

TLC123 wrote > Also i probably will use [x,y,r], format points in my trials. > <br> > Easy enough to separate them before calling polyRound. > <br> > Any reason you selected against that? > <br> Probably so he could draw the original polygon easily, independently of the script, for testing. The main reason I started the other script was to enable CSG export to FreeCAD and then into Fusion 360, as this couldn't be done using hull (read the thread here <http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-td16537.html> ). This meant that circles and arcs keep their definition, rather than being broken up into a mesh. Your script does seem to create a mesh, ie arcs are broken up into straight segments, so it doesn't maintain the geometry of circles when you import it into FreeCAD. Unlike the other script, the points don't have to go around in a clockwise order with yours, which is nice. Ian -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21910.html Sent from the OpenSCAD mailing list archive at Nabble.com.
D
droftarts
Sun, Jul 23, 2017 3:21 PM

Thinking about it, an approach that is somewhere between the two scripts
might be the best of both. Take the initial polygon, calculate the tangent
points between each three points and the radius, redraw the polygon without
the middle point but with the tangent points, then union or difference the
circle from it. This would give you the same shape as your version, but
constructed from a polygon with unioned or differenced circles, like my
version. This would mean on CSG export that it would maintain it's geometry,
rather than being converted to a mesh, so can be opened in other CAD
software as a solid body, rather than a mesh.

Ian

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21911.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Thinking about it, an approach that is somewhere between the two scripts might be the best of both. Take the initial polygon, calculate the tangent points between each three points and the radius, redraw the polygon without the middle point but with the tangent points, then union or difference the circle from it. This would give you the same shape as your version, but constructed from a polygon with unioned or differenced circles, like my version. This would mean on CSG export that it would maintain it's geometry, rather than being converted to a mesh, so can be opened in other CAD software as a solid body, rather than a mesh. Ian -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21911.html Sent from the OpenSCAD mailing list archive at Nabble.com.
K
KeithSloan52
Sun, Jul 23, 2017 4:35 PM

There seem's to be some miss understandings about FreeCAD's import of SCAD
and CSG files.

  1. FreeCAD does try and support hull and minkowski requests. For it to work
    FreeCAD must be able to find the OpenSCAD executable. The path to the
    OpenSCAD executable is an option of the OpenSCAD work bench. ( It can be
    very slow.)

  2. For hull & minkowski to work with 2D objects the option to allow FreeCAD
    to download and update DXF libraries must be enabled see general
    import/export preference, The downloadable library is in general no longer
    used by FreeCAD but IS used by importCSG for hull & Minkowski requests
    involving 2D objects. There was a bug with LWPOLYINE in the DXF library that
    has not long been fixed.

  3. polyhedron should also be supported, but again there was a bug until
    recently.

So if you have problems then please try the latest 0.17 version and if
still, problems please report in the FreeCAD forum.

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21912.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

There seem's to be some miss understandings about FreeCAD's import of SCAD and CSG files. 1) FreeCAD does try and support hull and minkowski requests. For it to work FreeCAD must be able to find the OpenSCAD executable. The path to the OpenSCAD executable is an option of the OpenSCAD work bench. ( It can be very slow.) 2) For hull & minkowski to work with 2D objects the option to allow FreeCAD to download and update DXF libraries must be enabled see general import/export preference, The downloadable library is in general no longer used by FreeCAD but IS used by importCSG for hull & Minkowski requests involving 2D objects. There was a bug with LWPOLYINE in the DXF library that has not long been fixed. 3) polyhedron should also be supported, but again there was a bug until recently. So if you have problems then please try the latest 0.17 version and if still, problems please report in the FreeCAD forum. -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21912.html Sent from the OpenSCAD mailing list archive at Nabble.com.
I
irevdev
Sun, Jul 23, 2017 7:26 PM

droftarts wrote

Thinking about it, an approach that is somewhere between the two scripts
might be the best of both. Take the initial polygon, calculate the tangent
points between each three points and the radius, redraw the polygon
without the middle point but with the tangent points, then union or
difference the circle from it. This would give you the same shape as your
version, but constructed from a polygon with unioned or differenced
circles, like my version. This would mean on CSG export that it would
maintain it's geometry, rather than being converted to a mesh, so can be
opened in other CAD software as a solid body, rather than a mesh.

Ian

Hi Ian,

short answer is if you use fn of 1 with my code it will draw the polygon
along all the tangent points only.

This was my initial approach, but I dumped it when I realised if you wanted
to have a relatively large radius compare to the overall size of the shape
than unioning it with a circle would mean the circle would take over. ie the
radius of 10 in the example, a circle that big would be bigger than most of
the shape. I thought it could be fixed by cutting the circle down before it
got unioned but at that point it seemed drawing points of the circle would
be easier.

If you wanted go back to this like I said you can use fn of 1 or you could
modify the round3points() function so that instead of passing the tangent
points and circle center to CentreN2PointsArc() it just returns these values
instead, that way you would also have the coordinates of the circle center
for the circle unioning.

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21913.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

droftarts wrote > Thinking about it, an approach that is somewhere between the two scripts > might be the best of both. Take the initial polygon, calculate the tangent > points between each three points and the radius, redraw the polygon > without the middle point but with the tangent points, then union or > difference the circle from it. This would give you the same shape as your > version, but constructed from a polygon with unioned or differenced > circles, like my version. This would mean on CSG export that it would > maintain it's geometry, rather than being converted to a mesh, so can be > opened in other CAD software as a solid body, rather than a mesh. > > Ian Hi Ian, short answer is if you use fn of 1 with my code it will draw the polygon along all the tangent points only. This was my initial approach, but I dumped it when I realised if you wanted to have a relatively large radius compare to the overall size of the shape than unioning it with a circle would mean the circle would take over. ie the radius of 10 in the example, a circle that big would be bigger than most of the shape. I thought it could be fixed by cutting the circle down before it got unioned but at that point it seemed drawing points of the circle would be easier. If you wanted go back to this like I said you can use fn of 1 or you could modify the round3points() function so that instead of passing the tangent points and circle center to CentreN2PointsArc() it just returns these values instead, that way you would also have the coordinates of the circle center for the circle unioning. -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21913.html Sent from the OpenSCAD mailing list archive at Nabble.com.
D
droftarts
Sun, Jul 23, 2017 9:37 PM

Ah yes, I see the problem, and now I try it, the other script has this
problem too. Though it probably shows how often it's a problem, as neither I
nor anyone else has noticed it before! Thanks for the extra info, I'll take
a look.

Keith: I'd like to see some examples of what FreeCad can import correctly
from OpenSCAD, but I think that belongs in another thread, rather than
hijack this one!

Ian

--
View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21914.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Ah yes, I see the problem, and now I try it, the other script has this problem too. Though it probably shows how often it's a problem, as neither I nor anyone else has noticed it before! Thanks for the extra info, I'll take a look. Keith: I'd like to see some examples of what FreeCad can import correctly from OpenSCAD, but I think that belongs in another thread, rather than hijack this one! Ian -- View this message in context: http://forum.openscad.org/Rounded-Polygon-tp21897p21914.html Sent from the OpenSCAD mailing list archive at Nabble.com.