wo80 / Triangle.NET

C# / .NET version of Jonathan Shewchuk's Triangle mesh generator.
463 stars 85 forks source link

Ran out of precision" error when enforcing max edge length #13

Closed mludlum closed 2 years ago

mludlum commented 4 years ago

I'm trying to enforce a max edge length in order to avoid unwanted mesh connections. Is there an easy way to do this? For example, imaging a survey of points along a river that winds. I don't want the contours of the river to be connected into one large blob. I've used another triangulation library that allows max leg length as a parameter, but this library is faster.

I'm using the UserTest callback. When I use the following code, I keep gettng the "Ran out of precision" error. I'm setting maxLegLength to 200 for testing.

            Func <ITriangle, double, bool> myTriTest = delegate (ITriangle tri, double area)
            {
                DPoint p1 = ToVector3(tri.GetVertex(0)), p2 = ToVector3(tri.GetVertex(1)),
                    p3 = ToVector3(tri.GetVertex(2));
                DLine line;
                line = new DLine();
                if (p1.XYDistanceFrom(p2) > maxLegLength)
                    return true;
                else if (p2.XYDistanceFrom(p3) > maxLegLength)
                    return true;
                else if (p3.XYDistanceFrom(p1) > maxLegLength)
                    return true;
                else
                    return false;
            };

            quality.UserTest = myTriTest;
wo80 commented 2 years ago

This should work in general, see Triangle.Examples Example7.cs

I'm closing this one with #16

If you want to discuss this further, please re-open and provide a minimal example that fails (geometry setup and triangulation options).