gwlucastrig / Tinfour

Delaunay and Constrained Delaunay Triangulations in Java, providing high-performance utilities for modeling surfaces with support for Lidar LAS files, Digital Elevation Models (DEM), finite element analysis, path planning, natural neighbor interpolation, and other applications of Triangulated Irregular Networks (TIN)
Apache License 2.0
153 stars 34 forks source link

Expose SimpleTriangle Circumcircle #59

Closed micycle1 closed 3 years ago

micycle1 commented 3 years ago

I'm guessing that circumcircles are calcuated for triangles during triangulation.

If this is so, can a SimpleTriangle have members (center point and radius) that expose its pre-calculated circumcircle? So I as a user don't have to re-calcuate the circumcircle using triangle's vertices afterwards, thus saving on total compute.

gwlucastrig commented 3 years ago

Because the structure of the Incremental TIN changes constantly as vertices are inserted into the mesh, the circumcircles are computed as needed and quickly discarded. Keep in mind that Tinfour is designed to handle millions of vertices, so storage space is at a premium. Similarly, there was a motivation to keep SimpleTriangle as lightweight as possible.

The GeometricOperations class has a utility for computing circumcircles. It automatically switches to extended precision when the triangles get too "flat". That being said, I really ought to include a circumcircle computation as part of the SimpleTriangle API. In fact, adding an additional member element to the class won't even increase its size in memory. In Java, all objects must be a multiple of 8 in size, right now SimpleTriangle is 28 bytes in size, but Java pads it out to be 32... so adding an additional 4-byte object reference for the circumcircle would not change the amount of memory required for the class.

Thanks for the suggestion. I'll add a getCircumcircle() method to the SimpleTriangle at my soonest opportunity,

gwlucastrig commented 3 years ago

Do you expect that your application will produce a very large number of circumcircles? I'm trying to find a balance between complexity in design, ease of use, and efficiency.

gwlucastrig commented 3 years ago

I have pushed a new version of SimpleTriangle that implements the circumcircle method. It also includes a constructor that will create a SimpleTriangle from an edge.

IQuadEdge e; // arbitrary edge
SimpleTriangle trig1 = new SimpleTriangle(tin, e);
SimpleTriangle trig2 = new SimpleTriangle(tin, e.getDual());

Also, as the SimpleTriangle javadoc says, SimpleTriangle is a very lightweight implementation without any significant safety checks. In particular, it is imperative that the TIN not be modified while a SimpleTriangle instance is in use. Of course, you can modify the TIN if you want, just don't use a pre-existing instance of SimpleTriangle after that.

I am going to leave this issue open for a few days while I review the code changes. Let me know if you encounter any issues.

Also, please let me know if you have any further suggestions for additions to the SimpleTriangle class that would make your work easier.

micycle1 commented 3 years ago

Do you expect that your application will produce a very large number of circumcircles?

Not particularly, just a few thousand. I just thought it was worthwhile not to calculate the same thing twice, if possible, but due to how TinFour is architected that doesn't seem to be the case.