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

Suggestion: Plane.TryFromPoints() #184

Open
DaveInCaz opened this issue Nov 19, 2020 · 3 comments
Open

Suggestion: Plane.TryFromPoints() #184

DaveInCaz opened this issue Nov 19, 2020 · 3 comments

Comments

@DaveInCaz
Copy link

Plane.FromPoints() will throw exceptions if the arguments don't actually form a plane. For instance, if you give it 3 points on the same line.

I have some cases where I have a large set of points which are coplanar, but I don't know in advance which 3 points necessarily will fulfill the conditions of FromPoints. So I have to iteratively try point triplets until one of them works. This is fine in itself, but it means that I either have to try/catch exceptions when calling FromPoints or I have to manually test the points before calling it.

I have two concerns with manual testing - one is that I can't know for certain that the numeric precision won't cause a failure - e.g., my test might conclude the points are not colinear, but the then test in FromPoints could conclude the opposite.

The other is just inefficiency, that essentially the same test would be performed twice, once by me and once by FromPoints.

Based on all that I think it would be useful to have a bool Plane.TryFromPoints() method in addition to the existing one. Probably the existing FromPoints could be refactored into that function and would itself remain just a wrapper to throw exceptions if the Try... version returned false.

I see that, for example, LineSegment2D has a TryIntersect() method which behaves in a similar way, so maybe this would be an OK pattern to use in this library.

I could submit a pull request for this if it sounds like a good idea?

@jkalias
Copy link
Member

jkalias commented Mar 28, 2023

Hi,

I think this is a good idea. My approach would be to find the best matching plane in terms of least-squares, as described here. The condition that we need at least 3 points will still hold of course. We would then need to determine if any point lies outside of this plane and if it does, we should discard it as invalid.

Let me know if you want to submit a PR or I should provide an implementation for further discussion.

@jkalias
Copy link
Member

jkalias commented Apr 5, 2023

Relates to #216

@f-frhs f-frhs mentioned this issue Apr 6, 2023
2 tasks
@jkalias
Copy link
Member

jkalias commented May 5, 2023

I could submit a pull request for this if it sounds like a good idea?

Are you still interested in this? Would you like to submit a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants