discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] Minkowski Sum and Cookie Cutter

M
MichaelAtOz
Sat, Mar 4, 2017 10:04 PM

Welcome to the forum. Your post is still flagged as "This post has NOT been
accepted by the mailing list yet", so nobody gets it unless they look.
You need to subscribe to the  mailing list
http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1  ,
and CLICK THE LINK in the registration email.

I have copied your post below for others.

borelg wrote

Dear Openscad Forum,

this is my first post here, but It has been a while since I have started
to use Openscad, which I consider a great piece of software.

Anyway, I am having some issue with executing a piece of code. In fact,
when I run the following code it gets incredibly slow:

$fn = 100;

minkowski()
{
linear_extrude(height = 0.1)
import("image.dxf");
cylinder(h = 20, r1 = 2, r2 = 0.4, center = true);
}

And, with slow, I mean that the executing phase (not the rendering, which
it takes even more) it takes hours!

The file "image.dxf" it's the vectorial image of the cookie cutter. I
obtained this image using the following method:

  • I extracted the contour of an image with Gimp
  • I vectorized the bitmap image of the extracted contour using Inkscape
    and I converted the spline in the path with the extension "Flatten Bezier"
    ( i used 0.1 as parameter for this function).
  • I saved the vetorial image as a DXF and I imported that in Openscad as
    you can see from the code.

My target is to obtain a cookie cutter that has sharp edges. I mean that I
do not want just to extrude the image of the contour of the cutter, but I
would like to give to this contour a slope. Thus, I thought about using
the minkowski sum with a suitable structuring element such as a cone (
cylinder function).

Anyway, I believe that I am doing something in the wrong way, and that my
code is written in a way that results very heavy to Openscad.

Do you have any suggestion in order to solve this issue?
If you have any advice about how to achieve my target in a different way,
I would be grateful as well!

Thank you in advance!! :)

Minkowski is notoriously slow, and using $fn=100 will make it much worse.
Use a low $fn to test, only use a bigger value toward the end, and only as
big as really needed (related to the resolution of whatever printer etc you
will make it with).

You could try offset(), a for() loop for height with slightly thicker
offsets as it gets higher?


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/Minkowski-Sum-and-Cookie-Cutter-tp20733p20746.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Welcome to the forum. Your post is still flagged as "This post has NOT been accepted by the mailing list yet", so nobody gets it unless they look. You need to subscribe to the mailing list <http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1> , and CLICK THE LINK in the registration email. I have copied your post below for others. borelg wrote > Dear Openscad Forum, > > this is my first post here, but It has been a while since I have started > to use Openscad, which I consider a great piece of software. > > Anyway, I am having some issue with executing a piece of code. In fact, > when I run the following code it gets incredibly slow: > $fn = 100; > > minkowski() > { > linear_extrude(height = 0.1) > import("image.dxf"); > cylinder(h = 20, r1 = 2, r2 = 0.4, center = true); > } > > And, with slow, I mean that the executing phase (not the rendering, which > it takes even more) it takes hours! > > The file "image.dxf" it's the vectorial image of the cookie cutter. I > obtained this image using the following method: > > - I extracted the contour of an image with Gimp > - I vectorized the bitmap image of the extracted contour using Inkscape > and I converted the spline in the path with the extension "Flatten Bezier" > ( i used 0.1 as parameter for this function). > - I saved the vetorial image as a DXF and I imported that in Openscad as > you can see from the code. > > My target is to obtain a cookie cutter that has sharp edges. I mean that I > do not want just to extrude the image of the contour of the cutter, but I > would like to give to this contour a slope. Thus, I thought about using > the minkowski sum with a suitable structuring element such as a cone ( > cylinder function). > > Anyway, I believe that I am doing something in the wrong way, and that my > code is written in a way that results very heavy to Openscad. > > Do you have any suggestion in order to solve this issue? > If you have any advice about how to achieve my target in a different way, > I would be grateful as well! > > Thank you in advance!! :) Minkowski is notoriously slow, and using $fn=100 will make it much worse. Use a low $fn to test, only use a bigger value toward the end, and only as big as really needed (related to the resolution of whatever printer etc you will make it with). You could try offset(), a for() loop for height with slightly thicker offsets as it gets higher? ----- Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/Minkowski-Sum-and-Cookie-Cutter-tp20733p20746.html Sent from the OpenSCAD mailing list archive at Nabble.com.
TP
Torsten Paul
Sat, Mar 4, 2017 11:54 PM

