discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Inconsistent conversion of floating number to string at 7th significant digit

MK
Marius Kintel
Sun, Nov 15, 2015 7:51 AM

On Nov 15, 2015, at 02:29 AM, wolf wv99999@gmail.com wrote:

[…] calculate the area of the
triangle to be written, after its vertex vectors have been truncated to
final precision, and if the area is zero, do not write the triangle into the
.stl file.

This isn’t feasible as that would leave a hole in the mesh, making it non-manifold. Try it and see how various software complains about it.

[…] Once code has been put together to allow
creating the cartesian coordinates of each vertex inside OpenSCAD, creating
3D-offset functionality should be trivial, since all that is required is to
erect the normal onto each face, move the face by the required amount along
the normal, and reconnect each face to its neighbours.

This only works for convex objects. Concave objects would cause self-intersections which would have to be resolved. That’s the non-trivial aspects of such a function.

I’m not sure what you’re trying to explain in the rest of your email (it’s getting a bit late here), so I’ll leave that so someone else :)

-Marius

> On Nov 15, 2015, at 02:29 AM, wolf <wv99999@gmail.com> wrote: > > […] calculate the area of the > triangle to be written, *after* its vertex vectors have been truncated to > final precision, and if the area is zero, do not write the triangle into the > .stl file. > This isn’t feasible as that would leave a hole in the mesh, making it non-manifold. Try it and see how various software complains about it. > […] Once code has been put together to allow > creating the cartesian coordinates of each vertex inside OpenSCAD, creating > 3D-offset functionality should be trivial, since all that is required is to > erect the normal onto each face, move the face by the required amount along > the normal, and reconnect each face to its neighbours. > This only works for convex objects. Concave objects would cause self-intersections which would have to be resolved. That’s the non-trivial aspects of such a function. I’m not sure what you’re trying to explain in the rest of your email (it’s getting a bit late here), so I’ll leave that so someone else :) -Marius
R
runsun
Wed, Nov 18, 2015 6:47 PM

After some fine-tuning on the fullnumstr(), it seems to work nicely under
more extensive tests. So at least for now, my lib has a working approach to
show numbers a little more faithfully than built-in str() does:

