| 1 |
|
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* The bezier class. Takes four points and draws a bezier curve. |
| 7 |
|
* Based on bezier.class.php by Reza Salehi, zaalion@yahoo.com. |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
class bezier { |
| 11 |
|
function bezier($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3) { |
| 12 |
|
$this->dimx=400; |
| 13 |
|
$this->dimy=400; |
| 14 |
|
$this->br=0; |
| 15 |
|
$this->bg=0; |
| 16 |
|
$this->bb=0; |
| 17 |
|
$this->ar=255; |
| 18 |
|
$this->ag=255; |
| 19 |
|
$this->ab=255; |
| 20 |
|
$this->hasgrid=0; |
| 21 |
|
$this->t_start=0; |
| 22 |
|
$this->t_end=1; |
| 23 |
|
$this->render=0; |
| 24 |
|
$this->step=.01; |
| 25 |
|
$this->x0=$x0; |
| 26 |
|
$this->y0=$y0; |
| 27 |
|
$this->x1=$x1; |
| 28 |
|
$this->y1=$y1; |
| 29 |
|
$this->x2=$x2; |
| 30 |
|
$this->y2=$y2; |
| 31 |
|
$this->x3=$x3; |
| 32 |
|
$this->y3=$y3; |
| 33 |
|
|
| 34 |
|
$this->cx=3*($x1-$x0); |
| 35 |
|
$this->bx=3*($x2-$x1)-$this->cx; |
| 36 |
|
$this->ax=$x3-$x0-$this->cx-$this->bx; |
| 37 |
|
|
| 38 |
|
$this->cy=3*($y1-$y0); |
| 39 |
|
$this->by=3*($y2-$y1)-$this->cy; |
| 40 |
|
$this->ay=$y3-$y0-$this->cy-$this->by; |
| 41 |
|
|
| 42 |
|
$this->function_x='('.$this->ax.')*$t*$t*$t+('.$this->bx.')*$t*$t+('.$this->cx.')*$t+'.$this->x0; |
| 43 |
|
$this->function_y='('.$this->ay.')*$t*$t*$t+('.$this->by.')*$t*$t+('.$this->cy.')*$t+'.$this->y0; |
| 44 |
|
$this->function_z=2; |
| 45 |
|
|
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
//---- some validations. |
| 49 |
|
function zscale() { |
| 50 |
|
return(1); |
| 51 |
|
} |
| 52 |
|
function yscale() { |
| 53 |
|
return(1); |
| 54 |
|
} |
| 55 |
|
function xscale() { |
| 56 |
|
return(1); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
function draw() { |
| 60 |
|
header("Content-type: image/jpeg"); |
| 61 |
|
$image=imagecreate($this->dimx,$this->dimy+20); |
| 62 |
|
$col=imagecolorallocate($image,$this->br,$this->bg,$this->bb); |
| 63 |
|
$col1=imagecolorallocate($image,$this->ar,$this->ag,$this->ab); |
| 64 |
|
$col2=imagecolorallocate($image, 250, 250, 100); |
| 65 |
|
$col3=imagecolorallocate($image, 50, 50, 50); |
| 66 |
|
$grcol=imagecolorallocate($image,8,100,8); |
| 67 |
|
|
| 68 |
|
imageline($image, $this->dimx/2, 0, $this->dimx/2, $this->dimy, $col3); |
| 69 |
|
imageline($image, 0, $this->dimy/2, $this->dimx, $this->dimy/2, $col3); |
| 70 |
|
|
| 71 |
|
imageline($image, $this->x0+$this->dimx/2, -$this->y0+$this->dimy/2, $this->x1+$this->dimx/2, -$this->y1+$this->dimy/2, $col2); |
| 72 |
|
imageline($image, $this->x2+$this->dimx/2, -$this->y2+$this->dimy/2, $this->x3+$this->dimx/2, -$this->y3+$this->dimy/2, $col2); |
| 73 |
|
|
| 74 |
|
imagestring ($image, 2, $this->x0+$this->dimx/2, -$this->y0+$this->dimy/2, 'A', $col1); |
| 75 |
|
imagestring ($image, 2, $this->x1+$this->dimx/2, -$this->y1+$this->dimy/2, 'B', $col1); |
| 76 |
|
imagestring ($image, 2, $this->x2+$this->dimx/2, -$this->y2+$this->dimy/2, 'C', $col1); |
| 77 |
|
imagestring ($image, 2, $this->x3+$this->dimx/2, -$this->y3+$this->dimy/2, 'D', $col1); |
| 78 |
|
|
| 79 |
|
$j = 0; |
| 80 |
|
$colx = $col1; |
| 81 |
|
for ($t = $this->t_start; $t < $this->t_end; $t += $this->step) { |
| 82 |
|
eval('$this->x_points[$j]='.$this->xscale().'*'.$this->function_x.';'); |
| 83 |
|
eval('$this->y_points[$j]='.$this->yscale().'*'.$this->function_y.';'); |
| 84 |
|
eval('$this->z_points[$j]='.$this->zscale().'*'.$this->function_z.';'); |
| 85 |
|
imagearc($image, $this->x_points[$j]+$this->dimx/2, ($this->y_points[$j]*(-1))+$this->dimy/2, $this->z_points[$j], $this->z_points[$j], 0, 360, $colx); |
| 86 |
|
$j++; |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
imagefilledrectangle ($image, 5, $this->dimy-30, $this->dimx/2, $this->dimy+10, $col); |
| 90 |
|
|
| 91 |
|
imagestring ($image, 2, 10, $this->dimy-40, 'start point (A) = ('.$this->x0.','.$this->y0.')', $col1); |
| 92 |
|
imagestring ($image, 2, 10, $this->dimy-28, 'end point (D) = ('.$this->x3.','.$this->y3.')', $col1); |
| 93 |
|
imagestring ($image, 2, 10, $this->dimy-15, 'control 1 (B) = ('.$this->x1.','.$this->y1.')', $col1); |
| 94 |
|
imagestring ($image, 2, 10, $this->dimy-3 , 'control 2 (C) = ('.$this->x2.','.$this->y2.')', $col1); |
| 95 |
|
imagejpeg($image,"",100); |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|