geometry-central icon indicating copy to clipboard operation
geometry-central copied to clipboard

Optimize barycentric coordinate computation

Open Ameobea opened this issue 2 years ago • 1 comments

In my application which traces thousands of geodesic paths, I found that the main bottleneck was solving the system of equations to convert cartesian -> barycentric coordinates.

I found a specialized solution for performing the conversion, and swapping it in produces the same results as the Eigen solver while doing so very much faster.

I totally understand if you're not interested in taking this change since it pulls code from a third party source and might have different behavior in case of weird things like degenerate/invalid triangles, NaNs, etc. but I thought I'd put it up to see if you're interested.

Ameobea avatar Oct 17 '23 22:10 Ameobea

Hi! Thanks for opening this.

I'm interested in merging this, the fast method seems quite nice.

I am a liiiiitle wary because the existing colPivQR approach was very extensively numerically tested as part of our intrinsic triangulations work. The explicit version here could be more stable or less stable, but either way I am a bit reluctant to merge it in without repeating those tests (and I don't have time to repeat those tests).

What if instead we could just merge it as an alternative option, for now? As a new cartesianVectorToBarycentric_fast() or something, alongside the old version? That way folks can have it as an option. We could even add a flag to the traceGeodesic() function to use it instead.

nmwsharp avatar Nov 19 '23 07:11 nmwsharp