Hi, long time OpenSCAD user, first time poster.
I want to export a model I've designed in OpenSCAD in a form that I can
import into a more 'feature rich' CAD package, so I can do some nice renders
of it. I've looked at Blender OpenSCAD import scripts, but these seem to be
rather limited, and the only other apparent way to export the model, and
retain geometry (rather than export as STL), seems to be to export as CSG,
and import into FreeCAD - the only tool I've found that can cope with
OpenSCAD CSG files.
FreeCAD's CSG import doesn't support OpenSCAD functions such as 'hull' and
'minkowski', which I've used to give my design nice rounded edges.
Fortunately, most of my parts are 2D extrusions, as I plan to lasercut most
of it, and it's relatively easy to reduce minkowski and hull functions to
squares, circles and polygons.
However, FreeCAD (on Mac OS X at least) doesn't seem to like unions of lots
of circles, squares and polygons, and drops geometry, creating holes from
overlapping parts when I import them. Also, some shapes are difficult to
translate into circles and squares alone. So I've come up a script that, to
some extent, replicates 2D hull and minkowski with just circles and a
polygon. With an input of the points of the shape, it draws a circle of a
given radius at each point, then calculates the tangents that connect all
the circles, and creates a polygon. With a linear extrusion, FreeCAD seems
happy with this. Here's my code so far:
radius = 5;
shape = [ 10,10 , 0,40 , 40,80 , 100,80 , 50,0];
x1 = shape[0];
y1 = shape[1];
x2 = shape[2];
y2 = shape[3];
x3 = shape[4];
y3 = shape[5];
x4 = shape[6];
y4 = shape[7];
x5 = shape[8];
y5 = shape[9];
linear_extrude (height=5)
union () {
translate ([x1,y1]) circle (r=radius);
translate ([x2,y2]) circle (r=radius);
translate ([x3,y3]) circle (r=radius);
translate ([x4,y4]) circle (r=radius);
translate ([x5,y5]) circle (r=radius);
polygon ([
tangent_1 (x1,y1,x2,y2,radius),
tangent_2 (x1,y1,x2,y2,radius),
tangent_1 (x2,y2,x3,y3,radius),
tangent_2 (x2,y2,x3,y3,radius),
tangent_1 (x3,y3,x4,y4,radius),
tangent_2 (x3,y3,x4,y4,radius),
tangent_1 (x4,y4,x5,y5,radius),
tangent_2 (x4,y4,x5,y5,radius),
tangent_1 (x5,y5,x1,y1,radius),
tangent_2 (x5,y5,x1,y1,radius),
]);
}
function tangent_1 (x_1, y_1, x_2, y_2, rad) =
let (
x_delta = x_2-x_1,
y_delta = y_2-y_1,
theta = atan2(y_delta,x_delta)+360,
xa = x_1+(cos(90+theta)*rad),
ya = y_1+(sin(90+theta)*rad),
xb = xa+x_delta,
yb = ya+y_delta
)
[xa,ya];
function tangent_2 (x_1,y_1,x_2,y_2,rad) =
let (
x_delta = x_2-x_1,
y_delta = y_2-y_1,
theta = atan2(y_delta,x_delta),
xa = x_1+(cos(90+theta)*rad),
ya = y_1+(sin(90+theta)*rad),
xb = xa+x_delta,
yb = ya+y_delta
)
[xb,yb];
This seems to produce a valid CSG shape, that I can import into FreeCAD,
displays correctly, and can be exported as a STEP file to bring into other
CAD programs with better rendering engines (Blender/Fusion360 are the ones
I've briefly tested).
I'm nearly at my limit of maths/programming, so I'm having difficulty with a
few things:
shape = [ 50,50 , 0,40 , 40,80 , 100,80 , 50,0];
You can see it attempts to draw the indentation, but it gets the tangent
wrong, because it needs to use inner tangent lines, rather than outer
tangent lines. I think it would be possible to create a script that deals
with these (the maths is here:
http://www.ambrsoft.com/TrigoCalc/Circles2/Circles2Tangent_.htm ), and
points outside the hull could be identified by using '-r', perhaps, then the
'-r' circles differenced from the polygon shape, rather than unioned. I
could probably use conditional operators (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Conditional_Operator
) or some kind of recursive function (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Recursive_functions
). But then I'm really at the limits of my maths/programming!
Unless you know of any other way of getting a model out of OpenSCAD, while
maintaining the geometry, any pointers/help with this script would be
greatly appreciated!
Ian S.
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Nice job so far Ian. I am hoping to do similar for my printer parts, will read with interest...
Tapped on my mobile phone.
On 18 Mar 2016, at 10:13, droftarts ginjaian@hotmail.com wrote:
Hi, long time OpenSCAD user, first time poster.
I want to export a model I've designed in OpenSCAD in a form that I can
import into a more 'feature rich' CAD package, so I can do some nice renders
of it. I've looked at Blender OpenSCAD import scripts, but these seem to be
rather limited, and the only other apparent way to export the model, and
retain geometry (rather than export as STL), seems to be to export as CSG,
and import into FreeCAD - the only tool I've found that can cope with
OpenSCAD CSG files.
FreeCAD's CSG import doesn't support OpenSCAD functions such as 'hull' and
'minkowski', which I've used to give my design nice rounded edges.
Fortunately, most of my parts are 2D extrusions, as I plan to lasercut most
of it, and it's relatively easy to reduce minkowski and hull functions to
squares, circles and polygons.
However, FreeCAD (on Mac OS X at least) doesn't seem to like unions of lots
of circles, squares and polygons, and drops geometry, creating holes from
overlapping parts when I import them. Also, some shapes are difficult to
translate into circles and squares alone. So I've come up a script that, to
some extent, replicates 2D hull and minkowski with just circles and a
polygon. With an input of the points of the shape, it draws a circle of a
given radius at each point, then calculates the tangents that connect all
the circles, and creates a polygon. With a linear extrusion, FreeCAD seems
happy with this. Here's my code so far:
radius = 5;
shape = [ 10,10 , 0,40 , 40,80 , 100,80 , 50,0];
x1 = shape[0];
y1 = shape[1];
x2 = shape[2];
y2 = shape[3];
x3 = shape[4];
y3 = shape[5];
x4 = shape[6];
y4 = shape[7];
x5 = shape[8];
y5 = shape[9];
linear_extrude (height=5)
union () {
translate ([x1,y1]) circle (r=radius);
translate ([x2,y2]) circle (r=radius);
translate ([x3,y3]) circle (r=radius);
translate ([x4,y4]) circle (r=radius);
translate ([x5,y5]) circle (r=radius);
polygon ([
tangent_1 (x1,y1,x2,y2,radius),
tangent_2 (x1,y1,x2,y2,radius),
tangent_1 (x2,y2,x3,y3,radius),
tangent_2 (x2,y2,x3,y3,radius),
tangent_1 (x3,y3,x4,y4,radius),
tangent_2 (x3,y3,x4,y4,radius),
tangent_1 (x4,y4,x5,y5,radius),
tangent_2 (x4,y4,x5,y5,radius),
tangent_1 (x5,y5,x1,y1,radius),
tangent_2 (x5,y5,x1,y1,radius),
]);
}
function tangent_1 (x_1, y_1, x_2, y_2, rad) =
let (
x_delta = x_2-x_1,
y_delta = y_2-y_1,
theta = atan2(y_delta,x_delta)+360,
xa = x_1+(cos(90+theta)*rad),
ya = y_1+(sin(90+theta)*rad),
xb = xa+x_delta,
yb = ya+y_delta
)
[xa,ya];
function tangent_2 (x_1,y_1,x_2,y_2,rad) =
let (
x_delta = x_2-x_1,
y_delta = y_2-y_1,
theta = atan2(y_delta,x_delta),
xa = x_1+(cos(90+theta)*rad),
ya = y_1+(sin(90+theta)*rad),
xb = xa+x_delta,
yb = ya+y_delta
)
[xb,yb];
This seems to produce a valid CSG shape, that I can import into FreeCAD,
displays correctly, and can be exported as a STEP file to bring into other
CAD programs with better rendering engines (Blender/Fusion360 are the ones
I've briefly tested).
I'm nearly at my limit of maths/programming, so I'm having difficulty with a
few things:
shape = [ 50,50 , 0,40 , 40,80 , 100,80 , 50,0];
You can see it attempts to draw the indentation, but it gets the tangent
wrong, because it needs to use inner tangent lines, rather than outer
tangent lines. I think it would be possible to create a script that deals
with these (the maths is here:
http://www.ambrsoft.com/TrigoCalc/Circles2/Circles2Tangent_.htm ), and
points outside the hull could be identified by using '-r', perhaps, then the
'-r' circles differenced from the polygon shape, rather than unioned. I
could probably use conditional operators (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Conditional_Operator
) or some kind of recursive function (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Recursive_functions
). But then I'm really at the limits of my maths/programming!
Unless you know of any other way of getting a model out of OpenSCAD, while
maintaining the geometry, any pointers/help with this script would be
greatly appreciated!
Ian S.
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Just a quick side note - especially for 2D extrusions, the double
offset() command can do an awesome job of rounding corners.
example: offset (r=+5) offset (r=-5) square(20);
of course, offset isn't supported in FreeCAD either.
On 3/18/2016 6:13 AM, droftarts wrote:
Hi, long time OpenSCAD user, first time poster.
I want to export a model I've designed in OpenSCAD in a form that I can
import into a more 'feature rich' CAD package, so I can do some nice renders
of it. I've looked at Blender OpenSCAD import scripts, but these seem to be
rather limited, and the only other apparent way to export the model, and
retain geometry (rather than export as STL), seems to be to export as CSG,
and import into FreeCAD - the only tool I've found that can cope with
OpenSCAD CSG files.
FreeCAD's CSG import doesn't support OpenSCAD functions such as 'hull' and
'minkowski', which I've used to give my design nice rounded edges.
Fortunately, most of my parts are 2D extrusions, as I plan to lasercut most
of it, and it's relatively easy to reduce minkowski and hull functions to
squares, circles and polygons.
However, FreeCAD (on Mac OS X at least) doesn't seem to like unions of lots
of circles, squares and polygons, and drops geometry, creating holes from
overlapping parts when I import them. Also, some shapes are difficult to
translate into circles and squares alone. So I've come up a script that, to
some extent, replicates 2D hull and minkowski with just circles and a
polygon. With an input of the points of the shape, it draws a circle of a
given radius at each point, then calculates the tangents that connect all
the circles, and creates a polygon. With a linear extrusion, FreeCAD seems
happy with this. Here's my code so far:
radius = 5;
shape = [ 10,10 , 0,40 , 40,80 , 100,80 , 50,0];
x1 = shape[0];
y1 = shape[1];
x2 = shape[2];
y2 = shape[3];
x3 = shape[4];
y3 = shape[5];
x4 = shape[6];
y4 = shape[7];
x5 = shape[8];
y5 = shape[9];
linear_extrude (height=5)
union () {
translate ([x1,y1]) circle (r=radius);
translate ([x2,y2]) circle (r=radius);
translate ([x3,y3]) circle (r=radius);
translate ([x4,y4]) circle (r=radius);
translate ([x5,y5]) circle (r=radius);
polygon ([
tangent_1 (x1,y1,x2,y2,radius),
tangent_2 (x1,y1,x2,y2,radius),
tangent_1 (x2,y2,x3,y3,radius),
tangent_2 (x2,y2,x3,y3,radius),
tangent_1 (x3,y3,x4,y4,radius),
tangent_2 (x3,y3,x4,y4,radius),
tangent_1 (x4,y4,x5,y5,radius),
tangent_2 (x4,y4,x5,y5,radius),
tangent_1 (x5,y5,x1,y1,radius),
tangent_2 (x5,y5,x1,y1,radius),
]);
}
function tangent_1 (x_1, y_1, x_2, y_2, rad) =
let (
x_delta = x_2-x_1,
y_delta = y_2-y_1,
theta = atan2(y_delta,x_delta)+360,
xa = x_1+(cos(90+theta)*rad),
ya = y_1+(sin(90+theta)*rad),
xb = xa+x_delta,
yb = ya+y_delta
)
[xa,ya];
function tangent_2 (x_1,y_1,x_2,y_2,rad) =
let (
x_delta = x_2-x_1,
y_delta = y_2-y_1,
theta = atan2(y_delta,x_delta),
xa = x_1+(cos(90+theta)*rad),
ya = y_1+(sin(90+theta)*rad),
xb = xa+x_delta,
yb = ya+y_delta
)
[xb,yb];
This seems to produce a valid CSG shape, that I can import into FreeCAD,
displays correctly, and can be exported as a STEP file to bring into other
CAD programs with better rendering engines (Blender/Fusion360 are the ones
I've briefly tested).
I'm nearly at my limit of maths/programming, so I'm having difficulty with a
few things:
shape = [ 50,50 , 0,40 , 40,80 , 100,80 , 50,0];
You can see it attempts to draw the indentation, but it gets the tangent
wrong, because it needs to use inner tangent lines, rather than outer
tangent lines. I think it would be possible to create a script that deals
with these (the maths is here:
http://www.ambrsoft.com/TrigoCalc/Circles2/Circles2Tangent_.htm ), and
points outside the hull could be identified by using '-r', perhaps, then the
'-r' circles differenced from the polygon shape, rather than unioned. I
could probably use conditional operators (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Conditional_Operator
) or some kind of recursive function (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Recursive_functions
). But then I'm really at the limits of my maths/programming!
Unless you know of any other way of getting a model out of OpenSCAD, while
maintaining the geometry, any pointers/help with this script would be
greatly appreciated!
Ian S.
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Thanks, Alex!
A note about the current script:
I did try another approach, which was to draw a polygon from each point,
draw a circle on each point, then draw a square of width r*2 between each
point, but this caused problems in FreeCAD. As each element (polygon,
circles, squares) is stored in the CSG, there were multiple overlapping
elements, and FreeCAD seemed to randomly put holes in. A 2D (ie no
linear_extrude) output of the above script still doesn't show correctly in
FreeCAD (there are some parts that are not coloured in), but the 3D version
does show correctly.
Ian
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16540.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Thanks shadowwynd, and I agree, offest is very useful. I'd tried that
approach for this problem, too, before finding it didn't import into FreeCAD
either!
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16542.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Hi Stuart,
Here is a general version that takes a list of points and makes a rounded
polygon.
radius = 5;
shape = [ [10,10] , [0,40] , [40,80] , [100,80] , [50,0] ];
linear_extrude (height=5) rounded_polygon(shape, radius);
function next(i) = (i + 1) % len(shape);
function tangents(i) = [tangent(shape[i], shape[next(i)],radius, 0),
tangent(shape[i], shape[next(i)],radius, 1)];
function flatten(list) = [for(p = list) for(x = p) x];
module rounded_polygon(points, radius)
union () {
for(point = shape)
translate(point)
circle (r = radius);
polygon(flatten([for(i = [0 : len(shape) - 1]) tangents(i)]));
}
function tangent(p1, p2, rad, side) =
let (
x_delta = p2.x - p1.x,
y_delta = p2.y - p1.y,
theta = atan2(y_delta, x_delta),
xa = p1.x +(cos(90 + theta) * rad),
ya = p1.y +(sin(90 + theta) * rad),
xb = xa + x_delta,
yb = ya + y_delta
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 10:51, droftarts ginjaian@hotmail.com wrote:
Thanks shadowwynd, and I agree, offest is very useful. I'd tried that
approach for this problem, too, before finding it didn't import into
FreeCAD
either!
Ian S
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16542.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Here's a simpler one:
radius = 5;
shape = [ [10,10] , [0,40] , [40,80] , [100,80] , [50,0] ];
linear_extrude (height=5) rounded_polygon(shape, radius);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)],radius, side);
module rounded_polygon(points, radius)
union () {
for(point = shape)
translate(point)
circle (r = radius);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
function tangent(p1, p2, rad, side) =
let (
x_delta = p2.x - p1.x,
y_delta = p2.y - p1.y,
theta = atan2(y_delta, x_delta),
xa = p1.x +(cos(90 + theta) * rad),
ya = p1.y +(sin(90 + theta) * rad),
xb = xa + x_delta,
yb = ya + y_delta
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 11:29, nop head nop.head@gmail.com wrote:
Hi Stuart,
Here is a general version that takes a list of points and makes a
rounded polygon.
radius = 5;
shape = [ [10,10] , [0,40] , [40,80] , [100,80] , [50,0] ];
linear_extrude (height=5) rounded_polygon(shape, radius);
function next(i) = (i + 1) % len(shape);
function tangents(i) = [tangent(shape[i], shape[next(i)],radius, 0),
tangent(shape[i], shape[next(i)],radius, 1)];
function flatten(list) = [for(p = list) for(x = p) x];
module rounded_polygon(points, radius)
union () {
for(point = shape)
translate(point)
circle (r = radius);
polygon(flatten([for(i = [0 : len(shape) - 1]) tangents(i)]));
}
function tangent(p1, p2, rad, side) =
let (
x_delta = p2.x - p1.x,
y_delta = p2.y - p1.y,
theta = atan2(y_delta, x_delta),
xa = p1.x +(cos(90 + theta) * rad),
ya = p1.y +(sin(90 + theta) * rad),
xb = xa + x_delta,
yb = ya + y_delta
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 10:51, droftarts ginjaian@hotmail.com wrote:
Thanks shadowwynd, and I agree, offest is very useful. I'd tried that
approach for this problem, too, before finding it didn't import into
FreeCAD
either!
Ian S
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16542.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Hi nophead
Wow! Thanks for the reply, that solves what I need at the moment. I knew
there had to be a way to iterate this, but just couldn't see it. That gives
me plenty to wrap my head around; I'd perhaps like to extend it to allow for
different radii.
I've been spending some time with your Mendel90 OpenSCAD files recently, and
have learnt a huge amount from that!
Ian S
P.S. Who's Stuart?!
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16545.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
P.S. Who's Stuart?!
No idea, sorry Ian.
I am attempting the different radii case at the moment. No quite right yet.
On 18 March 2016 at 12:26, droftarts ginjaian@hotmail.com wrote:
Hi nophead
Wow! Thanks for the reply, that solves what I need at the moment. I knew
there had to be a way to iterate this, but just couldn't see it. That gives
me plenty to wrap my head around; I'd perhaps like to extend it to allow
for
different radii.
I've been spending some time with your Mendel90 OpenSCAD files recently,
and
have learnt a huge amount from that!
Ian S
P.S. Who's Stuart?!
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16545.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Here is a multi radii version. It looks right but somebody might want to
check my maths as it is much simpler than the link you provided.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 80, 5], [100, 80, 10], [50, 0, 20]
];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
#circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 12:35, nop head nop.head@gmail.com wrote:
P.S. Who's Stuart?!
No idea, sorry Ian.
I am attempting the different radii case at the moment. No quite right yet.
On 18 March 2016 at 12:26, droftarts ginjaian@hotmail.com wrote:
Hi nophead
Wow! Thanks for the reply, that solves what I need at the moment. I knew
there had to be a way to iterate this, but just couldn't see it. That
gives
me plenty to wrap my head around; I'd perhaps like to extend it to allow
for
different radii.
I've been spending some time with your Mendel90 OpenSCAD files recently,
and
have learnt a huge amount from that!
Ian S
P.S. Who's Stuart?!
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16545.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
This version seems to handle the negative radii case:
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 13:01, nop head nop.head@gmail.com wrote:
Here is a multi radii version. It looks right but somebody might want to
check my maths as it is much simpler than the link you provided.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 80, 5], [100, 80, 10], [50, 0, 20]
];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
#circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 12:35, nop head nop.head@gmail.com wrote:
P.S. Who's Stuart?!
No idea, sorry Ian.
I am attempting the different radii case at the moment. No quite right
yet.
On 18 March 2016 at 12:26, droftarts ginjaian@hotmail.com wrote:
Hi nophead
Wow! Thanks for the reply, that solves what I need at the moment. I knew
there had to be a way to iterate this, but just couldn't see it. That
gives
me plenty to wrap my head around; I'd perhaps like to extend it to allow
for
different radii.
I've been spending some time with your Mendel90 OpenSCAD files recently,
and
have learnt a huge amount from that!
Ian S
P.S. Who's Stuart?!
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16545.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Slightly more efficient version that only calls tangent once per corner.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i)[side]]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 13:08, nop head nop.head@gmail.com wrote:
This version seems to handle the negative radii case:
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 13:01, nop head nop.head@gmail.com wrote:
Here is a multi radii version. It looks right but somebody might want to
check my maths as it is much simpler than the link you provided.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 80, 5], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
#circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 12:35, nop head nop.head@gmail.com wrote:
P.S. Who's Stuart?!
No idea, sorry Ian.
I am attempting the different radii case at the moment. No quite right
yet.
On 18 March 2016 at 12:26, droftarts ginjaian@hotmail.com wrote:
Hi nophead
Wow! Thanks for the reply, that solves what I need at the moment. I knew
there had to be a way to iterate this, but just couldn't see it. That
gives
me plenty to wrap my head around; I'd perhaps like to extend it to
allow for
different radii.
I've been spending some time with your Mendel90 OpenSCAD files
recently, and
have learnt a huge amount from that!
Ian S
P.S. Who's Stuart?!
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16545.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Actually that still called tangent twice, this version calls it once.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1])
let(ends = tangents(i))
for(end = [0, 1])
ends[end]]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 13:47, nop head nop.head@gmail.com wrote:
Slightly more efficient version that only calls tangent once per corner.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i)[side]]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 13:08, nop head nop.head@gmail.com wrote:
This version seems to handle the negative radii case:
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 13:01, nop head nop.head@gmail.com wrote:
Here is a multi radii version. It looks right but somebody might want to
check my maths as it is much simpler than the link you provided.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 80, 5], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
#circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 12:35, nop head nop.head@gmail.com wrote:
P.S. Who's Stuart?!
No idea, sorry Ian.
I am attempting the different radii case at the moment. No quite right
yet.
On 18 March 2016 at 12:26, droftarts ginjaian@hotmail.com wrote:
Hi nophead
Wow! Thanks for the reply, that solves what I need at the moment. I
knew
there had to be a way to iterate this, but just couldn't see it. That
gives
me plenty to wrap my head around; I'd perhaps like to extend it to
allow for
different radii.
I've been spending some time with your Mendel90 OpenSCAD files
recently, and
have learnt a huge amount from that!
Ian S
P.S. Who's Stuart?!
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16545.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Fixed all the references to shape instead of points and removed single use
functions.
$fn = 100;
shape1 = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape1);
module rounded_polygon(points, radius)
difference() {
len = len(points);
union () {
for(i = [0 : len - 1])
translate([points[i].x, points[i].y])
if(points[i][2] > 0)
circle(points[i][2]);
polygon([for(i = [0 : len - 1])
let(ends = tangent(points[i], points[(i + 1) %
len(points)]))
for(end = [0, 1])
ends[end]]);
}
for(i = [0 : len - 1])
translate([points[i].x, points[i].y])
if(points[i][2] < 0)
circle(-points[i][2]);
}
function tangent(p1, p2) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 13:53, nop head nop.head@gmail.com wrote:
Actually that still called tangent twice, this version calls it once.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1])
let(ends = tangents(i))
for(end = [0, 1])
ends[end]]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 13:47, nop head nop.head@gmail.com wrote:
Slightly more efficient version that only calls tangent once per corner.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i)[side]]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 13:08, nop head nop.head@gmail.com wrote:
This version seems to handle the negative radii case:
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
difference() {
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] > 0)
circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
if(shape[i][2] < 0)
circle(-shape[i][2]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 13:01, nop head nop.head@gmail.com wrote:
Here is a multi radii version. It looks right but somebody might want
to check my maths as it is much simpler than the link you provided.
$fn = 100;
shape = [ [10, 10, 8], [0, 40, 3], [40, 80, 5], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape);
function next(i) = (i + 1) % len(shape);
function tangents(i, side) = tangent(shape[i], shape[next(i)], side);
module rounded_polygon(points, radius)
union () {
for(i = [0 : len(shape) - 1])
translate([shape[i].x, shape[i].y])
#circle(shape[i][2]);
polygon([for(i = [0 : len(shape) - 1]) for(side = [0, 1])
tangents(i, side)]);
}
function tangent(p1, p2, side) =
let (
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)
side ? [xb, yb] : [xa, ya];
On 18 March 2016 at 12:35, nop head nop.head@gmail.com wrote:
P.S. Who's Stuart?!
No idea, sorry Ian.
I am attempting the different radii case at the moment. No quite right
yet.
On 18 March 2016 at 12:26, droftarts ginjaian@hotmail.com wrote:
Hi nophead
Wow! Thanks for the reply, that solves what I need at the moment. I
knew
there had to be a way to iterate this, but just couldn't see it. That
gives
me plenty to wrap my head around; I'd perhaps like to extend it to
allow for
different radii.
I've been spending some time with your Mendel90 OpenSCAD files
recently, and
have learnt a huge amount from that!
Ian S
P.S. Who's Stuart?!
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16545.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Thanks nophead, awesome stuff! I hope you find it useful too. But, dammit,
you're not giving me a chance to use my brain...!
I'll have a sit down over the weekend and see how you've coded this, so I
can understand it. One quick question: you use a '%' sign here:
...
let(ends = tangent(points[i], points[(i + 1) % len(points)]))
...
What does that do? I can see it's a 'scalar arithmetical operator' (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators )
for modulo (so finds the remainder after division of one number by another),
but I'm not clear why!
Ian S
P.S. re 'Stuart', you addressed me as Stuart in your first post!
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16553.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
It calculates the remainder after dividing by the length. That causes the
wrap round to zero to close the loop when i+1 equals the length.
On 18 March 2016 at 15:10, droftarts ginjaian@hotmail.com wrote:
Thanks nophead, awesome stuff! I hope you find it useful too. But, dammit,
you're not giving me a chance to use my brain...!
I'll have a sit down over the weekend and see how you've coded this, so I
can understand it. One quick question: you use a '%' sign here:
...
let(ends = tangent(points[i], points[(i + 1) % len(points)]))
...
What does that do? I can see it's a 'scalar arithmetical operator' (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators
)
for modulo (so finds the remainder after division of one number by
another),
but I'm not clear why!
Ian S
P.S. re 'Stuart', you addressed me as Stuart in your first post!
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16553.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
And just to confirm, this exports as a CSG file, and imports nicely into
FreeCAD as :
http://forum.openscad.org/file/n16555/FreeCAD.png
Which exports happily as a STEP file, which Fusion 360 can import and
render:
http://forum.openscad.org/file/n16555/Fusion_360.png
Thanks! I'll try it with some more complex geometry, and see if it still
copes.
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16555.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Cleaned up the generated csg by moving the circle translates inside the if
and replaced a call of len(points) with len.
$fn = 100;
shape1 = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape1);
module rounded_polygon(points)
difference() {
len = len(points);
union() {
for(i = [0 : len - 1])
if(points[i][2] > 0)
translate([points[i].x, points[i].y])
circle(points[i][2]);
polygon([for(i = [0 : len - 1])
let(ends = tangent(points[i], points[(i + 1) %
len]))
for(end = [0, 1])
ends[end]]);
}
for(i = [0 : len - 1])
if(points[i][2] < 0)
translate([points[i].x, points[i].y])
circle(-points[i][2]);
}
function tangent(p1, p2) =
let(
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 15:20, nop head nop.head@gmail.com wrote:
It calculates the remainder after dividing by the length. That causes the
wrap round to zero to close the loop when i+1 equals the length.
On 18 March 2016 at 15:10, droftarts ginjaian@hotmail.com wrote:
Thanks nophead, awesome stuff! I hope you find it useful too. But, dammit,
you're not giving me a chance to use my brain...!
I'll have a sit down over the weekend and see how you've coded this, so I
can understand it. One quick question: you use a '%' sign here:
...
let(ends = tangent(points[i], points[(i + 1) % len(points)]))
...
What does that do? I can see it's a 'scalar arithmetical operator' (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators
)
for modulo (so finds the remainder after division of one number by
another),
but I'm not clear why!
Ian S
P.S. re 'Stuart', you addressed me as Stuart in your first post!
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16553.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Looks nice in wood.
I suspect you could export the STL to Blender and give it a wood texture
and then render it. That would have the advantage of working with anything
OpenScad can produce. The Mendel90 printed
parts are rendered in Blender for the manual.
[image: Inline images 2]
They are not very pretty but that is just down to the blender template
used. I think it adds some random noise to make it look like a photo. I am
sure it could texture it with wood and give a photo realistic view. I am
not a blender user though, somebody else contributed it.
On 18 March 2016 at 15:30, droftarts ginjaian@hotmail.com wrote:
And just to confirm, this exports as a CSG file, and imports nicely into
FreeCAD as :
http://forum.openscad.org/file/n16555/FreeCAD.png
Which exports happily as a STEP file, which Fusion 360 can import and
render:
http://forum.openscad.org/file/n16555/Fusion_360.png
Thanks! I'll try it with some more complex geometry, and see if it still
copes.
Ian S
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16555.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
On 18. mars 2016 16:30, droftarts wrote:
And just to confirm, this exports as a CSG file, and imports nicely into
FreeCAD as :
http://forum.openscad.org/file/n16555/FreeCAD.png
Which exports happily as a STEP file, which Fusion 360 can import and
render:
http://forum.openscad.org/file/n16555/Fusion_360.png
Thanks! I'll try it with some more complex geometry, and see if it still
copes.
Does FreeCAD understand the polyhedron command? If so, OpenSCAD could
have an option to save the final body as a polyhedron to .csg, and you
could then use it in FreeCAD even if you had used Hull and Minkowski.
Carsten Arnholm
Converting the model to a polyhedron would be no different from exporting
as STL and then importing the STL in FreeCAD.
Droftarts says that STL is no good because it doesn't "retain the geometry".
On 18 March 2016 at 12:02, Carsten Arnholm arnholm@arnholm.org wrote:
On 18. mars 2016 16:30, droftarts wrote:
And just to confirm, this exports as a CSG file, and imports nicely into
FreeCAD as :
http://forum.openscad.org/file/n16555/FreeCAD.png
Which exports happily as a STEP file, which Fusion 360 can import and
render:
http://forum.openscad.org/file/n16555/Fusion_360.png
Thanks! I'll try it with some more complex geometry, and see if it still
copes.
Does FreeCAD understand the polyhedron command? If so, OpenSCAD could have
an option to save the final body as a polyhedron to .csg, and you could
then use it in FreeCAD even if you had used Hull and Minkowski.
Carsten Arnholm
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Very true but he also said "so I can do some nice renders of it". My point
is you don't need geometry to get nice renders in Blender. It works with
meshes.
On 18 March 2016 at 16:07, doug moen doug@moens.org wrote:
Converting the model to a polyhedron would be no different from exporting
as STL and then importing the STL in FreeCAD.
Droftarts says that STL is no good because it doesn't "retain the
geometry".
On 18 March 2016 at 12:02, Carsten Arnholm arnholm@arnholm.org wrote:
On 18. mars 2016 16:30, droftarts wrote:
And just to confirm, this exports as a CSG file, and imports nicely into
FreeCAD as :
http://forum.openscad.org/file/n16555/FreeCAD.png
Which exports happily as a STEP file, which Fusion 360 can import and
render:
http://forum.openscad.org/file/n16555/Fusion_360.png
Thanks! I'll try it with some more complex geometry, and see if it still
copes.
Does FreeCAD understand the polyhedron command? If so, OpenSCAD could
have an option to save the final body as a polyhedron to .csg, and you
could then use it in FreeCAD even if you had used Hull and Minkowski.
Carsten Arnholm
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
My vague understanding of STEP is that it can preserve information like:
"this is a circle with radius r", which is lost if you export to STL, but
preserved in the CSG file. Droftarts is using circle() in his model, so
maybe he wants to preserve the identity of circles for use by the Blender
and Fusion360 rendering engines?
On 18 March 2016 at 12:37, nop head nop.head@gmail.com wrote:
Very true but he also said "so I can do some nice renders of it". My point
is you don't need geometry to get nice renders in Blender. It works with
meshes.
On 18 March 2016 at 16:07, doug moen doug@moens.org wrote:
Converting the model to a polyhedron would be no different from exporting
as STL and then importing the STL in FreeCAD.
Droftarts says that STL is no good because it doesn't "retain the
geometry".
On 18 March 2016 at 12:02, Carsten Arnholm arnholm@arnholm.org wrote:
On 18. mars 2016 16:30, droftarts wrote:
And just to confirm, this exports as a CSG file, and imports nicely into
FreeCAD as :
http://forum.openscad.org/file/n16555/FreeCAD.png
Which exports happily as a STEP file, which Fusion 360 can import and
render:
http://forum.openscad.org/file/n16555/Fusion_360.png
Thanks! I'll try it with some more complex geometry, and see if it still
copes.
Does FreeCAD understand the polyhedron command? If so, OpenSCAD could
have an option to save the final body as a polyhedron to .csg, and you
could then use it in FreeCAD even if you had used Hull and Minkowski.
Carsten Arnholm
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
My guess is he needs it for Fusion360 but I don't think Blender understands
circles. You can get a nice render of a textured cylinder with not many
facets by interpolating the normals in the lighting calculation.
On 18 March 2016 at 16:47, doug moen doug@moens.org wrote:
My vague understanding of STEP is that it can preserve information like:
"this is a circle with radius r", which is lost if you export to STL, but
preserved in the CSG file. Droftarts is using circle() in his model, so
maybe he wants to preserve the identity of circles for use by the Blender
and Fusion360 rendering engines?
On 18 March 2016 at 12:37, nop head nop.head@gmail.com wrote:
Very true but he also said "so I can do some nice renders of it". My
point is you don't need geometry to get nice renders in Blender. It works
with meshes.
On 18 March 2016 at 16:07, doug moen doug@moens.org wrote:
Converting the model to a polyhedron would be no different from
exporting as STL and then importing the STL in FreeCAD.
Droftarts says that STL is no good because it doesn't "retain the
geometry".
On 18 March 2016 at 12:02, Carsten Arnholm arnholm@arnholm.org wrote:
On 18. mars 2016 16:30, droftarts wrote:
And just to confirm, this exports as a CSG file, and imports nicely
into
FreeCAD as :
http://forum.openscad.org/file/n16555/FreeCAD.png
Which exports happily as a STEP file, which Fusion 360 can import and
render:
http://forum.openscad.org/file/n16555/Fusion_360.png
Thanks! I'll try it with some more complex geometry, and see if it
still
copes.
Does FreeCAD understand the polyhedron command? If so, OpenSCAD could
have an option to save the final body as a polyhedron to .csg, and you
could then use it in FreeCAD even if you had used Hull and Minkowski.
Carsten Arnholm
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
On 18. mars 2016 17:07, doug moen wrote:
Converting the model to a polyhedron would be no different from exporting
as STL and then importing the STL in FreeCAD.
That makes no sense. The model is effectively a polyhedron mesh and
does not need to be converted.
Droftarts says that STL is no good because it doesn't "retain the
geometry".
STL is ALL geometry and no topology, unlike a polyhedron. It may be true
it does not retain the geometry either, depending on how the coordinates
are modified.
Does FreeCAD understand the polyhedron command?
Carsten Arnholm
On 18. mars 2016 18:58, Carsten Arnholm wrote:
Does FreeCAD understand the polyhedron command?
I just tried it and it doesn't.
I guess the explanation is that FreeCAD is based on OpenCASCADE which
does booleans on a B-rep model only.
Carsten Arnholm
By "geometry" people mean CSG in this context. I.e. cylinders and cubes,
etc, as opposed to a triangle mesh.
On 18 March 2016 at 17:58, Carsten Arnholm arnholm@arnholm.org wrote:
On 18. mars 2016 17:07, doug moen wrote:
Converting the model to a polyhedron would be no different from exporting
as STL and then importing the STL in FreeCAD.
That makes no sense. The model is effectively a polyhedron mesh and does
not need to be converted.
Droftarts says that STL is no good because it doesn't "retain the
geometry".
STL is ALL geometry and no topology, unlike a polyhedron. It may be true
it does not retain the geometry either, depending on how the coordinates
are modified.
Does FreeCAD understand the polyhedron command?
Carsten Arnholm
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Yes, that is what I meant, that CSG appears to be the only way to export a
model from openSCAD with smooth curves, and with the parts still
individually selectable. When you import a CSG into FreeCAD, you should get
smooth geometry, and the ability to select individual bodies of the
assembly. This should continue into the STEP file, and allow the individual
parts to be assigned material appearance, so making the render appear more
lifelike. You could export each individual part, in position, as an STL, and
bring this in, but I was experimenting to see if I can export for rendering
in one smooth operation, while maintaining quality (ie without
triangulation).
Thanks for the help, I'll incorporate it into my model, see how far it gets,
and report back. My only other option was to write a better renderer for
OpenSCAD, which is definitely above my programming level! Or maybe STEP
export...
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16575.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
STEP format import/export is available via:
Its a database kind of format.
In case anyone's interested....
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16576.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Hi nophead
Thanks for this, I never knew how to loop an array before! I wrote a little
example for myself, which helped me understand:
points = [0,1,2,3,4];
length = len (points);
for (i=[0:length*2-1])
echo (points[(i) % length],points[(i+1) % length]);
This runs around the array twice (the '*2' part in the 'for' loop), and
produces:
ECHO: 0, 1
ECHO: 1, 2
ECHO: 2, 3
ECHO: 3, 4
ECHO: 4, 0
ECHO: 0, 1
ECHO: 1, 2
ECHO: 2, 3
ECHO: 3, 4
ECHO: 4, 0
I'm sure using MOD is a fairly standard programming technique, but then I'm
not much of a programmer!
Ian S
nophead wrote
It calculates the remainder after dividing by the length. That causes the
wrap round to zero to close the loop when i+1 equals the length.
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16623.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Neon22 wrote
STEP format import/export is available via:
Its a database kind of format.
In case anyone's interested....
Looks interesting, and it would be great to have output from OpenSCAD that
is more friendly with other CAD packages, that kept the primitive geometry
and parts grouped together. Then it would be easy to export and add
finishing touches eg fillets. But I have no idea if this could be
incorporated into OpenSCAD, and give useful output. Maybe raise it as an
issue on github for the developers to take a look at?
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16628.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Producing decent quality STEP output, for the general case, looks like a
complex and challenging project that might require some significant
language extensions. We could also try for simple STEP export, which would
take the CSG tree as input, and fail if any primitives are found that can't
be translated to STEP.
I did a bit of web surfing for this. STEP is a huge standard for encoding
all kinds of manufacturing related data. It's not a file format, it's a
large family of file formats. The particular STEP file format we'd target
is AP203. There's also AP214, which is a superset, but the added features
seem to be things we don't support anyway.
The AP203 definition document is an ISO standard costing 198 swiss franks
(about $200 US). I'd guess you'd need to buy additional standards to
provide the background information for understanding this standard. It
sounds expensive. Another developer cost is purchasing the expensive CAD
programs that read STEP files, like SolidWorks.
I found a database schema for AP203. It appears that AP203 is a large,
complex language for describing geometric solids. It supports splines,
conic curves, meshes, etc. I'm calling it a language because it has
functions like vector cross product.
Anyway, AP203 appears to be a much bigger language than OpenSCAD, but it
also seems to be missing primitives that we support like convex hull and
minkowski sum.
Given how a lot of high level AP203 geometric primitives are coded directly
in OpenSCAD, such as splines and swept volumes, the CSG tree wouldn't be
enough for a good conversion. We'd need the ability to put AP203 metadata
into module definitions to guide the conversion process.
Given the complexity and cost of a good solution, and the limitations and
crappiness of a simple solution, I don't see this as a good fit for the
OpenSCAD project. If someone wants to work on this, I would suggest writing
an external tool for converting CSG files to STEP. Then we'll see.
On 21 March 2016 at 08:15, droftarts ginjaian@hotmail.com wrote:
Neon22 wrote
STEP format import/export is available via:
Its a database kind of format.
In case anyone's interested....
Looks interesting, and it would be great to have output from OpenSCAD that
is more friendly with other CAD packages, that kept the primitive geometry
and parts grouped together. Then it would be easy to export and add
finishing touches eg fillets. But I have no idea if this could be
incorporated into OpenSCAD, and give useful output. Maybe raise it as an
issue on github for the developers to take a look at?
Ian S
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16628.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Many thanks nophead, this works perfectly. It also has a nice feature, that
if you set the radius to '0', it does still work, and produces a 'point'
corner. I guess because the maths in the tangent function ends up = 0 for
the point where the radius = 0. It doesn't even put two points in on the
corner; polygon seems to be smart enough that if you have two point in the
same place, it ignores one of them!
The only improvement might be to error trap any cases where one circle
completely encircles (or is completely inside) the next, or if a
negative-radius circle overlaps a positive one; in both cases the polygon
fails to draw, as there are no tangents that can be calculated, with a
"WARNING: Range check failed for polygon. skipping" message. But maybe this
is actually preferable to ignoring an overlapping circle, and continuing to
draw the shape incorrectly.
Regarding exporting in STEP format, and subsequently opening in CAD software
for rendering: the point is to try and get an assembly of many parts out of
OpenSCAD in one export, where each individual part is separately selectable,
unlike STL ouput. This means that it's easier to apply appearances to
individual parts for rendering, and also it's a better/easier format for
editing in most CAD packages. By using CSG output, there is the additional
advantage of keeping curves and circles as arcs, rather than segmenting
them, which again makes them easier to manipulate in a solid modeller, which
most CAD programs are.
Though CSG exports all the underlying geometry (circles, squares, polygons
etc), once in FreeCAD, only the solid bodies (ie the extrusion based on all
the circles, squares and polygons) are required, not the underlying
geometry, for the STEP file. You can export the simple geometry (most CAD
software suggests building your parts as 2D drawings and extruding to 3D,
which is what the simple geometry is), but I intended the export to be in
one direction, so I don't mind that I remove this geometry. I haven't played
around with Blender much, but I understand it's a 'mesh' modeller, so STL is
a good format for it, and why it doesn't understand what a 'circle' is, let
alone the other OpenSCAD transformations!
A small problem with FreeCAD is that its OpenSCAD import filter needs
updating, as changes in OpenSCAD appear to have caused it to fail if you use
the latest version of OpenSCAD (see
http://forum.freecadweb.org/viewtopic.php?t=12744 ); at least, this is what
it does for me using the current compiled versions of FreeCAD (0.15) and
OpenSCAD (2015.03-2). I don't think this affects importing of CSG files,
just .scad files, and the way FreeCAD imports files is to open the .scad
file in OpenSCAD, and import the .csg file anyway! So I don't think there is
any advantage import the .scad file into FreeCAD (even if you could - it
didn't work when I used OpenSCAD 2014.03 either) over the .csg file.
I based my initial script on circles, rather than squares, as squares are
generally easier to redraw to remove the hull or minkowski command. My
design has rounded corners, so most squares were minkowski'd squares anyway,
which this script can replicate without using minkowski. I know this is
really only a solution for 2D uses of hull and minkowski, and perhaps rather
particular to my intent. I'm not really sure how you could do the same thing
for a 3D object, and get a sensible CSG ouput that you can import into
FreeCAD, to convert to a solid.
Thanks for all the help, hope this is useful to others, too!
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16635.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
I've replaced all the hull and minkowski transformations in my model with the
rounded_polygon script, and exported it from OpenSCAD as a CSG file, which
was then opened in FreeCAD. To export as a STEP file with the 'bodies'
(effectively components) separate (rather than all as one body, so only one
thing is selectable), you need to select each individual body you want in
FreeCAD before exporting as STEP. I don't have too many bodies in my model,
so this wasn't too onerous, only taking a couple of minutes. Then export as
STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try
to do much to the model, just checked that it was editable (it is), then
applied 'appearances' to various bodies. You can also apply appearances to
specific faces. After rendering, I got this, which I'm very happy with:
http://forum.openscad.org/file/n16661/Frame.png
Yes, it's another 3D printer... basically a fully parametric lasercut/CNC
routed/hand cut frame replacement for Mendel/Prusa machines, with minimal
vitamins and no printed parts (so far), and very quick to build. I've
already built a couple of these (admittedly with a standard Prusa i2
x-axis), and they're nice and stiff, and print well (J-head nozzle and
direct drive extruder).
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16661.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Hard to tell it isn't a photo of a real object. I wish OpenScad could do
that sort of rendering.
On 22 March 2016 at 18:16, droftarts ginjaian@hotmail.com wrote:
I've replaced all the hull and minkowski transformations in my model with
the
rounded_polygon script, and exported it from OpenSCAD as a CSG file, which
was then opened in FreeCAD. To export as a STEP file with the 'bodies'
(effectively components) separate (rather than all as one body, so only one
thing is selectable), you need to select each individual body you want in
FreeCAD before exporting as STEP. I don't have too many bodies in my model,
so this wasn't too onerous, only taking a couple of minutes. Then export as
STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try
to do much to the model, just checked that it was editable (it is), then
applied 'appearances' to various bodies. You can also apply appearances to
specific faces. After rendering, I got this, which I'm very happy with:
http://forum.openscad.org/file/n16661/Frame.png
Yes, it's another 3D printer... basically a fully parametric lasercut/CNC
routed/hand cut frame replacement for Mendel/Prusa machines, with minimal
vitamins and no printed parts (so far), and very quick to build. I've
already built a couple of these (admittedly with a standard Prusa i2
x-axis), and they're nice and stiff, and print well (J-head nozzle and
direct drive extruder).
Ian S
--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16661.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
nophead wrote
Hard to tell it isn't a photo of a real object. I wish OpenScad could do
that sort of rendering.
Yes, I'm rather pleased with it! I really didn't have to do very much to the
OpenSCAD output to achieve this, apart from recoding to remove minkowski and
hull. And Fusion 360 is free for 'hobbyists', and is a pretty fully-featured
CAD package.
Many thanks for your help, Chris. I've spoken to you a number of times; I
was the tech support guy at RepRapPro, and also did this thing a while ago,
which I'm in the process of updating with what I've learnt from looking at
the Mendel90 scad files! http://www.thingiverse.com/thing:16627
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16664.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
That’s very nice Ian.
Is it rounded_polygon from Nophead’s email of 18/03 15:33 you used?
I am keen to recreate your work, but I am a big fan of Minkowski and it’s in most of my printer parts! However I use my own module to manage it better, so hopefully I can substitute the rounded polygon script or similar without breaking my designs…
By the way, I shipped the first Edumaker prototype today J
Cheers
Alex
From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head
Sent: 22 March 2016 18:25
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Script to replicate hull and minkoswki for CSG export/import into FreeCAD
Hard to tell it isn't a photo of a real object. I wish OpenScad could do that sort of rendering.
On 22 March 2016 at 18:16, droftarts ginjaian@hotmail.com wrote:
I've replaced all the hull and minkowski transformations in my model with the
rounded_polygon script, and exported it from OpenSCAD as a CSG file, which
was then opened in FreeCAD. To export as a STEP file with the 'bodies'
(effectively components) separate (rather than all as one body, so only one
thing is selectable), you need to select each individual body you want in
FreeCAD before exporting as STEP. I don't have too many bodies in my model,
so this wasn't too onerous, only taking a couple of minutes. Then export as
STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try
to do much to the model, just checked that it was editable (it is), then
applied 'appearances' to various bodies. You can also apply appearances to
specific faces. After rendering, I got this, which I'm very happy with:
http://forum.openscad.org/file/n16661/Frame.png
Yes, it's another 3D printer... basically a fully parametric lasercut/CNC
routed/hand cut frame replacement for Mendel/Prusa machines, with minimal
vitamins and no printed parts (so far), and very quick to build. I've
already built a couple of these (admittedly with a standard Prusa i2
x-axis), and they're nice and stiff, and print well (J-head nozzle and
direct drive extruder).
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16661.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
alexgibson wrote
That’s very nice Ian. Is it rounded_polygon from Nophead’s email of
18/03 15:33 you used?
Yes, I don't think I changed anything from that version. Remember, the
points have to go around in a clockwise direction, though.
alexgibson wrote
By the way, I shipped the first Edumaker prototype today J
Congratulations! I was hoping to catch up with you at rlab last night, as
I'd like to do a coreXY machine using the same construction method as this
machine, but probably with your XY layout (or something similar).
Ian S
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16669.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Hi Nophead,
Many thanks again for this super useful script back in March.
I have a big request – how would I go about converting this to be a ‘rounded_polygon’ 3d version?
I’m similarly to Ian trying to export an OpenSCAD project to Fusion 360, and find that some fairly straightforward (In Openscad) ‘hull’ functions are hard to recreate.
Or if there’s any other way to replicate the hull() function in Fusion 360 I’d love to know!
Many thanks,
Alex
From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head
Sent: 18 March 2016 15:32
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Script to replicate hull and minkoswki for CSG export/import into FreeCAD
Cleaned up the generated csg by moving the circle translates inside the if and replaced a call of len(points) with len.
$fn = 100;
shape1 = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0, 20] ];
linear_extrude (height = 5) rounded_polygon(shape1);
module rounded_polygon(points)
difference() {
len = len(points);
union() {
for(i = [0 : len - 1])
if(points[i][2] > 0)
translate([points[i].x, points[i].y])
circle(points[i][2]);
polygon([for(i = [0 : len - 1])
let(ends = tangent(points[i], points[(i + 1) % len]))
for(end = [0, 1])
ends[end]]);
}
for(i = [0 : len - 1])
if(points[i][2] < 0)
translate([points[i].x, points[i].y])
circle(-points[i][2]);
}
function tangent(p1, p2) =
let(
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 15:20, nop head nop.head@gmail.com wrote:
It calculates the remainder after dividing by the length. That causes the wrap round to zero to close the loop when i+1 equals the length.
On 18 March 2016 at 15:10, droftarts ginjaian@hotmail.com wrote:
Thanks nophead, awesome stuff! I hope you find it useful too. But, dammit,
you're not giving me a chance to use my brain...!
I'll have a sit down over the weekend and see how you've coded this, so I
can understand it. One quick question: you use a '%' sign here:
...
let(ends = tangent(points[i], points[(i + 1) % len(points)]))
...
What does that do? I can see it's a 'scalar arithmetical operator' (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators )
for modulo (so finds the remainder after division of one number by another),
but I'm not clear why!
Ian S
P.S. re 'Stuart', you addressed me as Stuart in your first post!
--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16553.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I recently used the code to model the belt path for an H-bot and calculate
its exact length. I modelled the shape of the pitch line (where the cords
are) and then offset inwards and outwards to get the belt shape.
The 3D equivalent would be stretching an elastic membrane over spheres with
some on the inside and some on the outside. It would be useful but I am not
sure I am up to coding it in OpenSCAD. I think the real issue is that
FreeCAD needs to support hull and Minkowski. I think OpenSCAD now
implements its own versions of those, rather than using CGAL, so perhaps it
would be easy to transplant that code into FreeCAD (licenses permitting). I
have never used FreeCAD so I am not motivated to do it. OpenSCAD does
everything I need.
On 15 November 2016 at 14:34, Alex Gibson alex@alexgibson.net wrote:
Hi Nophead,
Many thanks again for this super useful script back in March.
I have a big request – how would I go about converting this to be a
‘rounded_polygon’ 3d version?
I’m similarly to Ian trying to export an OpenSCAD project to Fusion 360,
and find that some fairly straightforward (In Openscad) ‘hull’ functions
are hard to recreate.
Or if there’s any other way to replicate the hull() function in Fusion 360
I’d love to know!
Many thanks,
Alex
From: Discuss [mailto:discuss-bounces@lists.openscad.org] *On Behalf Of
*nop head
Sent: 18 March 2016 15:32
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Script to replicate hull and minkoswki for CSG
export/import into FreeCAD
Cleaned up the generated csg by moving the circle translates inside the if
and replaced a call of len(points) with len.
$fn = 100;
shape1 = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0,
20] ];
linear_extrude (height = 5) rounded_polygon(shape1);
module rounded_polygon(points)
difference() {
len = len(points);
union() {
for(i = [0 : len - 1])
if(points[i][2] > 0)
translate([points[i].x, points[i].y])
circle(points[i][2]);
polygon([for(i = [0 : len - 1])
let(ends = tangent(points[i], points[(i + 1) %
len]))
for(end = [0, 1])
ends[end]]);
}
for(i = [0 : len - 1])
if(points[i][2] < 0)
translate([points[i].x, points[i].y])
circle(-points[i][2]);
}
function tangent(p1, p2) =
let(
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
On 18 March 2016 at 15:20, nop head nop.head@gmail.com wrote:
It calculates the remainder after dividing by the length. That causes the
wrap round to zero to close the loop when i+1 equals the length.
On 18 March 2016 at 15:10, droftarts ginjaian@hotmail.com wrote:
Thanks nophead, awesome stuff! I hope you find it useful too. But, dammit,
you're not giving me a chance to use my brain...!
I'll have a sit down over the weekend and see how you've coded this, so I
can understand it. One quick question: you use a '%' sign here:
...
let(ends = tangent(points[i], points[(i + 1) % len(points)]))
...
What does that do? I can see it's a 'scalar arithmetical operator' (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators
)
for modulo (so finds the remainder after division of one number by
another),
but I'm not clear why!
Ian S
P.S. re 'Stuart', you addressed me as Stuart in your first post!
--
View this message in context: http://forum.openscad.org/
Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-
tp16537p16553.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org