borelg wrote

And, with slow, I mean that the executing phase (not the
rendering, which it takes even more) it takes hours!

This is way too high resolution for a cookie cutter, both
the $fn=100 and also the 0.1 beziers.

The heart cookie cutter below is probably still higher
resolution than actually needed, but renders in less
than 4 minutes. The star even renders in just 14 seconds
because of the small amount of vertices in the 2D base
shape.

ciao,
Torsten.

---snip---snap---snip---snap---snip---snap---snip---snap---
// CC BY-SA 4.0

$fa = 2;
$fs = 0.4;

height = 12;

module heart(w = 30) {
translate([0, w * sqrt(2) / 2]) {
rotate(-135) {
square(w);
translate([w / 2, 0]) circle(d = w);
translate([0, w / 2]) circle(d = w);
}
}
}

module star(n = 5, r1 = 22, r2 = 40) {
function r(a) = a % 2 == 0 ? r2 : r1;
function p(a) = [ -sin(a), cos(a) ];

assert(n >= 3);
points = [ for (a = [0 : 2 * n - 1]) r(a) * p(180 / n * a) ];
polygon(points);

}

module outline() {
difference() {
offset(0.01) children();
children();
}
}

module cut(height, base_height, r1, r2) {
translate([0, 0, -base_height]) cylinder(r = 2 * r1, h = base_height);
translate([0, 0, -0.01]) cylinder(r1 = r1, r2 = r2, h = height);
}

module cookie_cutter(height = 12, base_height = 1, r1 = 0.8, r2 = 0.2) {
minkowski() {
linear_extrude(0.01) outline() children();
cut(height, base_height, r1, r2);
}
}

cookie_cutter() heart(30);

// cookie_cutter() star(5, 22, 40);

---snip---snap---snip---snap---snip---snap---snip---snap---

borelg wrote > And, with slow, I mean that the executing phase (not the > rendering, which it takes even more) it takes hours! > This is way too high resolution for a cookie cutter, both the $fn=100 and also the 0.1 beziers. The heart cookie cutter below is probably still higher resolution than actually needed, but renders in less than 4 minutes. The star even renders in just 14 seconds because of the small amount of vertices in the 2D base shape. ciao, Torsten. ---snip---snap---snip---snap---snip---snap---snip---snap--- // CC BY-SA 4.0 $fa = 2; $fs = 0.4; height = 12; module heart(w = 30) { translate([0, w * sqrt(2) / 2]) { rotate(-135) { square(w); translate([w / 2, 0]) circle(d = w); translate([0, w / 2]) circle(d = w); } } } module star(n = 5, r1 = 22, r2 = 40) { function r(a) = a % 2 == 0 ? r2 : r1; function p(a) = [ -sin(a), cos(a) ]; assert(n >= 3); points = [ for (a = [0 : 2 * n - 1]) r(a) * p(180 / n * a) ]; polygon(points); } module outline() { difference() { offset(0.01) children(); children(); } } module cut(height, base_height, r1, r2) { translate([0, 0, -base_height]) cylinder(r = 2 * r1, h = base_height); translate([0, 0, -0.01]) cylinder(r1 = r1, r2 = r2, h = height); } module cookie_cutter(height = 12, base_height = 1, r1 = 0.8, r2 = 0.2) { minkowski() { linear_extrude(0.01) outline() children(); cut(height, base_height, r1, r2); } } cookie_cutter() heart(30); // cookie_cutter() star(5, 22, 40); ---snip---snap---snip---snap---snip---snap---snip---snap---