Page 1 of 1

Best Fit Plane Equation

Posted: Mon Jun 28, 2021 8:15 pm
by jwinkler
Hello,

I am very new to CloudCompare and working with point clouds. I created a best-fit plane to a part of a point cloud that I extracted and I was looking to extract the formula for the plane in the Ax+By+Cz+D=0 format. I think I understand how to get the A,B, and C normal variables but does anybody know how to get the D variable for the equation?

Re: Best Fit Plane Equation

Posted: Mon Jun 28, 2021 8:35 pm
by WargodHernandez
here is the code we use to get the plane equation

Code: Select all

const PointCoordinateType* ccPlane::getEquation()
{
	CCVector3 N = getNormal();
	m_PlaneEquation[0] = N.x;
	m_PlaneEquation[1] = N.y;
	m_PlaneEquation[2] = N.z;
	m_PlaneEquation[3] = getCenter().dot(N); //a point on the plane dot the plane normal
	return m_PlaneEquation;
}

so you would apply a point on the plane dotproduct the plane normal.
the center can be retrieved from the transformation matrix as the last columns first 3 values.
Dot product is calculated as follows

Code: Select all

inline Type dot(const Vector3Tpl& v) const { return x*v.x + y*v.y + z*v.z; }

Re: Best Fit Plane Equation

Posted: Mon Jun 28, 2021 9:11 pm
by jwinkler
Hey WargodHernandez,

I am very new to this and coding to be honest, is there a command window to enter this into to get these values?

Re: Best Fit Plane Equation

Posted: Mon Jun 28, 2021 9:29 pm
by WargodHernandez
I don't think it is displayed anywhere currently...

so for now you would need to copy the x,y,z translation from the transformation history and the normal values from the plane properties window
planeInfo.JPG
planeInfo.JPG (66.72 KiB) Viewed 6929 times
and then take those values into an online calculator like www.symbolab.com/solver/vector-dot-product-calculator
The link to the online calculator already has the corresponding values entered from the image above.

Also can be done in MS Excel pretty easy.

And finally we could probably add it to the Plane Properties window, but this isn't done yet and not sure when it would be added

Re: Best Fit Plane Equation

Posted: Mon Jun 28, 2021 10:30 pm
by jwinkler
Ahhh ok thank you that makes more sense now! I am basically trying to define the equation of the plane to check some point-to-plane distances we are calculating using another online calculator for a point cloud. But what's weird is based on the equation of the plane that I extracted using that method, Im getting really different number for point-to-plane measurements compared to using the cloud to mesh distance in CloudCompare. When I use the cloud to mesh distance for a specific point I get 51.02 (more reasonable for what Im doing), when I use the plane equation with the other point to plane calculator I get 1068.464. Does this have to do with the origin?

Re: Best Fit Plane Equation

Posted: Tue Jun 29, 2021 3:07 am
by WargodHernandez
I would specifically use the point to primitive distance calculation rather than the point to mesh calculation (it should work totally fine, but on certain edge cases the mesh based calculations can have an incorrect sign).

also with the point to primitive calculation you can choose whether or not to treat the plane as an infinite plane or as a bounded rectangular surface.


as for how it compares to an online calculator why don't you link to it so I can check it out.

Re: Best Fit Plane Equation

Posted: Tue Jun 29, 2021 2:58 pm
by jwinkler
Good to know, for what I was doing I couldnt see a difference between the cloud to mesh distance and the point to mesh calculation when I ran each one. See the link below to the calculator I used. The values in the snip are the ones I retrieved from my best fit plane and point in cloud compare.

https://keisan.casio.com/exec/system/1223614315
Capture1.PNG
Capture1.PNG (45.67 KiB) Viewed 6869 times

Re: Best Fit Plane Equation

Posted: Tue Jun 29, 2021 5:12 pm
by WargodHernandez
//point to plane distance: d = (a0*x+a1*y+a2*z - a3) / sqrt(a0^2+a1^2+a2^2) **USED in Cloud Compare
pointtoplanedist.JPG
pointtoplanedist.JPG (9.49 KiB) Viewed 6857 times
**USED in linked website

main difference is
(a0*x+a1*y+a2*z - a3) vs abs((a0*x+a1*y+a2*z + a3))

So it appears it is related to the sign of the const value
pointtoplanedistExample.JPG
pointtoplanedistExample.JPG (34.66 KiB) Viewed 6857 times
https://www.mathepower.com/en/distancepointplane.php Calculates with the same answer as cloud compare, honestly not sure which is correct without further investigation

Re: Best Fit Plane Equation

Posted: Tue Jun 29, 2021 5:44 pm
by jwinkler
That must be it, several of the other online calculators show the formula as having the absolute value of the numerator but the number from cloudcompare definitely makes more sense. Thanks for all of your help with this!