Commit 8edbb77
authored
Optimize and fix sphere-OBB intersection logic (#23865)
# Objective
- Optimize the Sphere and OOB intersection logic.
- Fix a bug when the sphere and OBB shared the exact same center.
## Solution
- The previous implementation calculated `v / d` (a normalized vector).
If the distance `d` was zero (in a situation when centers are
identical), this resulted in a division by zero. The new approach avoids
normalization by refactoring the comparison.
- Original: $d < r_1 + r_2$ where $r_2 =$
`relative_radius`$\Bigl(\frac{\mathbf{v}}{d}\Bigr)$
- New: $d^2 \leq r \cdot d + r_{\rm unscaled}$ where $r_{\rm unscaled}
=$ `relative_radius`$(\mathbf{v})$
## Testing
- Added new test cases covering identical centers, edge contacts, and
zero-extent volumes. These tests fail on main but pass with this PR.
- Verified performance via the newly added camera benchmarks in
#23863
```
intersects_obb/sphere_intersects_obb
time: [5.3677 ns 5.3932 ns 5.4227 ns]
change: [−19.462% −18.945% −18.426%] (p = 0.00 < 0.05)
Performance has improved.
```1 parent e9bfe1e commit 8edbb77
1 file changed
Lines changed: 78 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
222 | | - | |
223 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
| |||
608 | 609 | | |
609 | 610 | | |
610 | 611 | | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
611 | 686 | | |
612 | 687 | | |
613 | 688 | | |
| |||
0 commit comments