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

WIP: Vertex reflection along a plane #129

Closed
wants to merge 33 commits into from

Conversation

zilmarinen
Copy link
Contributor

Description

Work in progress proposal to add supporting methods to reflect Mesh and Polygon vertices along a given Plane.

This is currently a partial implementation as the reflected vertex normal yields incorrect results.

Discussion

I have implemented the appropriate methods for reflecting the vertex positions but the calculations used to determine the reflected normal of the plane are currently incorrect. This is most likely due to my lack of comprehension of the concepts discussed here and how this should be implemented. This requires further discussion.

The ordering of the polygon vertices is reversed using .inverted() which I believe to be correct but this feels a little like a code smell. Reversing the ordering feels intuitive to me as the polygons are mirrored 🤷‍♂️

Basic coverage for reflecting a quad has been added to the unit test suite but this will likely need additional tests for polygons which are coplanar / intersecting. I will bolster these further if there is any interest in merging this PR.

@zilmarinen zilmarinen marked this pull request as draft August 30, 2024 11:02
@nicklockwood
Copy link
Owner

I've fixed the reflection logic and landed your changes 👍

@nicklockwood
Copy link
Owner

The reason the reflection math you found wasn't working is that it's for calculating a reflection as if the normal was bouncing off the plane (like light reflecting off a mirror) but you want the reflection along the plane (i.e. where the object appears in the mirror - which is behind the plane not in front of it).

I'm also not great at math so there's probably a better way to do it, but I solved it by translating the position of the end of the normal (the same way you did for the vertex position) and then subtracting the reflected position from that to tun it back into a normal vector instead of a position vector.

@zilmarinen
Copy link
Contributor Author

Superb. Thank you @nicklockwood 🙌

Also, thanks for explaining the reflection logic and how you overcame this.

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.

3 participants