discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Problem using difference() with linear_extrude()

RW
Rogier Wolff
Tue, Aug 18, 2020 9:56 PM

On Tue, Aug 18, 2020 at 05:04:15PM +0100, nop head wrote:

Well everything is jagged in OpenSCAD, there are no curves. The twisted
shape has facets made of two triangles at an angle, that give it a rippled
surface. If you zoom you can see the ripples and that gives the jagged edge
when subtracted.

WELL......

For example this:

difference () {
linear_extrude (height=10, twist=360, convexity = 10,$fn=20)
square ([10,10]);
translate ([0,0,-1]) cube (14.2);
}

clearly shows a jagged edge near the Z-axis. (those elswhere: I
haven't investigated)

Now, normally with say "cylinder" or "sphere" you can increase $fn
and get the model to match more closely to the expected mathematical
shape. Here you can increase $fn too and.... That doesn't help.

The issue is that the inside edge of the square (the edge that starts
out on the X axis.) is multiplied into two triangles at each
slice. Both of these triangles are "skinny". One has a base (smallest
edge) near the Z axis of about 10mm/$fn and the other is a triangle
with base 2pi10mm.

The first triangle is completely vertical. The other is at an angle of
about atan (1/(2*pi)) . So these meet at an angle close to 90 degrees.

It doesn't matter how fine you make the slices: These triangles keep
meeting at that angle.

When you approximate a sphere with more and more triangular patches,
the angle between the patches approaches: "flat". So the curved nature
of the object is better approximated the more triangles you use. But
here increasing the number of triangles does not help.

IMHO, an extra $fa or something should be added to
linear_extrude. When the angle between such a pair of triangles
exceeds $fa, then the triangles should be split.until the angles
become less than $fa.

So in my example, the first, half-way split would give us FOUR
triangles, One of them still vertical on the Z axis, but now
the other triangle touching the Z axis with its tip is already
at atan (1/pi) a much bigger angle, closer to vertical...

If in my example, you replace the square with this almost-square:

polygon ([[0,0], [10,0],[10,10], [0,10], [0.001,5],[0.0011,2.5],[0.001,1.25], [0.0011,0.625]   ]);

the desired mathematical shape is already approximated a lot more
closely. it would be useful and "complete" for the openscad language
if the language would support something that allows a user to specify
how accurate to approximate the mathematical object. (Note that i've
fixed one side, not the other, so you can compare the results in one
object.).

When you move the square a bit to the -x direction, you'll get much
more pronounced spikes that the TS is also seeing.

These artefacts make some objects difficult to 3D print. They also end
up having a lousy fit...

Roger. 

There is nothing wrong with difference().

On Tue, 18 Aug 2020 at 16:35, jamcultur nyponen@gmail.com wrote:

I tried increasing slices to 100 and 200. There are no inside out bits, but
the edges are still jagged which they shouldn't be. You can see it when you
zoom in.

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


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

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.

On Tue, Aug 18, 2020 at 05:04:15PM +0100, nop head wrote: > Well everything is jagged in OpenSCAD, there are no curves. The twisted > shape has facets made of two triangles at an angle, that give it a rippled > surface. If you zoom you can see the ripples and that gives the jagged edge > when subtracted. WELL...... For example this: difference () { linear_extrude (height=10, twist=360, convexity = 10,$fn=20) square ([10,10]); translate ([0,0,-1]) cube (14.2); } clearly shows a jagged edge near the Z-axis. (those elswhere: I haven't investigated) Now, normally with say "cylinder" or "sphere" you can increase $fn and get the model to match more closely to the expected mathematical shape. Here you can increase $fn too and.... That doesn't help. The issue is that the inside edge of the square (the edge that starts out on the X axis.) is multiplied into two triangles at each slice. Both of these triangles are "skinny". One has a base (smallest edge) near the Z axis of about 10mm/$fn and the other is a triangle with base 2*pi*10mm. The first triangle is completely vertical. The other is at an angle of about atan (1/(2*pi)) . So these meet at an angle close to 90 degrees. It doesn't matter how fine you make the slices: These triangles keep meeting at that angle. When you approximate a sphere with more and more triangular patches, the angle between the patches approaches: "flat". So the curved nature of the object is better approximated the more triangles you use. But here increasing the number of triangles does not help. IMHO, an extra $fa or something should be added to linear_extrude. When the angle between such a pair of triangles exceeds $fa, then the triangles should be split.until the angles become less than $fa. So in my example, the first, half-way split would give us FOUR triangles, One of them still vertical on the Z axis, but now the other triangle touching the Z axis with its tip is already at atan (1/pi) a much bigger angle, closer to vertical... If in my example, you replace the square with this almost-square: polygon ([[0,0], [10,0],[10,10], [0,10], [0.001,5],[0.0011,2.5],[0.001,1.25], [0.0011,0.625] ]); the desired mathematical shape is already approximated a lot more closely. it would be useful and "complete" for the openscad language if the language would support something that allows a user to specify how accurate to approximate the mathematical object. (Note that i've fixed one side, not the other, so you can compare the results in one object.). When you move the square a bit to the -x direction, you'll get much more pronounced spikes that the TS is also seeing. These artefacts make some objects difficult to 3D print. They also end up having a lousy fit... Roger. > > There is nothing wrong with difference(). > > On Tue, 18 Aug 2020 at 16:35, jamcultur <nyponen@gmail.com> wrote: > > > I tried increasing slices to 100 and 200. There are no inside out bits, but > > the edges are still jagged which they shouldn't be. You can see it when you > > zoom in. > > > > > > > > -- > > 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 -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ** ** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 ** The plan was simple, like my brother-in-law Phil. But unlike Phil, this plan just might work.
RW
Rob Ward
Tue, Aug 18, 2020 11:27 PM

Excellent research (even if I am away from my machine, and find it very hard to follow without trying it) and a very patient reply.
Cheers, RobW

On 19 August 2020 7:56:43 am AEST, Rogier Wolff R.E.Wolff@BitWizard.nl wrote:

On Tue, Aug 18, 2020 at 05:04:15PM +0100, nop head wrote:

Well everything is jagged in OpenSCAD, there are no curves. The

twisted

shape has facets made of two triangles at an angle, that give it a

rippled

surface. If you zoom you can see the ripples and that gives the

jagged edge

when subtracted.

WELL......

For example this:

difference () {
linear_extrude (height=10, twist=360, convexity = 10,$fn=20)
square ([10,10]);
translate ([0,0,-1]) cube (14.2);
}

clearly shows a jagged edge near the Z-axis. (those elswhere: I
haven't investigated)

Now, normally with say "cylinder" or "sphere" you can increase $fn
and get the model to match more closely to the expected mathematical
shape. Here you can increase $fn too and.... That doesn't help.

The issue is that the inside edge of the square (the edge that starts
out on the X axis.) is multiplied into two triangles at each
slice. Both of these triangles are "skinny". One has a base (smallest
edge) near the Z axis of about 10mm/$fn and the other is a triangle
with base 2pi10mm.

The first triangle is completely vertical. The other is at an angle of
about atan (1/(2*pi)) . So these meet at an angle close to 90 degrees.

It doesn't matter how fine you make the slices: These triangles keep
meeting at that angle.

When you approximate a sphere with more and more triangular patches,
the angle between the patches approaches: "flat". So the curved nature
of the object is better approximated the more triangles you use. But
here increasing the number of triangles does not help.

IMHO, an extra $fa or something should be added to
linear_extrude. When the angle between such a pair of triangles
exceeds $fa, then the triangles should be split.until the angles
become less than $fa.

So in my example, the first, half-way split would give us FOUR
triangles, One of them still vertical on the Z axis, but now
the other triangle touching the Z axis with its tip is already
at atan (1/pi) a much bigger angle, closer to vertical...

If in my example, you replace the square with this almost-square:

polygon ([[0,0], [10,0],[10,10], [0,10],
[0.001,5],[0.0011,2.5],[0.001,1.25], [0.0011,0.625]  ]);

the desired mathematical shape is already approximated a lot more
closely. it would be useful and "complete" for the openscad language
if the language would support something that allows a user to specify
how accurate to approximate the mathematical object. (Note that i've
fixed one side, not the other, so you can compare the results in one
object.).

When you move the square a bit to the -x direction, you'll get much
more pronounced spikes that the TS is also seeing.

These artefacts make some objects difficult to 3D print. They also end
up having a lousy fit...

Roger. 

There is nothing wrong with difference().

On Tue, 18 Aug 2020 at 16:35, jamcultur nyponen@gmail.com wrote:

I tried increasing slices to 100 and 200. There are no inside out

bits, but

the edges are still jagged which they shouldn't be. You can see it

when you

zoom in.

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


OpenSCAD mailing list
Discuss@lists.openscad.org

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ **
+31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233
**
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.


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

Excellent research (even if I am away from my machine, and find it very hard to follow without trying it) and a very patient reply. Cheers, RobW On 19 August 2020 7:56:43 am AEST, Rogier Wolff <R.E.Wolff@BitWizard.nl> wrote: >On Tue, Aug 18, 2020 at 05:04:15PM +0100, nop head wrote: >> Well everything is jagged in OpenSCAD, there are no curves. The >twisted >> shape has facets made of two triangles at an angle, that give it a >rippled >> surface. If you zoom you can see the ripples and that gives the >jagged edge >> when subtracted. > >WELL...... > > >For example this: > >difference () { > linear_extrude (height=10, twist=360, convexity = 10,$fn=20) > square ([10,10]); > translate ([0,0,-1]) cube (14.2); >} > >clearly shows a jagged edge near the Z-axis. (those elswhere: I >haven't investigated) > >Now, normally with say "cylinder" or "sphere" you can increase $fn >and get the model to match more closely to the expected mathematical >shape. Here you can increase $fn too and.... That doesn't help. > >The issue is that the inside edge of the square (the edge that starts >out on the X axis.) is multiplied into two triangles at each >slice. Both of these triangles are "skinny". One has a base (smallest >edge) near the Z axis of about 10mm/$fn and the other is a triangle >with base 2*pi*10mm. > >The first triangle is completely vertical. The other is at an angle of >about atan (1/(2*pi)) . So these meet at an angle close to 90 degrees. > >It doesn't matter how fine you make the slices: These triangles keep >meeting at that angle. > >When you approximate a sphere with more and more triangular patches, >the angle between the patches approaches: "flat". So the curved nature >of the object is better approximated the more triangles you use. But >here increasing the number of triangles does not help. > >IMHO, an extra $fa or something should be added to >linear_extrude. When the angle between such a pair of triangles >exceeds $fa, then the triangles should be split.until the angles >become less than $fa. > >So in my example, the first, half-way split would give us FOUR >triangles, One of them still vertical on the Z axis, but now >the other triangle touching the Z axis with its tip is already >at atan (1/pi) a much bigger angle, closer to vertical... > >If in my example, you replace the square with this almost-square: > >polygon ([[0,0], [10,0],[10,10], [0,10], >[0.001,5],[0.0011,2.5],[0.001,1.25], [0.0011,0.625] ]); > >the desired mathematical shape is already approximated a lot more >closely. it would be useful and "complete" for the openscad language >if the language would support something that allows a user to specify >how accurate to approximate the mathematical object. (Note that i've >fixed one side, not the other, so you can compare the results in one >object.). > >When you move the square a bit to the -x direction, you'll get much >more pronounced spikes that the TS is also seeing. > >These artefacts make some objects difficult to 3D print. They also end >up having a lousy fit... > > > Roger. > > >> >> There is nothing wrong with difference(). >> >> On Tue, 18 Aug 2020 at 16:35, jamcultur <nyponen@gmail.com> wrote: >> >> > I tried increasing slices to 100 and 200. There are no inside out >bits, but >> > the edges are still jagged which they shouldn't be. You can see it >when you >> > zoom in. >> > >> > >> > >> > -- >> > 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 > > >-- >** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** >+31-15-2049110 ** >** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 > ** >The plan was simple, like my brother-in-law Phil. But unlike >Phil, this plan just might work. > >_______________________________________________ >OpenSCAD mailing list >Discuss@lists.openscad.org >http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
HL
Hans L
Wed, Aug 19, 2020 2:40 AM

Since its come up before, I decided to open an issue on github regarding
how to fix these jagged edges (without requiring user workarounds):
https://github.com/openscad/openscad/issues/3411

On Tue, Aug 18, 2020 at 6:28 PM Rob Ward rl.ward@bigpond.com wrote:

Excellent research (even if I am away from my machine, and find it very
hard to follow without trying it) and a very patient reply.
Cheers, RobW

On 19 August 2020 7:56:43 am AEST, Rogier Wolff R.E.Wolff@BitWizard.nl
wrote:

On Tue, Aug 18, 2020 at 05:04:15PM +0100, nop head wrote:

Well everything is jagged in OpenSCAD, there are no curves. The twisted
shape has facets made of two triangles at an angle, that give it a rippled
surface. If you zoom you can see the ripples and that gives the jagged edge
when subtracted.

WELL......

For example this:

difference () {
linear_extrude (height=10, twist=360, convexity = 10,$fn=20)
square ([10,10]);
translate ([0,0,-1]) cube (14.2);
}

clearly shows a jagged edge near the Z-axis. (those elswhere: I
haven't investigated)

Now, normally with say "cylinder" or "sphere" you can increase $fn
and get the model to match more closely to the expected mathematical
shape. Here you can increase $fn too and.... That doesn't help.

The issue is that the inside edge of the square (the edge that starts
out on the X axis.) is multiplied into two triangles at each
slice. Both of these triangles are "skinny". One has a base (smallest
edge) near the Z axis of about 10mm/$fn and the other is a triangle
with base 2pi10mm.

The first triangle is completely vertical. The other is at an angle of
about atan (1/(2*pi)) . So these meet at an angle close to 90 degrees.

It doesn't matter how fine you make the slices: These triangles keep
meeting at that angle.

When you approximate a sphere with more and more triangular patches,
the angle between the patches approaches: "flat". So the curved nature
of the object is better approximated the more triangles you use. But
here increasing the number of triangles does not help.

IMHO, an extra $fa or something should be added to
linear_extrude. When the angle between such a pair of triangles
exceeds $fa, then the triangles should be split.until the angles
become less than $fa.

So in my example, the first, half-way split would give us FOUR
triangles, One of them still vertical on the Z axis, but now
the other triangle touching the Z axis with its tip is already
at atan (1/pi) a much bigger angle, closer to vertical...

If in my example, you replace the square with this almost-square:

 polygon ([[0,0], [10,0],[10,10], [0,10], [0.001,5],[0.0011,2.5],[0.001,1.25], [0.0011,0.625]   ]);

the desired mathematical shape is already approximated a lot more
closely. it would be useful and "complete" for the openscad language
if the language would support something that allows a user to specify
how accurate to approximate the mathematical object. (Note that i've
fixed one side, not the other, so you can compare the results in one
object.).

When you move the square a bit to the -x direction, you'll get much
more pronounced spikes that the TS is also seeing.

These artefacts make some objects difficult to 3D print. They also end
up having a lousy fit...

Roger.

There is nothing wrong with difference().

On Tue, 18 Aug 2020 at 16:35, jamcultur nyponen@gmail.com wrote:

I tried increasing slices to 100 and 200. There are no inside out bits, but

the edges are still jagged which they shouldn't be. You can see it when you
zoom in.

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

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



Since its come up before, I decided to open an issue on github regarding how to fix these jagged edges (without requiring user workarounds): https://github.com/openscad/openscad/issues/3411 On Tue, Aug 18, 2020 at 6:28 PM Rob Ward <rl.ward@bigpond.com> wrote: > Excellent research (even if I am away from my machine, and find it very > hard to follow without trying it) and a very patient reply. > Cheers, RobW > > On 19 August 2020 7:56:43 am AEST, Rogier Wolff <R.E.Wolff@BitWizard.nl> > wrote: >> >> On Tue, Aug 18, 2020 at 05:04:15PM +0100, nop head wrote: >> >>> Well everything is jagged in OpenSCAD, there are no curves. The twisted >>> shape has facets made of two triangles at an angle, that give it a rippled >>> surface. If you zoom you can see the ripples and that gives the jagged edge >>> when subtracted. >>> >> >> WELL...... >> >> >> For example this: >> >> difference () { >> linear_extrude (height=10, twist=360, convexity = 10,$fn=20) >> square ([10,10]); >> translate ([0,0,-1]) cube (14.2); >> } >> >> clearly shows a jagged edge near the Z-axis. (those elswhere: I >> haven't investigated) >> >> Now, normally with say "cylinder" or "sphere" you can increase $fn >> and get the model to match more closely to the expected mathematical >> shape. Here you can increase $fn too and.... That doesn't help. >> >> The issue is that the inside edge of the square (the edge that starts >> out on the X axis.) is multiplied into two triangles at each >> slice. Both of these triangles are "skinny". One has a base (smallest >> edge) near the Z axis of about 10mm/$fn and the other is a triangle >> with base 2*pi*10mm. >> >> The first triangle is completely vertical. The other is at an angle of >> about atan (1/(2*pi)) . So these meet at an angle close to 90 degrees. >> >> It doesn't matter how fine you make the slices: These triangles keep >> meeting at that angle. >> >> When you approximate a sphere with more and more triangular patches, >> the angle between the patches approaches: "flat". So the curved nature >> of the object is better approximated the more triangles you use. But >> here increasing the number of triangles does not help. >> >> IMHO, an extra $fa or something should be added to >> linear_extrude. When the angle between such a pair of triangles >> exceeds $fa, then the triangles should be split.until the angles >> become less than $fa. >> >> So in my example, the first, half-way split would give us FOUR >> triangles, One of them still vertical on the Z axis, but now >> the other triangle touching the Z axis with its tip is already >> at atan (1/pi) a much bigger angle, closer to vertical... >> >> If in my example, you replace the square with this almost-square: >> >> polygon ([[0,0], [10,0],[10,10], [0,10], [0.001,5],[0.0011,2.5],[0.001,1.25], [0.0011,0.625] ]); >> >> the desired mathematical shape is already approximated a lot more >> closely. it would be useful and "complete" for the openscad language >> if the language would support something that allows a user to specify >> how accurate to approximate the mathematical object. (Note that i've >> fixed one side, not the other, so you can compare the results in one >> object.). >> >> When you move the square a bit to the -x direction, you'll get much >> more pronounced spikes that the TS is also seeing. >> >> These artefacts make some objects difficult to 3D print. They also end >> up having a lousy fit... >> >> >> Roger. >> >> >> >>> There is nothing wrong with difference(). >>> >>> On Tue, 18 Aug 2020 at 16:35, jamcultur <nyponen@gmail.com> wrote: >>> >>> I tried increasing slices to 100 and 200. There are no inside out bits, but >>>> the edges are still jagged which they shouldn't be. You can see it when you >>>> zoom in. >>>> >>>> >>>> >>>> -- >>>> 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 >>> >> >> _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >