Voting

: eight minus zero?
(Example: nine)

The Note You're Voting On

ruturaj_v at yahoo dot com
21 years ago
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&nbsp;&nbsp;&nbsp;$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&nbsp;&nbsp;&nbsp;$x2,$y2</br>");
echo (
"$arx2,$ary2&nbsp;&nbsp;&nbsp;$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);

?>

<< Back to user notes page

To Top