Пример #1
0
 /**
  * @param Bezier $curve
  * @param $startWidth
  * @param $endWidth
  */
 function addBezier($curve, $startWidth, $endWidth)
 {
     $widthDelta = $endWidth - $startWidth;
     $drawSteps = floor($curve->length());
     //var_dump($drawSteps);
     for ($i = 0; $i < $drawSteps; $i++) {
         // Calculate the Bezier (x, y) coordinate for this step.
         $t = (double) $i / $drawSteps;
         $tt = $t * $t;
         $ttt = $tt * $t;
         $u = 1 - $t;
         $uu = $u * $u;
         $uuu = $uu * $u;
         $x = $uuu * $curve->startPoint->x;
         $x += 3 * $uu * $t * $curve->control1->x;
         $x += 3 * $u * $tt * $curve->control2->x;
         $x += $ttt * $curve->endPoint->x;
         $y = $uuu * $curve->startPoint->y;
         $y += 3 * $uu * $t * $curve->control1->y;
         $y += 3 * $u * $tt * $curve->control2->y;
         $y += $ttt * $curve->endPoint->y;
         // Set the incremental stroke width and draw.
         $color = imagecolorallocate($this->mSignatureBitmap, 255, 0, 0);
         $strokeWidth = $startWidth + $ttt * $widthDelta;
         imagefilledellipse($this->mSignatureBitmap, $x, $y, $strokeWidth / 2.0, $strokeWidth / 2.0, $color);
     }
 }
Пример #2
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_scatter.php';
require_once 'jpgraph/jpgraph_regstat.php';
// Original data points
$xdata = array(1, 3, 12, 15);
$ydata = array(5, 15, 2, 19);
// Get the interpolated values by creating
// a new Spline object.
$bez = new Bezier($xdata, $ydata);
// For the new data set we want 40 points to
// get a smooth curve.
list($newx, $newy) = $bez->Get(50);
// Create the graph
$g = new Graph(300, 200);
$g->SetMargin(30, 20, 40, 30);
$g->title->Set("Bezier interpolation");
$g->title->SetFont(FF_ARIAL, FS_NORMAL, 12);
$g->subtitle->Set('(Control points shown in red)');
$g->subtitle->SetColor('darkred');
$g->SetMarginColor('lightblue');
//$g->img->SetAntiAliasing();
// We need a linlin scale since we provide both
// x and y coordinates for the data points.
$g->SetScale('linlin');
// We want 1 decimal for the X-label
$g->xaxis->SetLabelFormat('%1.1f');
// We use a scatterplot to illustrate the original