note 12212 deleted from function.imagearc by didou

From: Date: Thu, 29 May 2003 18:47:55 +0000
Subject: note 12212 deleted from function.imagearc by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-49271@lists.php.net to get a copy of this message
Note Submitter: nojer2@yahoo.com ---- This function draws rotated ellipses (with a bonus triangle function below): function rotatedellipse($im, $centrex, $centrey, $width, $height, $rotateangle, $colour, $filled=true) { $step=2; $cosangle=cos(deg2rad($rotateangle)); $sinangle=sin(deg2rad($rotateangle)); $diff = $width-$height; $px=$centrex; $py=$centrey; for ($angle=0; $angle<=(360+$step); $angle+=$step) { if ($angle<180) { $angleFromMajorAxis=$angle; } else { $angleFromMajorAxis=360-$angle; } $wibblecoefficient = 0.0; $radiusmodifier = 0.5 - (0.5 * cos(deg2rad(2*$angleFromMajorAxis)) ) - ($wibblecoefficient * sin(deg2rad(4*$angleFromMajorAxis)) ); $radius = $width - ($diff * $radiusmodifier); $ox = ($radius * cos(deg2rad($angle))); $oy = ($radius * sin(deg2rad($angle))); $x = $centrex + (($ox * $cosangle) - ($oy * $sinangle)); $y = $centrey + (($ox * $sinangle) + ($oy * $cosangle)); if ($filled) { triangle($im, $centrex, $centrey, $px,$py, $x,$y, $colour); } else { imageline($im, $x, $y, $px, $py, $colour); } $px=$x; $py=$y; } } function triangle($im, $x1,$y1, $x2,$y2, $x3,$y3, $colour) { $coords = array($x1,$y1, $x2,$y2, $x3,$y3); imagefilledpolygon($im, $coords, 3, $colour); } Unfortunately the curves come out slightly wrong. The 'wibblecoefficient' was my attempt to correct it (doesn't work, but it's fun to play with) Perhaps someone can suggest a better formula for the 'radiusmodifier'

« previous php.notes (#49271) next »