Skip to content

Instantly share code, notes, and snippets.

@aikar aikar/gist:523938
Created Aug 14, 2010

Embed
What would you like to do?
<?php
function intersectPoint($line1start, $line1end, $line2start, $line2end)
{
$x1 = (double) $line1start['lat'];
$y1 = (double) $line1start['lng'];
$x2 = (double) $line1end['lat'];
$y2 = (double) $line1end['lng'];
$x3 = (double) $line2start['lat'];
$y3 = (double) $line2start['lng'];
$x4 = (double) $line2end['lat'];
$y4 = (double) $line2end['lng'];
$div = (($y4 - $y3) * ($x2 - $x1)) - (($x4 - $x3) *($y2 - $y1));
if(!$div) return null;
$ua = ((($x4 - $x3) * ($y1 - $y3)) - (($y4 - $y3) * ($x1 - $x3))) / $div;
$ub = ((($x2 - $x1) * ($y1 - $y3)) - (($y2 - $y1) * ($x1 - $x3))) / $div;
if($ua >= 0 && $ua <= 1 && $ub >= 0 && $ub <= 1)
{
AppCommUtility::echof("ua $ua ub $ub div $div");
return array(
'lat' => $x1 + ($ua * ($x2 - $x1)),
'lng' => $y1 + ($ua * ($y2 - $y1))
);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.