I'm not sure why there isn't a function for this (that I can find at
least!). You can find a function that does what you want here:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<a href="http://www.vtk.org/pipermail/vtkusers/2004-March/072916.html" target="_blank">http://www.vtk.org/pipermail/vtkusers/2004-March/072916.html</a><br>
or here<br>
<a href="http://markmail.org/message/52odxars4ijopqfe#query:fit%20plane%20vtk+page:1+mid:52odxars4ijopqfe+state:results" target="_blank">http://markmail.org/message/52odxars4ijopqfe#query:fit%20plane%20vtk+page:1+mid:52odxars4ijopqfe+state:results</a><br>


<br>
The idea is that the eigen vector corresponding to the smallest eigen
value of the scatter matrix of the points is the normal of the plane.
It seems like there should be a function somewhere in vtk:<br>
vtkPlane* FitPlane(vtkPoints* Points);<br>
<br>
GC, when you get this working how you want it can you post it here and maybe someone can add it somewhere in vtk?<br>
<br clear="all">Thanks,<br><font color="#888888"><br>David<br>
</font></blockquote></div><br>I extracted this function mostly from vtkDelaunay2d. 
Maybe someone can add this to vtkPlane ?<br>
<br>
vtkPlane* BestFitPlane(vtkPoints *points)<br>
    {<br>
        vtkIdType NumPoints = points-&gt;GetNumberOfPoints();<br>
        <br>
        //find the center of mass of the points<br>
        double Center[3] = {0.0, 0.0, 0.0};<br>
        <br>
        for(vtkIdType i = 0; i &lt; NumPoints; i++)<br>
        {<br>
            double point[3];<br>
            points-&gt;GetPoint(i, point);<br>
        <br>
            Center[0] += point[0];<br>
            Center[1] += point[1];<br>
            Center[2] += point[2];<br>
        }<br>
                <br>
        Center[0] = Center[0]/static_cast&lt;double&gt;(NumPoints);<br>
        Center[1] = Center[1]/static_cast&lt;double&gt;(NumPoints);<br>
        Center[2] = Center[2]/static_cast&lt;double&gt;(NumPoints);<br>
        <br>
        //Compute Sample Covariance Matrix (with points centered at the origin)<br>
            <br>
        double *a[3], a0[3], a1[3], a2[3];<br>
        a[0] = a0; a[1] = a1; a[2] = a2; <br>
        for(unsigned int i = 0; i &lt; 3; i++)<br>
        {<br>
            a0[i] = a1[i] = a2[i] = 0.0;<br>
        }<br>
        <br>
        for(unsigned int pointId = 0; pointId &lt; NumPoints; pointId++ )<br>
        {<br>
            double x[3], xp[3];<br>
            points-&gt;GetPoint(pointId, x);<br>
            xp[0] = x[0] - Center[0]; <br>
            xp[1] = x[1] - Center[1]; <br>
            xp[2] = x[2] - Center[2];<br>
            for (unsigned int i = 0; i &lt; 3; i++)<br>
            {<br>
                a0[i] += xp[0] * xp[i];<br>
                a1[i] += xp[1] * xp[i];<br>
                a2[i] += xp[2] * xp[i];<br>
            }<br>
        }<br>
<br>
        for(unsigned int i = 0; i &lt; 3; i++)<br>
        {<br>
            a0[i] /= static_cast&lt;double&gt;(NumPoints);<br>
            a1[i] /= static_cast&lt;double&gt;(NumPoints);<br>
            a2[i] /= static_cast&lt;double&gt;(NumPoints);<br>
        }<br>
        <br>
        // Extract eigenvectors from covariance matrix<br>
        double *v[3], v0[3], v1[3], v2[3];<br>
        v[0] = v0; v[1] = v1; v[2] = v2; <br>
        double eigval[3];<br>
        vtkMath::Jacobi(a,eigval,v);<br>
        //Jacobi iteration for the solution of eigenvectors/eigenvalues
of a 3x3 real symmetric matrix. Square 3x3 matrix a; output eigenvalues
in w; and output eigenvectors in v. Resulting eigenvalues/vectors are
sorted in decreasing order; eigenvectors are normalized.<br>
        <br>
        vtkPlane* BestPlane = vtkPlane::New();<br>
        //Set the plane normal to the smallest eigen vector<br>
        BestPlane-&gt;SetNormal(v2[0], v2[1], v2[2]);<br>
        <br>
        //Set the plane origin to the center of mass<br>
        BestPlane-&gt;SetOrigin(Center[0], Center[1], Center[2]);<br>
        <br>
        return BestPlane;<br>
    }<br>
<br>
<br>
<br>
<br>
<br>
and a test call:<br>
<br>
    vtkPoints* Points = vtkPoints::New();    <br>
       <br>
    //create 3 known points<br>
    Points-&gt;InsertNextPoint(0.0, 0.0, 0.0);<br>
    Points-&gt;InsertNextPoint(1.0, 0.0, 0.0);<br>
    Points-&gt;InsertNextPoint(0.0, 1.0, 0.0);<br>
    <br>
    vtkPlane* BestPlane = VTKHelpers::BestFitPlane(Points);<br>
    <br>
    std::cout &lt;&lt; &quot;Best Plane:\n&quot; &lt;&lt; *BestPlane &lt;&lt; &quot;\n&quot;;<br>
<br><br>
<br clear="all">Thanks,<br><br>David<br>