Login   Register  
PHP Classes
elePHPant
Icontem

isPolyInside failing

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Polygon  >  All threads  >  isPolyInside failing  >  (Un) Subscribe thread alerts  
Subject:isPolyInside failing
Summary:isPolyInside method not returning the correct result
Messages:3
Author:Andy Burton
Date:2013-07-05 16:45:04
Update:2014-03-05 10:15:24
 

  1. isPolyInside failing   Reply   Report abuse  
Picture of Andy Burton
Andy Burton
2013-07-05 16:45:04
Bit of an odd one but there seem to be some scenarios that cause isPolyInside to incorrectly identify another polygon that is inside it e.g.

// Polygon coordinates

$coordsA = array (
array (5,5), array (15,2),
array (15,10), array (5,10)
);
$coordsB = array (
array (9,5), array (11,5),
array (11,7), array (9,7)
);

// Create polygons

$pA = new polygon;
$pB = new polygon;

foreach ($coordsA as $coord)
{
$pA->addv ($coord[0], $coord[1]);
}

foreach ($coordsB as $coord)
{
$pB->addv ($coord[0], $coord[1]);
}

// Check whether B is inside A
// This should return TRUE but instead returns FALSE

var_dump ($pA->isPolyInside ($pB));

If i change $point_at_infinity in polygon->isInside() to be 10000000 vs -10000000 as it is originally then it works correctly, HOWEVER this causes failures in other scenario's that would normally work.

I'm not certain what the problem is as i haven't gone as far as understanding the maths behind it, but i can't seem to get it working correctly in all situations regardless of what i try

  2. Re: isPolyInside failing   Reply   Report abuse  
Picture of Andy Burton
Andy Burton
2013-07-08 11:48:30 - In reply to message 1 from Andy Burton
For the help of anyone else in the future i've debugged this and altering the polygon->ints method to re-calculate and check the intersection after the perturb method has been called seems to do the job in all scenario's that i've tested.

  3. Re: isPolyInside failing   Reply   Report abuse  
Picture of Albert Ang
Albert Ang
2014-03-05 10:15:24 - In reply to message 2 from Andy Burton
Hi Andy, I think I encountered similar problem. How do you go about changing the original ints function?