LDraw.org Discussion Forums
Rounding Errors in primitives? - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: General (https://forums.ldraw.org/forum-12.html)
+--- Forum: Official File Specifications/Standards (https://forums.ldraw.org/forum-32.html)
+--- Thread: Rounding Errors in primitives? (/thread-24515.html)

Pages: 1 2 3


RE: Rounding Errors in primitives? - Lasse Deleuran - 2021-04-29

(2021-04-29, 20:54)Magnus Forsberg Wrote: The file claims to be made using PrimGen2, but if I re-create a new version today, I get correct values.

Then it seems like an open and shut case.

I am currently on a MAC without access to PrimGen2. Are you able to generate 1-4ring5.dat and compare it to the official file as well? It also appears to have a mix of computed points. If I compute the primitive in what I believe is the correct way, then I get the point:

5.5434 0 2.2962

such as in the quad:

4 16 6 0 0 5.5434 0 2.2962 4.6195 0 1.9135 5 0 0

which differst from the official file:

4 16 6 0 0 5.5433 0 2.2961 4.6195 0 1.9135 5 0 0

The point should come from scaling the points from the simple primitives. In this case we can take 1-4edge.dat with the point:

0.9239 0 0.3827

Multiply by 6 and you get the "5.5434 0 2.2962" point and not the one in the official file!


Now. If I generate this primitive without regards to the trick, then I get another issue. I get the following quad:

4 16 6 0 0 5.5433 0 2.2961 4.6194 0 1.9134 5 0 0

which ALSO differs from the quad in the official file:

4 16 6 0 0 5.5433 0 2.2961 4.6195 0 1.9135 5 0 0

So how was this primitive generated?


RE: Rounding Errors in primitives? - Travis Cobbs - 2021-04-29

(2021-04-29, 20:54)Magnus Forsberg Wrote: The file claims to be made using PrimGen2, but if I re-create a new version today, I get correct values.

Your screenshot shows both 4.5922 and 4.5924 (the reported problem).


RE: Rounding Errors in primitives? - Magnus Forsberg - 2021-05-02

Your first example show that the official file is not correct.

   

Your second example, is correct compaired to the official file, but your calculation is not.


RE: Rounding Errors in primitives? - Magnus Forsberg - 2021-05-03

How do you want to continue?
A have a set of the 11 mentioned ring and cone prims, ready for recycling.


RE: Rounding Errors in primitives? - Lasse Deleuran - 2021-05-05

(2021-05-03, 15:57)Magnus Forsberg Wrote: How do you want to continue?
A have a set of the 11 mentioned ring and cone prims, ready for recycling.

With official parts I have previously sent an email directly to Chris Dee with the fixed files.


RE: Rounding Errors in primitives? - Lasse Deleuran - 2021-05-05

(2021-05-02, 19:45)Magnus Forsberg Wrote: (...) Your second example, is correct compaired to the official file, but your calculation is not.

I want to learn how to perform the correct calculation, so that my testing framework can include these primitives as well.
Can you please tell me where I am making a wrong assumption below?


1-4ring5.dat consists of quads based on the points from 1-4edge.dat. 

The points in 1-4edge.dat are those of the quarter circle with diameter 1:
1 0 0
0.9239 0 0.3827
0.7071 0 0.7071
0.3827 0 0.9239
0 0 1

1-4ring5.dat spans from the quarter circle of diameter 5 to the quarter circle of diameter 6. It consists of the following points:

5 0 0
4.6195 0 1.9135
3.5355 0 3.5355
1.9135 0 4.6195
0 0 5

6 0 0 
5.5433 0 2.2961 
4.2426 0 4.2426
2.2961 0 5.5433
0 0 6

By scaling the points from 1-4edge.dat with 5 and 6, respectively, we get:

5 0 0 
4.6195 0 1.9135
3.5355 0 3.5355
1.9135 0 4.6195
0 0 5

6 0 0 
5.5434 0 2.2962 
4.2426 0 4.2426
2.2962 0 5.5434 
0 0 6

Which differ from the points in the official file where highlighted.


Calculations done in JS console, by:
'1 0 0 0.9239 0 0.3827 0.7071 0 0.7071 0.3827 0 0.9239 0 0 1'.split(' ').map(x => 5*x).join(' ');
'1 0 0 0.9239 0 0.3827 0.7071 0 0.7071 0.3827 0 0.9239 0 0 1'.split(' ').map(x => 6*x).join(' ');


RE: Rounding Errors in primitives? - Magnus Forsberg - 2021-05-05

(2021-05-05, 8:50)Lasse Deleuran Wrote: I want to learn how to perform the correct calculation, so that my testing framework can include these primitives as well.
Can you please tell me where I am making a wrong assumption below?

I'm sorry, I can't point in any direction.  I don't speak math...

Do you know that PrimGen2 is integrated in LDPE? And LDPE is platform independant, right?


RE: Rounding Errors in primitives? - Travis Cobbs - 2021-05-06

I'm pretty sure that 1-4ring5.dat is wrong.


RE: Rounding Errors in primitives? - Orion Pobursky - 2021-05-06

(2021-05-05, 15:29)Magnus Forsberg Wrote: I'm sorry, I can't point in any direction.  I don't speak math...

Do you know that PrimGen2 is integrated in LDPE? And LDPE is platform independant, right?

LDPE doesn't do any good for the WebGL framework Lasse maintains. He's trying to figure out what the correct way is in order to generate these primitives such that the code framework can validate them correctly (for error checking) and auto-generate them (to save time have to parse and render these files client side).


RE: Rounding Errors in primitives? - Lasse Deleuran - 2021-06-06

(2021-05-06, 18:48)Travis Cobbs Wrote: I'm pretty sure that 1-4ring5.dat is wrong.

But how can we figure out if it is wrong or not? I do not have access to the source code of PrimGen2, and I cannot find any documentation for how the points are computed. 

All I can do for now is to relax the comparisons to allow large errors. 

Not even allowing an error of 0.0001 is sufficient, as 1-4ring7.dat has the following quad:

4 16 8 0 0 7.391 0 3.0614 6.4672 0 2.6788 7 0 0

But using the same computation as mentioned above, I get the following where differences over 0.0001 are highlighted:

4 16 8 0 0 7.3912 0 3.0616 6.4673 0 2.6789 7 0 0




Full transparency. The points of the quad are computed exactly as before by scaling the points of 1-4edge.dat in Javascript:

'1 0 0 0.9239 0 0.3827 0.7071 0 0.7071 0.3827 0 0.9239 0 0 1'.split(' ').map(x => 7*x).join(' ');

'1 0 0 0.9239 0 0.3827 0.7071 0 0.7071 0.3827 0 0.9239 0 0 1'.split(' ').map(x => 8*x).join(' ');