title: How to find center axis line of an object and why it is different from principal axis?
body: <p>I have (x,y,z) data points of many solid objects which are not aligned to the global axis. The data points are available only for the end part of solid objects, not for middle part due to experimental constraints. My task is to first align the center line of each solid object to the global axis and then compare these solids. Finding the center line of both ends separately is also okay to me.  I read about finding the principal axis using the eigenvector, which I did but it is not finding centerline. </p>
  
  <p>How do I find the longitudinal centerline of this kind of object?</p>
  
  <p>Magenta Largest eigenvector of whole </p>
  
  <p>Red and yellow (Largest eigenvector of separate part)</p>
  
  <p><img src="https://i.imgur.com/FIgRKu8.jpeg" alt=""></p>
  
  <pre><code>r=cov(data);  data=DTPT (86043×3)
  [vec,val]=eig(r);
  plot3(data(:,1),data(:,2),data(:,3),'.','markersize',1)
  
  mu=mean(data);
  d = sqrt(diag(val));
  hold on;
  quiver3(mu(1),mu(2),mu(3),2*vec(1,3),2*vec(2,3),2*vec(3,3), d(3), 'm','LineWidth',5);
  quiver3(mu(1),mu(2),mu(3),-2*vec(1,3),-2*vec(2,3),-2*vec(3,3), d(3), 'm', 'LineWidth',5);
  hold off;
  
  
  indDT=1:37768; 
  data1=data(indDT,:);
  [v,l]=eig(cov(data1));
  mu=mean(data1);
  d = sqrt(diag(l));
  hold on;
  quiver3(mu(1),mu(2),mu(3),3*v(1,3),3*v(2,3),3*v(3,3),d(3), 'r', 'LineWidth',5);
  quiver3(mu(1),mu(2),mu(3),-3*v(1,3),-3*v(2,3),-3*v(3,3),d(3),'r','LineWidth',5);
  hold off;
  
  indPT=37769:86043;
  data2=data(indPT,:);
  [v,l]=eig(cov(data2));
  mu=mean(data2);
  d = sqrt(diag(l));
  hold on;
  quiver3(mu(1),mu(2),mu(3),3*v(1,3),3*v(2,3),3*v(3,3),d(3), 'y','LineWidth',5);
  quiver3(mu(1),mu(2),mu(3),-3*v(1,3),-3*v(2,3),-3*v(3,3),d(3),'y','LineWidth',5);
  hold off;
  </code></pre>
  
  <p>Here are <a href="https://www.dropbox.com/s/slw9q9iqyjz9teu/solidData.mat?dl=0" rel="nofollow noreferrer">the data</a> and the <a href="https://www.dropbox.com/s/yu8sfv4fvfud2dk/S17WT.fig?dl=0" rel="nofollow noreferrer">MATLAB figure</a>. </p>