Sie sind auf Seite 1von 4

Notes on Flatness

Patch Kessler, June 30, 2011 Denition: The atness of a collection of points is the minimum of the distances between parallel planes that sandwich the points.

The xs are more flat than the os.

Approximate Flatness
d6 d3 d4 d5

Let di be the distance from the ith point to a plane.

d2

d1
As the t between the plane and the points gets better, the quantity D = d2 +d2 + +d2 gets smaller. Usually n 1 2 one best t plane exists for which D is as small as possible. Unfortunately, atness is only approximately equal to the minimum distance between sandwiching planes parallel to this best t plane. To see this, consider the four points below to the left, and the six points below to the right.

flatness = A < B
The best t plane for the four points to the left is the horizontal blue line. The atness of these points is equal to A. Adding two points (see the point set to the right) causes the best t plane to rotate. The atness of the point set hasnt changed, however the distance between sandwiching planes parallel to the best t plane is now B > A. The dierence between approximate and true atness is small enough that it doesnt matter in most cases. 1

1.1

Finding the Best Fit Plane

Every plane can be parameterized by a unit normal vector e and a scalar (such that the plane contains the point e). The sum of the squares of the distances from the points x1 , x2 , . . . , xn to the plane given by e and is D = (e (x1 e))2 + (e (x2 e))2 + + (e (xn e))2 , = eTAe 2eT b + 2 , (1)

where A = x1 xT + x1 xT + + xn xT , and b = x1 + x2 + xn . Translating coordinates so that the centroid1 n 1 1 of the xi s coencides with the origin causes b = 0, eliminating the middle term from (1). A minimum in D = eTAe + 2 is attained only if = 0, (i.e., only if the best t plane passes through the centroid). Finding an optimal e is slightly harder. Because A = AT , the spectral theorem guarantees the existence of an orthonormal basis {e1 , e2 , . . . , ed } such that A = 1 e1 eT + 2 e2 eT + + d ed eT . For non pathological 1 2 d data, one of the i s will be smaller than the others. Relabel if necessary so that the smallest i is 1 . Note 2 2 2 that e = 1 e1 + 2 e2 + + d ed where 1 + 2 + d = 1. If e = e1 , then some i=1 = 0 so that
2 2 2 eTAe = 1 1 + 2 2 + + d d > 1 = eTAe1 . 1

(2)

It follows that eTAe is minimized when e = e1 . Notice that the dimension of the space of the points is d. This discussion and the following Matlab code work for any d. When d = 2 were dealing with points in 2D; the best t plane through these points is a line (as in the gures in this document). When d = 3 were dealing with points in 3D; the best t plane through these points is a plane in the colloquial sense, (i.e., a at 2D surface). When d > 3, were dealing with hyper-points and hyper-planes in higher dimensional spaces.

1.2

Finding Approximate Flatness

Given e from the previous section, and supposing the centroid of the xi s is at the origin, the approximate atness of the xi s is given by max{e xi } min{e xi }.

1.3

Practical Calculations in Matlab

The following Matlab code accepts a d n array as input (the n columns of which locate n points in Rd ), and returns approximate atness as output:
function af=ApproximateFlatness(X) n=size(X,2); c=sum(X,2)/n; A=(X-c*ones(1,n))*X; [V,D]=eig(A); [Dmin,I]=min(diag(D)); d=V(:,I)*(X-c*ones(1,n)); af=max(d)-min(d);

1 The

centroid of the n points xi is

1 n

xi .

True Flatness

If the sandwiching planes each contain one point, then they can be rotated closer together.

d1

d2 d1 > d2

The planes can be rotated up to where one of them intersects a new point, (further rotation would cause the planes to not sandwich all the points). It follows that atness can be computed by a minimization over the faces and edges of a point sets convex hull.

Point Set

Point Set + Convex Hull d = Point Set Flatness

The process is similar in 3D but involves more bookkeeping; code for doing this is given on the next page.

2.1

Matlab Code for True Flatness

function [tf,DE,DF]=flatness(X) %compute flatness of the columns of X. K=convhulln(X); %Compute the convex hull. count=1; while ~isempty(K) H(count).node=K(1); [r,c]=find(K==K(1)); Kt=K(r,:); Kt=Kt(:); H(count).nbr=unique(Kt(Kt~=K(1))); K(r,:)=[]; count=count+1; end %Edges EN=numel([H.nbr]); E=zeros(2,EN); index=1; for k=1:length(H) n=length(H(k).nbr); E(1,index:index+n-1)=H(k).node; E(2,index:index+n-1)=H(k).nbr; index=index+n; end DE=inf; optE=zeros(2); %columns give indices of closest edges for k1=1:EN for k2=k1+1:EN if E(1,k1)==E(1,k2) | E(1,k1)==E(2,k2) | E(2,k1)==E(1,k2) | E(2,k1)==E(2,k2) continue end x1=X(:,E(1,k1)); e1=X(:,E(2,k1))-x1; e1=e1/norm(e1); x2=X(:,E(1,k2)); e2=X(:,E(2,k2))-x2; e2=e2/norm(e2); e3=cross(e1,e2); if norm(e3)<1e-10, disp(warning!! e3 is too small.), continue, end e3=e3/norm(e3); s1=sign(e3*(X-x1*ones(1,size(X,2)))); s1(E(:,k1))=0; s2=sign(e3*(X-x2*ones(1,size(X,2)))); s2(E(:,k2))=0; if any(s1.*s2>0), continue, end d=abs(e3*(x1-x2)); if d<DE, DE=d; optE=E(:,[k1 k2]); end end end %Faces DF=inf; optF=zeros(1,4); %first three indecies identify triangle, last one identifies point. QF=[]; %find all triangular rings of edges (faces and more). for k=1:length(E) T=[E(1,E(2,:)==E(1,k)) E(2,E(1,:)==E(1,k))]; T=T(T~=E(2,k)); B=[E(1,E(2,:)==E(2,k)) E(2,E(1,:)==E(2,k))]; B=B(B~=E(1,k)); I=intersect(T,B); QF=[QF;[ones(length(I),1)*E(:,k) I]]; end for k=1:length(QF) a=X(:,QF(k,1))-X(:,QF(k,2)); b=X(:,QF(k,3))-X(:,QF(k,2)); e=cross(a,b); e=e/norm(e); d=e*(X-X(:,QF(k,2))*ones(1,length(X))); if any(d>0)&any(d<0), continue, end [d,Id]=max(abs(d)); if d<DF, DF=d; optF=[QF(k,:) Id]; end end tf=min(DE,DF);

Das könnte Ihnen auch gefallen