php __line,PHP Draw a line

用户评论:

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) );

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值