Skip to content

Add best-fitting origin/normal method to vtkPlane and use in vtkDelaunay2D

Motivation: vtkDelaunay2D performs triangulation in the (x,y) plane. If the points are not located in this plane then it uses the ComputeBestFittingPlane() method and builds a transform. This transformation transforms the points into the (x,y) where the triangulation is performed. The existing ComputeBestFittingPlane() method makes use of a least-square fit. This assumes that the best normal still has a component in z-direction, and is dependent on the calculation of a matrix determinant:

if (!normal_computed && (det = vtkMath::Determinant3x3 (c1,c2,c3)) > tolerance ) { normal[0] = vtkMath::Determinant3x3 (v,c2,c3) / det; normal[1] = vtkMath::Determinant3x3 (c1,v,c3) / det; normal[2] = -1.0; // because of the formulation }

If the points describe a plane with normal perpendicular to the z-direction then the existing method fails. I came across this problem in a blog where the author first had implemented a similar solution here. However in a later blog post he offered a more general, stable solution. Since this is a general problem I implemented his covariance matrix method as a static method in vtkPlane so it is accessible for other problems as well. I then deleted the old least-square method in vtkDelaunay2D and replaced it with a call to the covariance matrix method.

Merge request reports