Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

81 lines (65 sloc) 2.096 kb
function point($x, $y) {
return array(0=>$x, 1=>$y);
function intersect($A, $B, $C, $D) {
$Ax = $A[0]; $Ay = $A[1];
$Bx = $B[0]; $By = $B[1];
$Cx = $C[0]; $Cy = $C[1];
$Dx = $D[0]; $Dy = $D[1];
// Fail if either line is undefined.
if ($Ax==$Bx && $Ay==$By || $Cx==$Dx && $Cy==$Dy) return NO;
// (1) Translate the system so that point A is on the origin.
$Bx-=$Ax; $By-=$Ay;
$Cx-=$Ax; $Cy-=$Ay;
$Dx-=$Ax; $Dy-=$Ay;
// Discover the length of segment A-B.
// (2) Rotate the system so that point B is on the positive X axis.
$Cy =$Cy*$theCos-$Cx*$theSin; $Cx=$newX;
$Dy =$Dy*$theCos-$Dx*$theSin; $Dx=$newX;
// Fail if the lines are parallel.
if ($Cy==$Dy) return NO;
// (3) Discover the position of the intersection point along line A-B.
// (4) Apply the discovered position to line A-B in the original coordinate system.
return(point($X, $Y));
// Returns array($top, $bottom, $inside, $outside)
function van_der_graaf($width, $height) {
$T = intersect(
point(0-$width, $height),
point($width, 0),
point(0, 0),
point($width, $height)
$K = intersect(
point(0, 0),
point($width, $height),
point(0-$T[0], $T[1]),
point($T[0], 0)
$O = intersect(
point($width, $K[1]),
point(0-$width, $height),
point($width, 0)
$B = intersect(
point(0, 0),
point($width, $height),
point($O[0], $height)
$top = $K[1];
$bottom = $height-$B[1];
$inside = $K[0];
$outside = $width-$B[0];
return array($top, $bottom, $inside, $outside);
Jump to Line
Something went wrong with that request. Please try again.