note 25649 added to function.pdf-lineto

From: Date: Tue, 01 Oct 2002 15:20:38 +0000
Subject: note 25649 added to function.pdf-lineto
Groups: php.notes 
Request: Send a blank email to php-notes+get-37469@lists.php.net to get a copy of this message
function find_angle ($x1, $y1, $x2, $y2) { // This function takes two points (x1,y1) and (x2,y2) // as inputs and finds the slope and angle of a line // between those two points. It returns the angle // and slope in an array. I can't figure out how to // return a NULL value, so if the two input points // are in a vertical line, the function returns // $angle = 90 and $slope = 0. I know this is wrong. if (($x2-$x1) != 0) { $slope = ($y2-$y1)/($x2-$x1); // Get rotation angle by finding the arctangent of the slope $angle = rad2deg(atan($slope)); if ($x1 > $x2) { $angle = 180+$angle; } elseif ($y1 > $y2) { $angle = 360+$angle; } } else { // Vertical line has no slope, 90deg angle $angle = 90; # unset ($slope); $slope = 0; } return array ($angle, $slope); } -- http://www.php.net/manual/en/function.pdf-lineto.php http://master.php.net/manage/user-notes.php?action=edit+25649 http://master.php.net/manage/user-notes.php?action=delete+25649 http://master.php.net/manage/user-notes.php?action=reject+25649

« previous php.notes (#37469) next »