用户评论:
rod-php at thecomplex dot com (2002-10-01 10:32:02)
function pdf_arrow ($pdfobj, $x1, $y1, $x2, $y2, $dashed) {
// This function will draw, stroke, and fill a line
// from (x1,y1) to (x2,y2) with an arrowhead defined
// by $headangle (in degrees) and $arrowlength.
// If $dashed is nonzero, a dashed line is drawn.
// REQUIRES: find_angle
$headangle = 20;
$arrowlength = 20;
list ($angle, $slope) = find_angle($x1, $y1, $x2, $y2);
pdf_moveto($pdfobj, $x2, $y2);
// Find the two other points of the arrowhead
// using $headangle and $arrowlength.
$xarrow1 = $x2+cos(deg2rad(180+$angle+$headangle/2))*$arrowlength;
$yarrow1 = $y2+sin(deg2rad(180+$angle+$headangle/2))*$arrowlength;
$xarrow2 = $x2+cos(deg2rad(180+$angle-$headangle/2))*$arrowlength;
$yarrow2 = $y2+sin(deg2rad(180+$angle-$headangle/2))*$arrowlength;
// Draw two legs of the arrowhead, close and fill
pdf_lineto($pdfobj, $xarrow1, $yarrow1);
pdf_lineto($pdfobj, $xarrow2, $yarrow2);
pdf_closepath($pdfobj);
pdf_fill($pdfobj);
// Find the point bisecting the short side
// of the arrowhead. This is necessary so
// the end of the line doesn't poke out the
// beyond the arrow point.
$x2line = ($xarrow1+$xarrow2)/2;
$y2line = ($yarrow1+$yarrow2)/2;
// Now draw the "body" line of the arrow
if ($dashed != 0) {
pdf_setdash($pdfobj,5,5);
}
pdf_moveto($pdfobj, $x1, $y1);
pdf_lineto($pdfobj, $x2line, $y2line);
pdf_stroke($pdfobj);
}
rod-php at thecomplex dot com (2002-10-01 10:20:38)
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);
}
rod-php at thecomplex dot com (2002-10-01 10:18:50)
function find_length ($x1, $y1, $x2, $y2) {
// Find distance between two points (x1,y1) and (x2,y2)
// Also useful to find length of a line.
return sqrt( pow($x2-$x1,2) + pow($y2-$y1,2) );
}