LDraw.org Discussion Forums

Full Version: Rounding bug in PrimGen2?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hej,
I think, I found a rounding problem in PrimGen2.
I'll continue to check all primitives for rounding errors, correct file ending and add a "generated with primgen" comment, when comparison is successful or the file is regenerated.
Please see these lines:
Code:
0 Cone 15 x 0.25
0 Name: 1-4con15.dat
0 Author: Max Martin Richter [MMR1988]
0 !LDRAW_ORG Unofficial_Primitive
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt

0 BFC CERTIFY CCW

4 16 15 1 0 [color=#FF0000]13.8585 1 5.7405[/color] 14.7824 0 6.1232 16 0 0
4 16 13.8585 1 5.7405 10.6065 1 10.6065 11.3136 0 11.3136 14.7824 0 6.1232
4 16 10.6065 1 10.6065 [color=#FF00CC]5.7405 1 13.8585[/color] 6.1232 0 14.7824 11.3136 0 11.3136
4 16 5.7405 1 13.8585 0 1 15 0 0 16 6.1232 0 14.7824
0 // conditional lines
5 24 15 1 0 16 0 0 15 1 -6.2132 [color=#FF0000]13.8582 1 5.7403[/color]
5 24 13.8585 1 5.7405 14.7824 0 6.1232 15 1 0 10.6066 1 10.6066
5 24 10.6065 1 10.6065 11.3136 0 11.3136 13.8582 1 5.7403 [color=#FF00CC]5.7403 1 13.8582[/color]
5 24 5.7405 1 13.8585 6.1232 0 14.7824 10.6066 1 10.6066 0 1 15
5 24 0 1 15 0 0 16 5.7403 1 13.8582 -6.2132 1 15
0 // Build by Primitive Generator 2

This problem seem to exist for cones only...

/Max
Indeed, problem lies in condlines values that are not rounded properly. The algorithm to get proper values for cones is
sine(angle) rounded to 4 decimal places, multiplied by radius. This is done properly for quads, but condlines use sine(angle) multiplied by radius, rounded to 4dp. The rounding scheme may seem weird at first sight, but it ensures a perfect match with edges/discs that have a unit size, are rounded to 4dp and scaled to size when used.
After thinking over this problem again I would suggest the following solution:
Change the calculation algorithm of the condline values to the algorithm of the quads values. This will not cause in hairline gaps for parts and changing the condlines will not result in any problems for the existing parts.

/Max
Yes, that's correct - round first, then multiply by radius.
Are these lines better:
0 Name: 1-4con15.dat
0 Author: Michael Heidemann [mikeheide]
0 !LDRAW_ORG Unofficial_Primitive
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt

0 BFC CERTIFY CCW

4 16 15 1 0 13.8585 1 5.7405 14.7824 0 6.1232 16 0 0
4 16 13.8585 1 5.7405 10.6065 1 10.6065 11.3136 0 11.3136 14.7824 0 6.1232
4 16 10.6065 1 10.6065 5.7405 1 13.8585 6.1232 0 14.7824 11.3136 0 11.3136
4 16 5.7405 1 13.8585 0 1 15 0 0 16 6.1232 0 14.7824
0 // conditional lines
5 24 15 1 0 16 0 0 15 1 -6.213 13.8585 1 5.7405
5 24 13.8585 1 5.7405 14.7824 0 6.1232 15 1 0 10.6065 1 10.6065
5 24 10.6065 1 10.6065 11.3136 0 11.3136 13.8585 1 5.7405 5.7405 1 13.8585
5 24 5.7405 1 13.8585 6.1232 0 14.7824 10.6065 1 10.6065 0 1 15
5 24 0 1 15 0 0 16 5.7405 1 13.8585 -6.213 1 15
0 // Build by Primitive Generator 2

I had indeed forgot to use the rounding for the third and fourth vertice on optional lines. Sorry!
Yes, this seems to work.
Do you prepare an update of PrimGen?

/Max
Now, after I got a proof that my bugfix is correct - YES. Maybe tomorrow. Wink
Now since it only affect control points to less than the 3rd dp, the effect is completely unnoticeable!!!
Yes, it is. But it is weird to have different values for the control points than for the quads.
/Max
The new version is online at http://ldraw.heidemann.org/index.php?page=primgen2

Have fun Smile
Pages: 1 2