You are here

function pSpring::intersect in Visitors 7.2

Same name and namespace in other branches
  1. 7 pChart/class/pSpring.class.php \pSpring::intersect()
1 call to pSpring::intersect()
pSpring::lastPass in pChart/class/pSpring.class.php

File

pChart/class/pSpring.class.php, line 847

Class

pSpring

Code

function intersect($X1, $Y1, $X2, $Y2, $X3, $Y3, $X4, $Y4) {
  $A = ($X3 * $Y4 - $X4 * $Y3) * ($X1 - $X2) - ($X1 * $Y2 - $X2 * $Y1) * ($X3 - $X4);
  $B = ($Y1 - $Y2) * ($X3 - $X4) - ($Y3 - $Y4) * ($X1 - $X2);
  if ($B == 0) {
    return FALSE;
  }
  $Xi = $A / $B;
  $C = $X1 - $X2;
  if ($C == 0) {
    return FALSE;
  }
  $Yi = $Xi * (($Y1 - $Y2) / $C) + ($X1 * $Y2 - $X2 * $Y1) / $C;
  if ($Xi >= min($X1, $X2) && $Xi >= min($X3, $X4) && $Xi <= max($X1, $X2) && $Xi <= max($X3, $X4)) {
    if ($Yi >= min($Y1, $Y2) && $Yi >= min($Y3, $Y4) && $Yi <= max($Y1, $Y2) && $Yi <= max($Y3, $Y4)) {
      return TRUE;
    }
  }
  return FALSE;
}