NMO13 / earclipper

3D triangulation library
MIT License
71 stars 13 forks source link

Coplanar Mapping chooses incorrect normal vector #11

Open SamuelReithmeir opened 1 month ago

SamuelReithmeir commented 1 month ago

When applying coplanar mapping to this input:

2027.9122314453125 40 2.3806018829345703 2024.5794677734375 40 99.70745086669922 2022.4283447265625 40 162.5243682861328 2022.4283447265625 140 162.5243682861328 2024.6356201171875 140 98.06507873535156 2024.6033935546875 68 99.00758361816406 2027.9937744140625 68 0 2027.979736328125 40 0.4065830111503601 image

i get this result: 2027.9122314453125 40 2.3806018829345703 2024.5794677734375 40 99.70745086669922 2022.4283447265625 40 162.5243682861328 2022.4283447265625 40 162.5243682861328 2024.6356201171875 40 98.06507873535156 2024.6033935546875 40 99.00758361816406 2027.9937744140625 40 0 2027.979736328125 40 0.4065830111503601

image

the current implementation chooses the wrong normal vector for creating the coplanar mapping which results in a wrong polygon.

the problem is the approach of using a "dominant" normal, as this is prone to floating point accuracy. In this example "correct" normals are slightly different from each other, but the totaly wrong one appears twice which creates a mapping that maps the points on one line.

SamuelReithmeir commented 1 month ago

fixed by #12