Zend PDF绘制一条曲线

时间:2015-11-20 13:01:28

标签: php pdf zend-framework draw

我目前正试图在zend pdf绘图上绘制一条角线。将尝试尽可能多地解释它。 enter image description here

我到目前为止对于线和箭头的代码如下:

$this->drawArrow($pdf, $xStart + 58.5, $yStart,1, 270); //bottom left  arrow
$this->drawArrow($pdf, $xStart + $leftRake, $yStart + ($leftRake/     tan(deg2rad(abs($leftRake)))) ,1, 157); //top left  arrow
$pdf->drawCircle($xStart, $yStart, 58.5, 0, deg2rad(90 - abs($leftRake)), $fillType); //left angle line 

绘制箭头是我创建的函数:

@param object $pdf The page to draw on
     * @param integer $x Page coordinate for arrow
     * @param integer $y Page coordinate for arrow
     * @param float $scale Default size 1
     * @param integer $angle Arrow angle 90 = up, 180 = right, 270 = down etc
     *
     * @return $pdf Page returned with arrow
     *
     */
    drawArrow($pdf, $x, $y, $scale = 1, $angle)

This is the function for drawCircle:
6.  * Method signatures:
7.  * drawCircle($x, $y, $radius);
8.  * drawCircle($x, $y, $radius, $fillType);
9.  * drawCircle($x, $y, $radius, $startAngle, $endAngle);
10. * drawCircle($x, $y, $radius, $startAngle, $endAngle, $fillType);
11. *
12. *
13. * It's not a really circle, because PDF supports only cubic Bezier
14. * curves. But very good approximation.
15. * It differs from a real circle on a maximum 0.00026 radiuses (at PI/8,
16. * 3*PI/8, 5*PI/8, 7*PI/8, 9*PI/8, 11*PI/8, 13*PI/8 and 15*PI/8 angles).
17. * At 0, PI/4, PI/2, 3*PI/4, PI, 5*PI/4, 3*PI/2 and 7*PI/4 it's exactly
18. * a tangent to a circle.
19. *
20. * @param float $x
21. * @param float $y
22. * @param float $radius
23. * @param mixed $param4
24. * @param mixed $param5
25. * @param mixed $param6
26. * @return Zend_Pdf_Page
27. */
28. public function  drawCircle($x,
29.                             $y,
30.                             $radius,
31.                             $param4 = null,
32.                             $param5 = null,
33.                             $param6 = null);

最接近曲线的是使用绘制圆函数: xstart和ystart变量是角落(左下角) $ leftRake点是一条角度线,该值存储在我的数据库中。

对于drawCircle线,起始角度是底线(0),理想情况下,结束角度应该与对角直线(它在图像中的直线)对齐

我的问题是 - 我似乎无法使顶部箭头与绘制圆圈中的结束角度线相匹配...有什么建议吗?

1 个答案:

答案 0 :(得分:3)

箭头放置问题似乎是三角函数,因为代码看起来很普通。所以目前你有这条线:

$this->drawArrow($pdf, $xStart + $leftRake, $yStart 
+ ($leftRake / tan(deg2rad(abs($leftRake)))) ,1, 157); //top left  arrow

应该是:

$this->drawArrow($pdf, $xStart + (58.5 * cos(deg2rad(abs(90 - $leftRake)))), $yStart 
+ (58.5 * sin(deg2rad(abs(90 - $leftRake)))) ,1, 157); //top left  arrow