Skip to content

Line-line distance by clamping and reprojecting - #30

Merged
nhz2 merged 2 commits into
mainfrom
line-line-reproject
Nov 3, 2026
Merged

nhz2 merged 2 commits into
mainfrom
line-line-reproject

Conversation

@nhz2

@nhz2 nhz2 commented Nov 2, 2026

Copy link
Copy Markdown
Member

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.

nhz2 and others added 2 commits November 2, 2026 16:35
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
@nhz2
nhz2 merged commit 287e746 into main Nov 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant