Re: Fitting a Cylinder to 3D data points

• To: mathgroup at smc.vnet.net
• Subject: [mg47949] Re: [mg47679] Fitting a Cylinder to 3D data points
• From: Daniel Lichtblau <danl at wolfram.com>
• Date: Sun, 2 May 2004 04:50:45 -0400 (EDT)
• References: <200404210923.FAA02477@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Nicolas Flannery wrote:
> I am trying to write a Mathematica algorithm that will allow me to
> find a cylinder or center line and radius that will best fit a set
> of 3D coordinates.  These coordinates are in an arbitrary coordinate
> system and may describe a cylinder in any orientation.  One approach
> I think would work would be to find a line that is equidistant from
> each point in the list, however I need assistance in doing this.  The
> points do have some noise so an optimization method is necessary.  Thanks
>
> Nick

Apologies for the delayed response. I had a draft that covers this but I
wanted to complete it before posting. Not so simple because I set it
down three years ago and found it hard to recall what exactly I was
thinking at that time. I'm still not thrilled with the last subsections
involving theory, but that's life.

The basic idea for what you want to do first involves finding all
cylinders through five of the points; this is the magic number for which
there are generically finitely many. Next we take the coordinates that
define the most promising one, and use them as start values for a least
squares minimization involving all the other points. Details (including
Mathematica code) may be found in:

D.L. (2004). Cylinders through five points in R^3.

The relevant code for computing center-line/radius of cylinders through
five points is in section 2, and handling the overdetermined case from
there is a subsection of section 3.

I put a copy of the notebook (around 500 Kb) at

By the way, if you have in mind an application for this, I'd be