Skip to content
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

fix: rewrite ClosestLine and PolygonPolygonClosestLine logic for improved accuracy on sloped polygons #3124

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

mattjennings
Copy link
Contributor

===:clipboard: PR Checklist :clipboard:===

  • 📌 issue exists in github for these changes
  • 🔬 existing tests still pass
  • 🙈 code conforms to the style guide
  • 📐 new tests written and passing / old tests updated with new scenario(s)
  • 📄 changelog entry added (or not needed)

==================

Improves accuracy of PolygonPolygonClosestLine and ClosestLine functions. Big disclaimer, I heavily relied on ChatGPT for the math logic here... extra eyes greatly appreciated. I myself plan to do a deeper review on the math here before merging.

Before:

CleanShot_2024-07-12_at_19.03.52.mov

After:

CleanShot_2024-07-12_at_19.17.05.mov

I also think there's a faster way to do the PolygonPolygonClosestLine logic. Right now it iterates over each side of the polygon, draws a line, and returns the shortest result. Potentially it could use SAT to determine the closest sides, but I had unexpected results

PolygonPolygonClosestLine(polygonA: PolygonCollider, polygonB: PolygonCollider) {
    const aSat = SeparatingAxis.findPolygonPolygonSeparation(polygonA, polygonB);
    const bSat = SeparatingAxis.findPolygonPolygonSeparation(polygonB, polygonA);

    return ClosestLine2(aSat.side, bSat.side);
}
CleanShot.2024-07-12.at.20.08.14.mp4

@github-actions github-actions bot added the bug This issue describes undesirable, incorrect, or unexpected behavior label Jul 13, 2024
@eonarheim eonarheim marked this pull request as ready for review July 15, 2024 00:04
@eonarheim eonarheim merged commit 2745795 into main Jul 15, 2024
9 checks passed
@eonarheim eonarheim deleted the fix/improve-closest-line-logic branch July 15, 2024 00:21
@eonarheim
Copy link
Member

@mattjennings Thanks again! Bravo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants