Cylinder calculation


I have a set of points which should lie on a cylinder but are not fairly distributed on it. I need to get the optimal parameter values that can describe such a cylinder.
Does anybody have an idea or a pointer to solve this problem?


“not fairly distributed on it”
I assume it means that all points are not placed randomlny ON cylinder’s surface but NEAR cylinder’s surface.

If they’re just near the cylinder then you can try simple genetic algorithm. One such algorith could look like that:
You need to find two points - center of cylinder’s top and center of cylinder’s bottom.
You do that by creating two random points and calculating how good is your current solution.
If it’s not good enough then modify one or more coordinates and see if it got any better. Keep doing that until you are satisfied. As your solution gets better, modify your point’s coordinates by lesser and lesser values.
Very easy so far, but now the hard part - we need a function that will tell us how good is our current solution.

  1. Let’s call our points A and B
  2. Create vector V1 = normalize(B - A)
  3. Create plane PA = (V1.x, V1.y, V1.z, dot(V1, A))
  4. Create plane PB = (V1.x, V1.y, V1.z, dot(V1, B))
  5. Now for every point X = (x, y, z, 1) calculate DA = dot(X, PA) and DB = dot(X, PB)
  6. Create some threshold T - let’s say it’s 5-10% if distance between A and B
  7. Every point with DA <= T is “Bottom” point
  8. Every point with DB >= -T is “Top” point
  9. All other points are “Middle” points
  10. For all “Top” points compute sum of abs(DB)
  11. For all “Bottom” points compute sum of abs(DA)
  12. For all middle points compute distance from cylinder’s axis: R = length(cross( -, - remember minimum (Rmin) and maximum (Rmax) distances
  13. If sum of all distances (abs(DA) and (abs(DB))and difference between Rmin and Rmax is less than your current “best” solution’s then you have found better solution.
    Of course you should search for solution as long as it keeps improving.

Using cylindrical coords :
theta = RAND
x = RAND

et voila

EDIT: Ok, I misunderstood the inputs and the outputs wanted …

mmm… Well… i think the genetic algorithm sounds like a good idea… since I need to optimize the cylinder radius and center axis… I just hoped there could be a more straight forward regression-type method…

Many Thanks!