Skip to content

Add an analytic ray-capsule intersection test - #446

Open
joonazan wants to merge 6 commits into
dimforge:masterfrom
joonazan:ray-capsule
Open

Add an analytic ray-capsule intersection test#446
joonazan wants to merge 6 commits into
dimforge:masterfrom
joonazan:ray-capsule

Conversation

@joonazan

@joonazan joonazan commented Sep 7, 2026

Copy link
Copy Markdown

I need ray-capsule intersections and was surprised that they were really slow because they are implemented via GJK, so I wrote an analytical version.

I did not solve the equations myself. I adapted Inigo Quilez's GLSL. The result is more optimized than anything else I can find.

On my machine the analytical version takes about 5 ns per query hit or miss. GJK takes 50 ns on a miss and 400 - 700 ns on a hit.

The analytical version's error is smaller, too. Could be better, though. In extreme corner cases errors of 1e-3 can be observed at scales of a few units using f32.

@joonazan

joonazan commented Sep 8, 2026

Copy link
Copy Markdown
Author

Replaced the initial AI version of the collision check with a handwritten one that is shorter and is much more numerically stable due to cross products instead of dot products followed by a * b - c * d. Worst case error didn't improve much but it is way better on average.

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