title: Geometry from 2D point cloud with MATLAB
body: <p>I have an unorganized point cloud and I want to compare ideal CAD geometry and profile measurement of an object. For example, I have a CAD data of ideal object and I have a point cloud like this;</p>
  
  <p><img src="https://i.stack.imgur.com/5KqUs.jpg" alt="Point Cloud"></p>
  
  <p>How can I compare these two data? I know from CAD file, is point on the CAD data  belongs to line or radius(Arc), but how can I derive radius error of an Arc or length error of a Line?</p>
  
  <p>I tried to organize data with knnsearch but results are not satisfying.So, I tried to draw a line starting from a one point ( lets Say point 1) and I want to go next closest point ( Lets say Point 2). If closest neighbour of Point 2 is Point 1, then go to second closest point of Point 2. That algorithm seems to good for me but results are not satisfying also. Connection lines went one edge to other.</p>
  
  <p>I also thought that, may be I should convert CAD data to point cloud and I have to compare each point of measurement with closest point on CAD point cloud. I know which points belong to line and which point belong the Arc and I can calculate mean error from a line or Arc. But end points of lines or arcs will be trouble I think. Comparison results at these points will have large error I think.</p>
  
  <p>On the other hand, CAD geometry and measurements will not be convex and perfectly covered always. Some non-convex geometries can be measured. For example, you can see measurements of inverted V shape with lack of some points. It is the worst case;</p>
  
  <p><img src="https://i.stack.imgur.com/JVTEv.jpg" alt="Worst Case"></p>
  
  <p>If there are some errors on geometry estimation when measurements are not enough, it is acceptable for me.</p>
  
  <p>CPU load is also important criteria for me. There are 10.000 points and I want to complete filterings and geometry matchings in 20 ms with i7 processors.</p>
  
  <p>Are there any robust solution for this aim?</p>