<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Calculate a convex hull - The QuickHull algorithm</title>
    <link>http://westhoffswelt.de/blog/0040_quickhull_introduction_and_php_implementation.html</link>
    <description>In need of a fast and efficient way of calculating the convex hull of a point set, I stumbled across the QuickHull algorithm, after doing some research. This algorithm is a divide and conquer approach to solve the given problem, which is quite efficient in the average case. The following article gives an introduction into convex hulls and the QuickHull algorithm itself. Furthermore a implementation of it in PHP is presented for download.
</description>
    <language>en</language>
    <copyright>CC by-nc-sa</copyright>
    <managingEditor>Jakob Westhoff</managingEditor>
    <managingEditor>Jakob Westhoff &lt;jakob@westhoffswelt.de&gt;</managingEditor>
    <pubDate>Wed, 21 Oct 2009 12:35:15 +0000</pubDate>
    <lastBuildDate>Wed, 21 Oct 2009 12:35:15 +0000</lastBuildDate>
    <generator>eZ Components Feed dev (http://ezcomponents.org/docs/tutorials/Feed)</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <item>
      <title>Trivial Implementation at Fri, 06 May 2011 23:04:46 +0200</title>
      <link>http://westhoffswelt.de/blog/0040_quickhull_introduction_and_php_implementation.html#comment_3</link>
      <description>In compliance with GPL3, here's my published code:&#13;
&#13;
&lt;code&gt;&#13;
&lt;?php&#13;
include( 'convex_hull.php' );&#13;
&#13;
$cn = mysql_connect('localhost','xxx','yyy'); &#13;
mysql_select_db('zzz', $cn);&#13;
&#13;
$regions = array();&#13;
&#13;
$result = mysql_query("SELECT * FROM regions WHERE polygon IS NULL");&#13;
while ($region = mysql_fetch_assoc($result)) {&#13;
	$regions[] = $region;&#13;
}&#13;
mysql_free_result($result);&#13;
&#13;
$max = 0;&#13;
$max_name = '';&#13;
&#13;
foreach($regions as &amp;$region) {&#13;
	$points = array();&#13;
	&#13;
	$result = mysql_query("SELECT latitude, longitude FROM postal_codes WHERE region_id = " . $region['id']);&#13;
	while ($point = mysql_fetch_row($result)) {&#13;
		$points[] = $point;&#13;
	}&#13;
	mysql_free_result($result);&#13;
	&#13;
	echo "Calculating shape of " . $region['name'] . "...\n";&#13;
	$hull = new ConvexHull($points);&#13;
	$region['polygon'] = $hull-&gt;getHullPoints();&#13;
	&#13;
	echo "Updating " .  $region['name'] . "...\n";&#13;
	&#13;
	$polygon = mysql_real_escape_string(serialize($region['polygon']) );&#13;
	mysql_query('UPDATE regions ' .&#13;
		'SET polygon = \'' . $polygon . '\' ' .&#13;
		'WHERE id = ' . $region['id']&#13;
	);&#13;
	&#13;
	echo 'Polygon is ' . strlen($polygon) . ' characters.'; &#13;
	&#13;
	if (strlen($polygon) &gt; $max) {&#13;
		$max = strlen($polygon);&#13;
		$max_name = $region['name'];&#13;
	}&#13;
	&#13;
}&#13;
&#13;
mysql_close($cn);&#13;
&#13;
echo "Largest polygon is " . $max_name . " at " . $max . " characters.\n";&#13;
&#13;
exit;&#13;
&lt;/code&gt;</description>
      <author>Trivial Implementation</author>
      <pubDate>Fri, 06 May 2011 21:04:46 +0000</pubDate>
    </item>
    <item>
      <title>Barry Cornelius at Sun, 30 Jan 2011 19:31:52 +0100</title>
      <link>http://westhoffswelt.de/blog/0040_quickhull_introduction_and_php_implementation.html#comment_2</link>
      <description>I wanted KML files giving the outline of UK postcode areas (e.g., DH).  Surprisingly,  I couldn't find these on the web.  However, you can get from the Ordnance Survey/Royal Mail, the coordinates of the centre of each postcode (e.g., DH1 3LE). I used your code to generate some points giving an outline of a postcode area and produced some KML from these points.  I specifically needed it for a web site I have for displaying future running races in North East England, as shown at http://www.northeastraces.com/running/races/explain/pcaYO?arg=pcaYO.  However,  I thought I might as well do the rest of the UK at the same time as shown at http://www.northeastraces.com/runningstatic/pcas/.  Thanks.</description>
      <author>Barry Cornelius</author>
      <pubDate>Sun, 30 Jan 2011 18:31:52 +0000</pubDate>
    </item>
    <item>
      <title>Jason Judge at Sun, 30 Jan 2011 02:16:21 +0100</title>
      <link>http://westhoffswelt.de/blog/0040_quickhull_introduction_and_php_implementation.html#comment_1</link>
      <description>Thanks! Just what I was looking for to create polygons around UK postcodes. I have up to 1.7 million points to process at any time, so will be looking for a way to apply this algorithm to a series of database queries rather than trying to pull all points into memory in one go.&#13;
&#13;
The diagrams are great in helping to understand how it all works.</description>
      <author>Jason Judge</author>
      <pubDate>Sun, 30 Jan 2011 01:16:21 +0000</pubDate>
    </item>
  </channel>
</rss>

