-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Make Triangle.closestPointToPoint much faster #14377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@WestLangley looks good? |
|
You might want to consider #8493 (comment) as well. |
|
@mrdoob It's a go! |
|
I think I was wrong, I believe this algorithm is actually the same as @sxenos's. |
|
It's clearly closely related. I personally strongly prefer using an algorithm where I can read something that tells me how it was derived and how it works, so I prefer this implementation (unless there is an explanation of sxenos's hanging around somewhere.) But if you really feel strongly, I'll benchmark the other one sometime soon. |
|
Agreed. I prefer an algorithm with a published reference. Edge cases and numerical stability can be tricky. |
|
Sounds good! |
|
Thanks! |
This is an interesting function to improve because it's a small hotspot for the three-pathfinding library's functionality for clamping positions onto a navigation mesh.
The algorithm I implemented is very well-explained in Real-Time Collision Detection by Christer Ericson. You may be able to preview the relevant part of the book on Google Books, starting on page 136 (I don't know exactly how Google Books decides who can see what parts of what books.)
How much faster this is depends on the inputs. In the benchmark I wrote, I tried to make a representative sample of points and triangles and observed approximately an 8x speedup on both desktop Chrome and Firefox, which seems plausible. If you really want, I can produce more performance numbers, but it should clearly be much faster in all situations.
For correctness testing, I tested it alongside the old version on all of the point/triangle pairs in the benchmark and verified that the two produced the same output modulo floating-point error.