note 42390 added to function.imageline
| From: | ruturaj_v at yahoo dot com | Date: | Fri, 14 May 2004 12:48:23 +0000 |
| Subject: | note 42390 added to function.imageline | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69606@lists.php.net to get a copy of this message | ||
here is a function that helps you create arrows...
<?php
function get_arrowheads ($x1, $y1, $x2, $y2, $arrhead, $arrang) {
$debug = false;
define("INFINITE", 'INFINITE');
if (($x2-$x1)==0) {
if ($y1 == 0) {
$slope = 0;
} else {
$slope = INFINITE;
}
} else {
$slope = -($y2-$y1)/($x2-$x1);
}
//$slope = number_format($slope, 2, '.','');
if ($slope == 'INFINITE') {
$ang = 90;
} else {
$ang = atan ($slope);
$ang = ($ang * 180)/pi();
}
//$ang = number_format($ang, 2, '.', '');
//echo ($ang);
//exit;
//convert the angle
$arrang1 = ($ang - $arrang);
$arrangdeg1 = ($ang - $arrang);
//echo ($arrang1);exit;
$arrang1 = ($arrang1*pi())/180;
$arrang2 = ($ang + $arrang);
$arrangdeg2 = ($ang + $arrang);
$arrang2 = ($arrang2*pi())/180;
//echo ($arrang1);
$arx1 = (floor(cos($arrang1)*$arrhead));
$ary1 = (floor(sin($arrang1)*$arrhead));
$arx2 = (floor(cos($arrang2)*$arrhead));
$ary2 = (floor(sin($arrang2)*$arrhead));
if ($debug) {
echo ("Values of arx1.. before add/sub</br>");
echo ("$arx1,$ary1 $arx2,$ary2</br>");
}
if ($ang==0) {
if ($x2 > $x1) {
$arx1 = $x2 - $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 - $ary2;
} elseif ($x2 < $x1) {
$arx1 = $x2 + $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 + $arx2; $ary2 = $y2 - $ary2;
}
}
if ($ang > 0 && $ang < 90) {
if (($x2 > $x1) && ($y2 < $y1)) {
$arx1 = $x2 - $arx1; $ary1 = $y2 + $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 + $ary2;
} elseif (($x2 < $x1) && ($y2 > $y1)) {
$arx1 = $x2 + $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 + $arx2; $ary2 = $y2 - $ary2;
}
}
if ($ang==90) {
if (($y2 > $y1)) {
$arx1 = $x2 - $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 - $ary2;
} elseif (($y2 < $y1)) {
$arx1 = $x2 - $arx1; $ary1 = $y2 + $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 + $ary2;
}
}
if ($ang > -90 && $ang < 0) {
if (($x2 > $x1) && ($y2 > $y1)) {
$arx1 = $x2 - $arx1; $ary1 = $y2 + $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 + $ary2;
} elseif (($x2 < $x1) && ($y2 < $y1)) {
$arx1 = $x2 + $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 + $arx2; $ary2 = $y2 - $ary2;
}
}
if ($debug) {
echo ("Angle of line is (".$ang*180/pi().")</br>");
echo ("Angle of line1 is $arrangdeg1</br>");
echo ("Angle of line2 is $arrangdeg2</br>");
echo ("$arx1,$ary1 $x2,$y2</br>");
echo ("$arx2,$ary2 $x2,$y2");
exit;
}
$array_arrows = array (
'x1' =>$arx1,
'y1' => $ary1,
'x2' => $arx2,
'y2' => $ary2
);
return $array_arrows;
}
$x1 = 200; $y1 = 200;
$x2 = 400; $y2 = 100;
$arrhead = 15; //10px
$arrang = 10; //10 deg
$ar_arrws = get_arrowheads ($x1, $y1, $x2, $y2, $arrhead, $arrang);
$im = imagecreate (400, 400);
$w = imagecolorallocate ($im, 255, 255, 255);
$red = imagecolorallocate ($im, 255, 0, 0);
//creates the base line
imageline ($im, $x1, $y1, $x2, $y2, $green);
imageline ($im, $x1+1, $x2+1, $y1+1, $y2+1, $red);
imageline ($im, $x2, $y2, $ar_arrws['x1'], $ar_arrws['y1'], $green);
imageline ($im, $x2, $y2, $ar_arrws['x2'], $ar_arrws['y2'], $green);
?>
----
Manual Page -- http://www.php.net/manual/en/function.imageline.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42390
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42390&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42390&report=yes
Search -- http://master.php.net/manage/user-notes.php