Repository navigation
Line-line distance by clamping and reprojecting - #30
Merged
Merged
Conversation
The line-line kernel now clamps and reprojects, as in Ericson, "Real-Time Collision Detection" (2005), §5.1.9, but with `t` first: `t` from the lines, clamped, then `s` of the point at `t`, clamped, then `t` of the point at `s`, clamped. That replaces the end point candidates and their two minimums, so it is three divides with one result. `inv(a)` and `inv(c)` start early, beside the divide for the first `t`, so only one divide is on the dependency chain. The comment proves the result is the closest pair in exact arithmetic, and keeps the Gram-Schmidt form of the same steps, which has only second powers of the coordinates but was about 20% slower. Rational results are unchanged, and floating point accuracy in stress tests is the same as before, well within the contract. Against main, the line-line, line-triangle and triangle-triangle distances are 12-30% faster in throughput and 8-18% in latency, and `collide_forces!` is 4-10% faster. The isosphere neighbor lists are 1-4% slower, which is not explained yet. The line-line force keeps its own divides: sharing `inv(a)` made an end weight one ulp below one, which moved the end point more than the separation in a test with parallel line segments. Bump the version to 0.3.2-dev. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the case-by-case argument for why clamping `t`, then `s`, then `t` gives the closest pair with three steps on one fact: the distance from a point moving along a line to a fixed line or line segment is convex, so its minimum over `[0, 1]` is its unconstrained minimizer clamped. The first step also covers parallel line segments, so the underflow paragraph now refers back to it. Comments only. Assisted-by: Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The line-line kernel now clamps and reprojects, as in Ericson, "Real-Time Collision Detection" (2005), §5.1.9, but with
tfirst:tfrom the lines, clamped, thensof the point att, clamped, thentof the point ats, clamped. That replaces the end point candidates and their two minimums, so it is three divides with one result.inv(a)andinv(c)start early, beside the divide for the firstt, so only one divide is on the dependency chain.The comment proves the result is the closest pair in exact arithmetic, and keeps the Gram-Schmidt form of the same steps, which has only second powers of the coordinates but was about 20% slower. Rational results are unchanged, and floating point accuracy in stress tests is the same as before, well within the contract.
Against main, the line-line, line-triangle and triangle-triangle distances are 12-30% faster in throughput and 8-18% in latency, and
collide_forces!is 4-10% faster. The isosphere neighbor lists are 1-4% slower, which is not explained yet.The line-line force keeps its own divides: sharing
inv(a)made an end weight one ulp below one, which moved the end point more than the separation in a test with parallel line segments.Bump the version to 0.3.2-dev.