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