Page 2 of 2

Re: Procedure to define a best-fit Plane through a set of po

Posted: Fri Jan 17, 2020 4:37 am
by IdeasVacuum
I'm working on integrating your code - on average, there are around 70 planes to define (mostly not displayed graphically, they are a means to an end - intersections. If User selection of planes is required, then symbolic square quad faces are displayed.

Re: Procedure to define a best-fit Plane through a set of po

Posted: Sat Jan 18, 2020 9:14 pm
by IdeasVacuum
Hi again alter Mann

I'm having a torrid time trying to separate the code into what is required to find the best fit plane and the code required to display/rotate/zoom the plane (which I don't need for the plane, it's one of many, but I would like to "recycle" that part of the code to allow the whole model to be rotated/zoomed).

As I understand it:
1) In Procedure Main, DATcalcSize(adPoints(),adMinMax(),adSP()) defines the Bounding Box of the points?
2) What does adSP() represent? The centroid of the points Bounding Box?

Re: Procedure to define a best-fit Plane through a set of po

Posted: Sun Jan 19, 2020 11:28 am
by alter Mann
adMinMax ist the bounding box. adSP is the centroid of all data points. This is not the same as the centroid of the bouning box. The centroid is part of the best-fit plane (see the article you linked above).
adMP is the centroid of the bounding box.
CalcMat calculates the matrix, according to which the eigenvectors and the eigenvalues ​​are calculated. The eigenvector of the minimum of the eigenvalues shows the plane normal vector (also explained in the article).
Hope this help you a little bit.

Re: Procedure to define a best-fit Plane through a set of po

Posted: Thu Feb 13, 2020 8:00 pm
by Psychophanta
Interesting problem.
I would proceed in this manner:
Get the 'n' points (3D vectors really).
Get 3 groups (n/3), if 'n' is 40 for example: then 1 group from 13, other 13, and other 14. The groups are obtained randomly i.e. never mind what points.
Locate the "center of masses" from each group, for example for first group would be the arithmetic mean: ' v1+v2+v3... / 13 ' , where v1, v2, etc. are the points (vectors).
So you have now 3 points to build the wanted plane.

Repeat that algorithm adding to the 'n' those above 3 points, and using now a Weighted_arithmetic_mean (https://en.wikipedia.org/wiki/Weighted_arithmetic_mean) giving to the 3 points a bigger "weigth" than the others.

Repeat again. So you will get 46, and the weight for the 3 points is now still bigger.

Repeat again.

The more loops the more accurate plane will obtain.

Re: Procedure to define a best-fit Plane through a set of po

Posted: Wed Feb 19, 2020 1:55 am
by IdeasVacuum
Hi Psychophanta - I did experiment with a similar method before, but it was not waif and stray proof enough for my purpose. However, it would not be unusual for the cause of failure to be my implementation rather than the method :wink:

Re: Procedure to define a best-fit Plane through a set of po

Posted: Wed Feb 19, 2020 6:17 pm
by IdeasVacuum
Hi alter Mann

Until now, I have not paid attention to the plane's normal direction, but I discovered I have made errors by not taking it into consideration. :(

In the best-fit plane code, can I define the normal direction?

Re: Procedure to define a best-fit Plane through a set of po

Posted: Wed Feb 19, 2020 9:54 pm
by alter Mann
The point set does not define one direction of the plane but both, the calculated direction (adV()) and the opposite direchtion (-adV(0),-adV(1),-adV(2)). To choose one of both you need additional information.

Re: Procedure to define a best-fit Plane through a set of po

Posted: Thu Feb 20, 2020 1:40 am
by IdeasVacuum
Indeed in this case I know the directions required so I have set-up a test for each case, which is working well :D