| fullnumstr ( n [d,dmax] )=str ( tested:60 )
|
| Integer:
|
| 0> fullnumstr(0)= "0"
| 1> fullnumstr(5)= "5"
| 2> fullnumstr(12)= "12"
| 3> fullnumstr(200)= "200"
| 4> fullnumstr(1230)= "1230"
| 5> fullnumstr(123456)= "123456"
| 6> fullnumstr(1234567)= "1234567"
| 7> fullnumstr(123456789)= "123456789"
| 8> fullnumstr(123456000)= "123456000"
| 9> fullnumstr(12345670)= "12345670"
| 10> fullnumstr(123456789012345)= "123456789012345"
| 11> fullnumstr(-123456789012345)= "-123456789012345"
| 12> fullnumstr(12345678901234500)= "12345678901234500"
|
| Float:
|
| 13> fullnumstr(1234.5)= "1234.5"
| 14> fullnumstr(12345.6)= "12345.6"
| 15> fullnumstr(12345.67)= "12345.67"
| 16> fullnumstr(0.12345)= "0.12345"
| 17> fullnumstr(0.12)= "0.12"
| 18> fullnumstr(0.123)= "0.123"
| 19> fullnumstr(0.1234)= "0.1234"
| 20> fullnumstr(0.123456)= "0.123456"
| 21> fullnumstr(0.0000123456)= "0.0000123456"
| 22> fullnumstr( 0.123456789012345)= "0.123456789012345"
| 23> fullnumstr(-0.123456789012345)= "-0.123456789012345"
| 24> fullnumstr(1/3)= "0.333333333333333"
| 25> fullnumstr(2/3)= "0.666666666666667"
| 26> fullnumstr(2/3,d=5)= "0.66667"
|
| Use d and dmax to set digits of fraction:
| // Note the difference between d and dmax.
|
| 27> fullnumstr(5,d=2)= "5.00"
| 28> fullnumstr(-5,d=2)= "-5.00"
| 29> fullnumstr(5,dmax=2)= "5"
| 30> fullnumstr(38,d=0)= "38"
| 31> fullnumstr(38,d=2)= "38.00"
| 32> fullnumstr(80,d=0)= "80"
| 33> fullnumstr(3.80)= "3.8"
| 34> fullnumstr(38.2,dmax=3)= "38.2"
| 35> fullnumstr(38.2,d=3, dmax=2)= "38.20"
| 36> fullnumstr(38.2,d=3, dmax=4)= "38.200"
| 37> fullnumstr(38.2,d=5, dmax=4)= "38.2000"
| 38> fullnumstr(3.839, d=0)= "4"
| 39> fullnumstr(3.839, d=1)= "3.8"
| 40> fullnumstr(3.839, d=2)= "3.84"
| 41> fullnumstr(3.839, d=3)= "3.839"
| 42> fullnumstr(3.839, d=4)= "3.8390"
| 43> fullnumstr(3.839, d=1, dmax=2)= "3.8"
| 44> fullnumstr(3.839, d=2, dmax=2)= "3.84"
| 45> fullnumstr(3.839, d=3, dmax=2)= "3.84"
| 46> fullnumstr(3.839, d=4, dmax=2)= "3.84"
| 47> fullnumstr(43.839, d=4, dmax=2)= "43.84"
| 48> fullnumstr(-3.839, d=1)= "-3.8"
| 49> fullnumstr(-3.839, d=2)= "-3.84"
| 50> fullnumstr(-3.839, d=4)= "-3.8390"
|
| 51> fullnumstr(0.123456789012345,d=6)= "0.123457"
| 52> fullnumstr(0.123456789012345,d=7)= "0.1234568"
| 53> fullnumstr(0.123456789012345,d=8)= "0.12345679"
| 54> fullnumstr(0.123456789012345,d=9)= "0.123456789"
| 55> fullnumstr(800.1,d=0)= "800"
| 56> fullnumstr(800.01,d=0)= "800"
| 57> fullnumstr(800.01,d=1)= "800.0"
| 58> fullnumstr(800000000000.01,d=1)= "800000000000.0"
| 59> fullnumstr(79.516556302228700,d=0)= "80"


$  Runsun Pan, PhD

$ libs:

doctest ,

faces ( git ),

offline doc ( git ),

runscad.py( 1 , 2 , git );

$ tips:

hash( 1 , 2 ),

sweep ,

var( 1 , 2 ),

lerp ,

animGif ,

precision

--
View this message in context: http://forum.openscad.org/Inconsistent-conversion-of-floating-number-to-string-at-7th-significant-digit-tp14350p14625.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

After some fine-tuning on the *fullnumstr()*, it seems to work nicely under more extensive tests. So at least for now, my lib has a working approach to show numbers a little more faithfully than built-in str() does: | fullnumstr ( n [d,dmax] )=str ( tested:60 ) | | Integer: | | 0> fullnumstr(0)= "0" | 1> fullnumstr(5)= "5" | 2> fullnumstr(12)= "12" | 3> fullnumstr(200)= "200" | 4> fullnumstr(1230)= "1230" | 5> fullnumstr(123456)= "123456" | 6> fullnumstr(1234567)= "1234567" | 7> fullnumstr(123456789)= "123456789" | 8> fullnumstr(123456000)= "123456000" | 9> fullnumstr(12345670)= "12345670" | 10> fullnumstr(123456789012345)= "123456789012345" | 11> fullnumstr(-123456789012345)= "-123456789012345" | 12> fullnumstr(12345678901234500)= "12345678901234500" | | Float: | | 13> fullnumstr(1234.5)= "1234.5" | 14> fullnumstr(12345.6)= "12345.6" | 15> fullnumstr(12345.67)= "12345.67" | 16> fullnumstr(0.12345)= "0.12345" | 17> fullnumstr(0.12)= "0.12" | 18> fullnumstr(0.123)= "0.123" | 19> fullnumstr(0.1234)= "0.1234" | 20> fullnumstr(0.123456)= "0.123456" | 21> fullnumstr(0.0000123456)= "0.0000123456" | 22> fullnumstr( 0.123456789012345)= "0.123456789012345" | 23> fullnumstr(-0.123456789012345)= "-0.123456789012345" | 24> fullnumstr(1/3)= "0.333333333333333" | 25> fullnumstr(2/3)= "0.666666666666667" | 26> fullnumstr(2/3,d=5)= "0.66667" | | Use d and dmax to set digits of fraction: | // Note the difference between d and dmax. | | 27> fullnumstr(5,d=2)= "5.00" | 28> fullnumstr(-5,d=2)= "-5.00" | 29> fullnumstr(5,dmax=2)= "5" | 30> fullnumstr(38,d=0)= "38" | 31> fullnumstr(38,d=2)= "38.00" | 32> fullnumstr(80,d=0)= "80" | 33> fullnumstr(3.80)= "3.8" | 34> fullnumstr(38.2,dmax=3)= "38.2" | 35> fullnumstr(38.2,d=3, dmax=2)= "38.20" | 36> fullnumstr(38.2,d=3, dmax=4)= "38.200" | 37> fullnumstr(38.2,d=5, dmax=4)= "38.2000" | 38> fullnumstr(3.839, d=0)= "4" | 39> fullnumstr(3.839, d=1)= "3.8" | 40> fullnumstr(3.839, d=2)= "3.84" | 41> fullnumstr(3.839, d=3)= "3.839" | 42> fullnumstr(3.839, d=4)= "3.8390" | 43> fullnumstr(3.839, d=1, dmax=2)= "3.8" | 44> fullnumstr(3.839, d=2, dmax=2)= "3.84" | 45> fullnumstr(3.839, d=3, dmax=2)= "3.84" | 46> fullnumstr(3.839, d=4, dmax=2)= "3.84" | 47> fullnumstr(43.839, d=4, dmax=2)= "43.84" | 48> fullnumstr(-3.839, d=1)= "-3.8" | 49> fullnumstr(-3.839, d=2)= "-3.84" | 50> fullnumstr(-3.839, d=4)= "-3.8390" | | 51> fullnumstr(0.123456789012345,d=6)= "0.123457" | 52> fullnumstr(0.123456789012345,d=7)= "0.1234568" | 53> fullnumstr(0.123456789012345,d=8)= "0.12345679" | 54> fullnumstr(0.123456789012345,d=9)= "0.123456789" | 55> fullnumstr(800.1,d=0)= "800" | 56> fullnumstr(800.01,d=0)= "800" | 57> fullnumstr(800.01,d=1)= "800.0" | 58> fullnumstr(800000000000.01,d=1)= "800000000000.0" | 59> fullnumstr(79.516556302228700,d=0)= "80" ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py( 1 , 2 , git ); $ tips: hash( 1 , 2 ), sweep , var( 1 , 2 ), lerp , animGif , precision -- View this message in context: http://forum.openscad.org/Inconsistent-conversion-of-floating-number-to-string-at-7th-significant-digit-tp14350p14625.html Sent from the OpenSCAD mailing list archive at Nabble.com.
TH
Triffid Hunter
Thu, Dec 31, 2015 9:42 AM

On 15 November 2015 at 15:51, Marius Kintel marius@kintel.net wrote:

On Nov 15, 2015, at 02:29 AM, wolf wv99999@gmail.com wrote:

[…] calculate the area of the
triangle to be written, after its vertex vectors have been truncated to
final precision, and if the area is zero, do not write the triangle into

the

.stl file.

This isn’t feasible as that would leave a hole in the mesh, making it
non-manifold. Try it and see how various software complains about it.

How would removing a zero-area triangle leave a non-zero-area hole?

On 15 November 2015 at 15:51, Marius Kintel <marius@kintel.net> wrote: > > On Nov 15, 2015, at 02:29 AM, wolf <wv99999@gmail.com> wrote: > > > > […] calculate the area of the > > triangle to be written, *after* its vertex vectors have been truncated to > > final precision, and if the area is zero, do not write the triangle into > the > > .stl file. > > > This isn’t feasible as that would leave a hole in the mesh, making it > non-manifold. Try it and see how various software complains about it. > How would removing a zero-area triangle leave a non-zero-area hole?
NH
nop head
Thu, Dec 31, 2015 9:55 AM

You most likely end up with a vertex meeting an edge whereas vertices
should always meet other vertices. The zero area triangle can have non zero
length.

On 31 December 2015 at 09:42, Triffid Hunter triffid.hunter@gmail.com
wrote:

On 15 November 2015 at 15:51, Marius Kintel marius@kintel.net wrote:

On Nov 15, 2015, at 02:29 AM, wolf wv99999@gmail.com wrote:

[…] calculate the area of the
triangle to be written, after its vertex vectors have been truncated

to

final precision, and if the area is zero, do not write the triangle

into the

.stl file.

This isn’t feasible as that would leave a hole in the mesh, making it
non-manifold. Try it and see how various software complains about it.

How would removing a zero-area triangle leave a non-zero-area hole?


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

You most likely end up with a vertex meeting an edge whereas vertices should always meet other vertices. The zero area triangle can have non zero length. On 31 December 2015 at 09:42, Triffid Hunter <triffid.hunter@gmail.com> wrote: > On 15 November 2015 at 15:51, Marius Kintel <marius@kintel.net> wrote: > >> > On Nov 15, 2015, at 02:29 AM, wolf <wv99999@gmail.com> wrote: >> > >> > […] calculate the area of the >> > triangle to be written, *after* its vertex vectors have been truncated >> to >> > final precision, and if the area is zero, do not write the triangle >> into the >> > .stl file. >> > >> This isn’t feasible as that would leave a hole in the mesh, making it >> non-manifold. Try it and see how various software complains about it. >> > > How would removing a zero-area triangle leave a non-zero-area hole? > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
NH
nop head
Thu, Dec 31, 2015 9:56 AM

You do end up with a zero area hole, but it is still topologically a hole.

On 31 December 2015 at 09:55, nop head nop.head@gmail.com wrote:

You most likely end up with a vertex meeting an edge whereas vertices
should always meet other vertices. The zero area triangle can have non zero
length.

On 31 December 2015 at 09:42, Triffid Hunter triffid.hunter@gmail.com
wrote:

On 15 November 2015 at 15:51, Marius Kintel marius@kintel.net wrote:

On Nov 15, 2015, at 02:29 AM, wolf wv99999@gmail.com wrote:

[…] calculate the area of the
triangle to be written, after its vertex vectors have been truncated

to

final precision, and if the area is zero, do not write the triangle

into the

.stl file.

This isn’t feasible as that would leave a hole in the mesh, making it
non-manifold. Try it and see how various software complains about it.

How would removing a zero-area triangle leave a non-zero-area hole?


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

You do end up with a zero area hole, but it is still topologically a hole. On 31 December 2015 at 09:55, nop head <nop.head@gmail.com> wrote: > You most likely end up with a vertex meeting an edge whereas vertices > should always meet other vertices. The zero area triangle can have non zero > length. > > On 31 December 2015 at 09:42, Triffid Hunter <triffid.hunter@gmail.com> > wrote: > >> On 15 November 2015 at 15:51, Marius Kintel <marius@kintel.net> wrote: >> >>> > On Nov 15, 2015, at 02:29 AM, wolf <wv99999@gmail.com> wrote: >>> > >>> > […] calculate the area of the >>> > triangle to be written, *after* its vertex vectors have been truncated >>> to >>> > final precision, and if the area is zero, do not write the triangle >>> into the >>> > .stl file. >>> > >>> This isn’t feasible as that would leave a hole in the mesh, making it >>> non-manifold. Try it and see how various software complains about it. >>> >> >> How would removing a zero-area triangle leave a non-zero-area hole? >> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >