TheSwamp

Code Red => .NET => Topic started by: kaefer on April 14, 2011, 09:14:49 PM

Title: Collinearity in convex hull algorithm
Post by: kaefer on April 14, 2011, 09:14:49 PM
First, many thanks for gile's concise F# implementation of the Graham scan algorithm (http://www.theswamp.org/index.php?topic=31865.msg429472#msg429472). I had to make do with Carsten König's variant (http://fssnip.net/3j) before, which is a little more verbose.

Put to use by throwing it together with Kean's 2D point gathering (http://through-the-interface.typepad.com/through_the_interface/2011/02/gathering-points-defining-2d-autocad-geometry-using-net.html), I had to notice slight damage to my sport car's left front wheel (see picture).

My suspicion falls on the clockwise function, replacing it with Bryco's isLeftMath method (http://www.theswamp.org/index.php?topic=29216.msg348194#msg348194) brings better results. What gives? Looks like the case that 3 points lie in a row needs to be handled explicitly.
Title: Re: Collinearity in convex hull algorithm
Post by: Kerry on April 14, 2011, 09:24:51 PM

looks like the roof above the rear window is also a little 'dented'
Title: Re: Collinearity in convex hull algorithm
Post by: kaefer on April 15, 2011, 02:54:45 AM
looks like the roof above the rear window is also a little 'dented'

That's right, too.

How embarassing, inadequate testing led to completely wrong diagnosis. I should've checked the less complex procedure first: Generate the points, save them as DBPoints into the Database, and all's well with gile's Convex Hull.
Title: Re: Collinearity in convex hull algorithm
Post by: gile on April 15, 2011, 06:07:35 AM
Hi,

Thanks for reporting.

After reading this post I looked deeper in the code I posted and noticed some problem with colinear points at 0° from the pivot point (eg. with a rectugular arry of points), so I modify the sorting lambda function in the code here (http://www.theswamp.org/index.php?topic=31865.msg429472#msg429472).
It seems to work fine now: all colinear points are removed.
Title: Re: Collinearity in convex hull algorithm
Post by: gile on April 16, 2011, 11:13:51 AM
Hi,

I think I finally solve the problem with colinear points by using a tolerance in the cosines comparison while sorting the point list.
New code here (http://www.theswamp.org/index.php?topic=31865.msg429472#msg429472).