CloudCompare / CloudComPy

Python wrapper for CloudCompare
Other
283 stars 40 forks source link

Plane equation values are different !? #133

Closed fusturnu closed 11 months ago

fusturnu commented 1 year ago

Hi, I have fitted a plane on my point cloud via CloudCompare v2.11.1 and CloudComPy separately. And I have computed different plane equation from these two tools.

CloudCompare gives that plane equation parameters : a=0.071364350617, b=-0.129927158356, c=0.988951981068, d=335.179871

What I did? : Tools > Fit > Plane > Copy Transformation Matrix > Edit > Apply transformation > Paste and apply

I got this matrix after fitting plane: 0.997439384460 0.004661835730 -0.071364350617 24.632812500000 0.004661835730 0.991512537003 0.129927158356 -44.846801757813 0.071364350617 -0.129927158356 0.988951981068 -16.164764404297 0.000000000000 0.000000000000 0.000000000000 1.000000000000

After applying transformation d turned into 335.179871 from 351.344635

CloudComPy gives that plane equation parameters : a=0.07136435061693192, b=-0.1299271583557129, c=0.9889519810676575, d=333.9215393066406

Code:

tr1 = cc.ccGLMatrix()
cloud.applyRigidTransformation(tr1)

plane = cc.ccPlane.Fit(cloud)
equation = plane.getEquation()
print(equation)
tr2 = plane.getTransformation()

Result: 0.7894984483718872 0.6095894575119019 0.07136435061693192 749.8129272460938 -0.5985828638076782 0.7904539704322815 -0.1299271583557129 249.35223388671875 -0.13561245799064636 0.05985981225967407 0.9889519810676575 333.9215393066406 0.0 0.0 0.0 1.0

What I would like to ask is why these two matrices are different, and especially why d value is different? (CloudCompare=335.179871 vs CloudComPy=333.9215393066406

fusturnu commented 1 year ago

Actually What I would like to calculate is z distance from the local x-y plane of the points.

prascle commented 1 year ago

Hello, I'm a bit lost in your calculations, I couldn't find the equations of the plane corresponding to your transformations. I compared the CloudComPy transformations with the corresponding version of CloudCompare (recent 2.13 beta) and found the same transformations for one of my example plane fitting problems. You mention CloudCompare 2.11, I don't think anything has changed between 2.11 and now, these calculations are very stable... About the transformation and the plane equation: When you obtain a plan, the transformation is as follows:

c00 c10 c20  d0
c01 c11 c21  d1
c02 c12 c23  d2
  0   0   0   1

The corresponding plane equation is: c20*x + c21*y + c22*z + d, with d equal to the dot product of the last 2 columns: c20*d0 + c21*d1 + c22*d2 Here, vectors are normalized, so that the distance of a point (x,y,z) from the plane is the value of the plane equation. Let me know if I've forgotten anything or if you're still having problems.

Regards, Paul