discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to get an outline of a 2D object?

RP
Ronaldo Persiano
Mon, Nov 16, 2020 10:16 PM

I don't have a general solution to your problem but if the polygon you want
has some properties there is a way to find it.

The simpler case (besides a convex polygon) happens when the polygon has a
"visual center", that is an inner point from which all vertices can be seen
from inside. The solution for those cases is just to translate the polygon
so that the center goes to the origin, then extrude it with a scale nearly
zero, project it back to the xy plane and translating it back to the
center.

module fill_holes(center)

translate(center) {
projection()
linear_extrude(1, scale=0.0001)
translate( - center) children();
scale(.01) hull() children();
}

The hull was added to prevent for an eventual hole at the center (because
the scale cannot be zero).

If no such center exists, fill_holes(p) holed_poly() will include some
points that doesn't belongs to holed_poly() for all possible point p.  In
this case, you may try to intersect all  fill_holes(p) holed_poly() for p
in a set of points P. A good choice of the set P may produce the correct
answer.

module fill_holes2(P)

intersection_for(p=P)

translate(center) {
  projection()
    linear_extrude(1, scale=0.0001)
      translate( - center) children();
scale(.01) hull() children();

}

In this case, the set P doesn't need to be inside the polygon.

Em sáb., 14 de nov. de 2020 às 19:36, Troberg troberg.anders@gmail.com
escreveu:

I have a problem. I have 2D objects, which might be concave, and which has
holes in them. These objects are pretty complex, done in several stages,
and
the holes are made in a pretty early part of the process, and the holes may
(or may not) also affect the shape of the outline.

What I want is to get just the outer contour of the object, without the
holes contained fully within, to create masks for other stages in the
production.

If I knew the objects were convex, it wouldn't be a problem, then hull()
would work, but I cannot rely on them to be convex (in fact, they most
certainly aren't).

If the objects were simple, I could do it by union() with some "cover
objects", but they aren't.

If I could do the holes last, it would (partly, but not guaranteed) help,
but I can't as I have other later stages which requires them to be there.

Likewise, bouncing an offset out and back won't work, as it'll affect
corners.

So, any idea on how one could do an outline() module?

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I don't have a general solution to your problem but if the polygon you want has some properties there is a way to find it. The simpler case (besides a convex polygon) happens when the polygon has a "visual center", that is an inner point from which all vertices can be seen from inside. The solution for those cases is just to translate the polygon so that the center goes to the origin, then extrude it with a scale nearly zero, project it back to the xy plane and translating it back to the center. module fill_holes(center) translate(center) { projection() linear_extrude(1, scale=0.0001) translate( - center) children(); scale(.01) hull() children(); } The hull was added to prevent for an eventual hole at the center (because the scale cannot be zero). If no such center exists, fill_holes(p) holed_poly() will include some points that doesn't belongs to holed_poly() for all possible point p. In this case, you may try to intersect all fill_holes(p) holed_poly() for p in a set of points P. A good choice of the set P may produce the correct answer. module fill_holes2(P) intersection_for(p=P) translate(center) { projection() linear_extrude(1, scale=0.0001) translate( - center) children(); scale(.01) hull() children(); } In this case, the set P doesn't need to be inside the polygon. Em sáb., 14 de nov. de 2020 às 19:36, Troberg <troberg.anders@gmail.com> escreveu: > I have a problem. I have 2D objects, which might be concave, and which has > holes in them. These objects are pretty complex, done in several stages, > and > the holes are made in a pretty early part of the process, and the holes may > (or may not) also affect the shape of the outline. > > What I want is to get just the outer contour of the object, without the > holes contained fully within, to create masks for other stages in the > production. > > If I knew the objects were convex, it wouldn't be a problem, then hull() > would work, but I cannot rely on them to be convex (in fact, they most > certainly aren't). > > If the objects were simple, I could do it by union() with some "cover > objects", but they aren't. > > If I could do the holes last, it would (partly, but not guaranteed) help, > but I can't as I have other later stages which requires them to be there. > > Likewise, bouncing an offset out and back won't work, as it'll affect > corners. > > So, any idea on how one could do an outline() module? > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
NH
nop head
Mon, Nov 16, 2020 10:52 PM

Very clever.

On Mon, 16 Nov 2020 at 22:17, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

I don't have a general solution to your problem but if the polygon you
want has some properties there is a way to find it.

The simpler case (besides a convex polygon) happens when the polygon has a
"visual center", that is an inner point from which all vertices can be seen
from inside. The solution for those cases is just to translate the polygon
so that the center goes to the origin, then extrude it with a scale nearly
zero, project it back to the xy plane and translating it back to the
center.

module fill_holes(center)

translate(center) {
projection()
linear_extrude(1, scale=0.0001)
translate( - center) children();
scale(.01) hull() children();
}

The hull was added to prevent for an eventual hole at the center (because
the scale cannot be zero).

If no such center exists, fill_holes(p) holed_poly() will include some
points that doesn't belongs to holed_poly() for all possible point p.  In
this case, you may try to intersect all  fill_holes(p) holed_poly() for p
in a set of points P. A good choice of the set P may produce the correct
answer.

module fill_holes2(P)

intersection_for(p=P)

 translate(center) {
   projection()
     linear_extrude(1, scale=0.0001)
       translate( - center) children();
 scale(.01) hull() children();

}

In this case, the set P doesn't need to be inside the polygon.

Em sáb., 14 de nov. de 2020 às 19:36, Troberg troberg.anders@gmail.com
escreveu:

I have a problem. I have 2D objects, which might be concave, and which has
holes in them. These objects are pretty complex, done in several stages,
and
the holes are made in a pretty early part of the process, and the holes
may
(or may not) also affect the shape of the outline.

What I want is to get just the outer contour of the object, without the
holes contained fully within, to create masks for other stages in the
production.

If I knew the objects were convex, it wouldn't be a problem, then hull()
would work, but I cannot rely on them to be convex (in fact, they most
certainly aren't).

If the objects were simple, I could do it by union() with some "cover
objects", but they aren't.

If I could do the holes last, it would (partly, but not guaranteed) help,
but I can't as I have other later stages which requires them to be there.

Likewise, bouncing an offset out and back won't work, as it'll affect
corners.

So, any idea on how one could do an outline() module?

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Very clever. On Mon, 16 Nov 2020 at 22:17, Ronaldo Persiano <rcmpersiano@gmail.com> wrote: > I don't have a general solution to your problem but if the polygon you > want has some properties there is a way to find it. > > The simpler case (besides a convex polygon) happens when the polygon has a > "visual center", that is an inner point from which all vertices can be seen > from inside. The solution for those cases is just to translate the polygon > so that the center goes to the origin, then extrude it with a scale nearly > zero, project it back to the xy plane and translating it back to the > center. > > module fill_holes(center) > > translate(center) { > projection() > linear_extrude(1, scale=0.0001) > translate( - center) children(); > scale(.01) hull() children(); > } > > > The hull was added to prevent for an eventual hole at the center (because > the scale cannot be zero). > > If no such center exists, fill_holes(p) holed_poly() will include some > points that doesn't belongs to holed_poly() for all possible point p. In > this case, you may try to intersect all fill_holes(p) holed_poly() for p > in a set of points P. A good choice of the set P may produce the correct > answer. > > module fill_holes2(P) > > intersection_for(p=P) > > translate(center) { > projection() > linear_extrude(1, scale=0.0001) > translate( - center) children(); > scale(.01) hull() children(); > } > > > In this case, the set P doesn't need to be inside the polygon. > > Em sáb., 14 de nov. de 2020 às 19:36, Troberg <troberg.anders@gmail.com> > escreveu: > >> I have a problem. I have 2D objects, which might be concave, and which has >> holes in them. These objects are pretty complex, done in several stages, >> and >> the holes are made in a pretty early part of the process, and the holes >> may >> (or may not) also affect the shape of the outline. >> >> What I want is to get just the outer contour of the object, without the >> holes contained fully within, to create masks for other stages in the >> production. >> >> If I knew the objects were convex, it wouldn't be a problem, then hull() >> would work, but I cannot rely on them to be convex (in fact, they most >> certainly aren't). >> >> If the objects were simple, I could do it by union() with some "cover >> objects", but they aren't. >> >> If I could do the holes last, it would (partly, but not guaranteed) help, >> but I can't as I have other later stages which requires them to be there. >> >> Likewise, bouncing an offset out and back won't work, as it'll affect >> corners. >> >> So, any idea on how one could do an outline() module? >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> 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 >
T
Troberg
Tue, Nov 17, 2020 6:36 AM

Ronaldo wrote

I don't have a general solution to your problem but if the polygon you
want
has some properties there is a way to find it.

The simpler case (besides a convex polygon) happens when the polygon has a
"visual center", that is an inner point from which all vertices can be
seen
from inside. The solution for those cases is just to translate the polygon
so that the center goes to the origin, then extrude it with a scale nearly
zero, project it back to the xy plane and translating it back to the
center.

Really neat, but, sadly, my shapes doesn't (usually) have such a center,
being, in part, composed of arch-like segments.

Some examples of what I do here (not too explicit, but don't look on a work
computer):
https://beguilingtorments.com/ElMachoGrande/img/toys_notbuilt/en_toys_notbuilt.html

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

Ronaldo wrote > I don't have a general solution to your problem but if the polygon you > want > has some properties there is a way to find it. > > The simpler case (besides a convex polygon) happens when the polygon has a > "visual center", that is an inner point from which all vertices can be > seen > from inside. The solution for those cases is just to translate the polygon > so that the center goes to the origin, then extrude it with a scale nearly > zero, project it back to the xy plane and translating it back to the > center. Really neat, but, sadly, my shapes doesn't (usually) have such a center, being, in part, composed of arch-like segments. Some examples of what I do here (not too explicit, but don't look on a work computer): https://beguilingtorments.com/ElMachoGrande/img/toys_notbuilt/en_toys_notbuilt.html -- Sent from: http://forum.openscad.org/
AC
A. Craig West
Tue, Nov 17, 2020 12:22 PM

My solution to this was annoyingly crude, I wrote my modules with two
boolean parameters, includeHoles and includeOutlines, then use if
statements inside the module to enable the appropriate shapes inside the
module

On Sat, 14 Nov 2020, 14:36 Troberg, troberg.anders@gmail.com wrote:

I have a problem. I have 2D objects, which might be concave, and which has
holes in them. These objects are pretty complex, done in several stages,
and
the holes are made in a pretty early part of the process, and the holes may
(or may not) also affect the shape of the outline.

What I want is to get just the outer contour of the object, without the
holes contained fully within, to create masks for other stages in the
production.

If I knew the objects were convex, it wouldn't be a problem, then hull()
would work, but I cannot rely on them to be convex (in fact, they most
certainly aren't).

If the objects were simple, I could do it by union() with some "cover
objects", but they aren't.

If I could do the holes last, it would (partly, but not guaranteed) help,
but I can't as I have other later stages which requires them to be there.

Likewise, bouncing an offset out and back won't work, as it'll affect
corners.

So, any idea on how one could do an outline() module?

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

My solution to this was annoyingly crude, I wrote my modules with two boolean parameters, includeHoles and includeOutlines, then use if statements inside the module to enable the appropriate shapes inside the module On Sat, 14 Nov 2020, 14:36 Troberg, <troberg.anders@gmail.com> wrote: > I have a problem. I have 2D objects, which might be concave, and which has > holes in them. These objects are pretty complex, done in several stages, > and > the holes are made in a pretty early part of the process, and the holes may > (or may not) also affect the shape of the outline. > > What I want is to get just the outer contour of the object, without the > holes contained fully within, to create masks for other stages in the > production. > > If I knew the objects were convex, it wouldn't be a problem, then hull() > would work, but I cannot rely on them to be convex (in fact, they most > certainly aren't). > > If the objects were simple, I could do it by union() with some "cover > objects", but they aren't. > > If I could do the holes last, it would (partly, but not guaranteed) help, > but I can't as I have other later stages which requires them to be there. > > Likewise, bouncing an offset out and back won't work, as it'll affect > corners. > > So, any idea on how one could do an outline() module? > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
T
Troberg
Tue, Nov 17, 2020 12:33 PM

acwest wrote

My solution to this was annoyingly crude, I wrote my modules with two
boolean parameters, includeHoles and includeOutlines, then use if
statements inside the module to enable the appropriate shapes inside the
module

If it's just simple holes, then, sure, but when they affect the shape of the
final object (using offset()), it's not that simple.

I rely on offset() a lot to produce smooth, almost organic looking shapes.

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

acwest wrote > My solution to this was annoyingly crude, I wrote my modules with two > boolean parameters, includeHoles and includeOutlines, then use if > statements inside the module to enable the appropriate shapes inside the > module If it's just simple holes, then, sure, but when they affect the shape of the final object (using offset()), it's not that simple. I rely on offset() a lot to produce smooth, almost organic looking shapes. -- Sent from: http://forum.openscad.org/
D
dpa
Tue, Nov 17, 2020 2:56 PM

I don't know if this was discussed already, this is also not 100% clean:
offset() could close your internal things. The problem is that it may
deform sharp notches

offset(r= -offsetsize) // set back the offset
offset(r=  offsetsize) // make a lot of offset
2Dobject();

example attached

Am Di., 17. Nov. 2020 um 13:34 Uhr schrieb Troberg <troberg.anders@gmail.com

:

acwest wrote

My solution to this was annoyingly crude, I wrote my modules with two
boolean parameters, includeHoles and includeOutlines, then use if
statements inside the module to enable the appropriate shapes inside the
module

If it's just simple holes, then, sure, but when they affect the shape of
the
final object (using offset()), it's not that simple.

I rely on offset() a lot to produce smooth, almost organic looking shapes.

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I don't know if this was discussed already, this is also not 100% clean: offset() could close your internal things. The problem is that it may deform sharp notches offset(r= -offsetsize) // set back the offset offset(r= offsetsize) // make a lot of offset 2Dobject(); example attached Am Di., 17. Nov. 2020 um 13:34 Uhr schrieb Troberg <troberg.anders@gmail.com >: > acwest wrote > > My solution to this was annoyingly crude, I wrote my modules with two > > boolean parameters, includeHoles and includeOutlines, then use if > > statements inside the module to enable the appropriate shapes inside the > > module > > If it's just simple holes, then, sure, but when they affect the shape of > the > final object (using offset()), it's not that simple. > > I rely on offset() a lot to produce smooth, almost organic looking shapes. > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
RP
Ronaldo Persiano
Tue, Nov 17, 2020 3:30 PM

Nice designs,

I guess that if you could collect all arc and circle center points in a
list P, fill_holes2(P) would give you the outline you want.

Em ter., 17 de nov. de 2020 às 06:37, Troberg troberg.anders@gmail.com
escreveu:

Ronaldo wrote

I don't have a general solution to your problem but if the polygon you
want
has some properties there is a way to find it.

The simpler case (besides a convex polygon) happens when the polygon has

a

"visual center", that is an inner point from which all vertices can be
seen
from inside. The solution for those cases is just to translate the

polygon

so that the center goes to the origin, then extrude it with a scale

nearly

zero, project it back to the xy plane and translating it back to the
center.

Really neat, but, sadly, my shapes doesn't (usually) have such a center,
being, in part, composed of arch-like segments.

Some examples of what I do here (not too explicit, but don't look on a work
computer):

https://beguilingtorments.com/ElMachoGrande/img/toys_notbuilt/en_toys_notbuilt.html

Nice designs, I guess that if you could collect all arc and circle center points in a list P, fill_holes2(P) would give you the outline you want. Em ter., 17 de nov. de 2020 às 06:37, Troberg <troberg.anders@gmail.com> escreveu: > Ronaldo wrote > > I don't have a general solution to your problem but if the polygon you > > want > > has some properties there is a way to find it. > > > > The simpler case (besides a convex polygon) happens when the polygon has > a > > "visual center", that is an inner point from which all vertices can be > > seen > > from inside. The solution for those cases is just to translate the > polygon > > so that the center goes to the origin, then extrude it with a scale > nearly > > zero, project it back to the xy plane and translating it back to the > > center. > > Really neat, but, sadly, my shapes doesn't (usually) have such a center, > being, in part, composed of arch-like segments. > > Some examples of what I do here (not too explicit, but don't look on a work > computer): > > https://beguilingtorments.com/ElMachoGrande/img/toys_notbuilt/en_toys_notbuilt.html > >
P
Parkinbot
Tue, Nov 17, 2020 11:52 PM

Ronaldo wrote

I don't have a general solution to your problem but if the polygon you
want
has some properties there is a way to find it.

this was also my first thought. As long as the origin is within the polygon
it is enough to write:

projection()
linear_extrude(height = 1, scale =0)
convex_with_hole();

all other cases can easily be done with the boundingbox() function the
OpenSCAD community has been waiting for years now.

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

Ronaldo wrote > I don't have a general solution to your problem but if the polygon you > want > has some properties there is a way to find it. this was also my first thought. As long as the origin is within the polygon it is enough to write: projection() linear_extrude(height = 1, scale =0) convex_with_hole(); all other cases can easily be done with the boundingbox() function the OpenSCAD community has been waiting for years now. -- Sent from: http://forum.openscad.org/
RP
Ronaldo Persiano
Wed, Nov 18, 2020 4:52 AM

My last suggestion doesn't work.

What will you do if you had the bounding box?

A terça, 17/11/2020, 20:52, Parkinbot rudolf@digitaldocument.de escreveu:

Ronaldo wrote

I don't have a general solution to your problem but if the polygon you
want
has some properties there is a way to find it.

this was also my first thought. As long as the origin is within the polygon
it is enough to write:

projection()
linear_extrude(height = 1, scale =0)
convex_with_hole();

all other cases can easily be done with the boundingbox() function the
OpenSCAD community has been waiting for years now.

My last suggestion doesn't work. What will you do if you had the bounding box? A terça, 17/11/2020, 20:52, Parkinbot <rudolf@digitaldocument.de> escreveu: > Ronaldo wrote > > I don't have a general solution to your problem but if the polygon you > > want > > has some properties there is a way to find it. > > this was also my first thought. As long as the origin is within the polygon > it is enough to write: > > projection() > linear_extrude(height = 1, scale =0) > convex_with_hole(); > > all other cases can easily be done with the boundingbox() function the > OpenSCAD community has been waiting for years now. >
P
Parkinbot
Wed, Nov 18, 2020 11:53 AM

A boundingbox function would probably return me the coordinates of the
diagonal and I could calculate the center and a translation, just like you
do it.

Of course a boundingbox function can also be implemented to just return the
[dx, dy, dz] extents according to the three axes. But this would be the
worst way to implement it. Usually it is implemented to return a pair of
3D-points or a box object with an origin and the [dx, dy, dz] extents.

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

A boundingbox function would probably return me the coordinates of the diagonal and I could calculate the center and a translation, just like you do it. Of course a boundingbox function can also be implemented to just return the [dx, dy, dz] extents according to the three axes. But this would be the worst way to implement it. Usually it is implemented to return a pair of 3D-points or a box object with an origin and the [dx, dy, dz] extents. -- Sent from: http://forum.openscad.org/