note 95472 added to function.imageantialias
| From: | verdy_p at wanadoo dot fr | Date: | Mon, 04 Jan 2010 21:27:39 +0000 |
| Subject: | note 95472 added to function.imageantialias | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164641@lists.php.net to get a copy of this message | ||
There's a minor edit bug in those lines in the fast algorithm ("20 times faster"):
imageLine( $img, $cx + $ix, $cy + $iy - 1, $cx + $ix, $cy + $ix, $fill );
imageLine( $img, $cx + $ix, $cy - $iy + 1, $cx + $ix, $cy - $ix, $fill );
imageLine( $img, $cx - $ix, $cy + $iy - 1, $cx - $ix, $cy + $ix, $fill );
imageLine( $img, $cx - $ix, $cy - $iy + 1, $cx - $ix, $cy - $ix, $fill );
imageLine( $img, $cx + $iy - 1, $cy + $ix, $cx + $ix, $cy + $ix, $fill );
imageLine( $img, $cx + $iy - 1, $cy - $ix, $cx + $ix, $cy - $ix, $fill );
imageLine( $img, $cx - $iy + 1, $cy + $ix, $cx - $ix, $cy + $ix, $fill );
imageLine( $img, $cx - $iy + 1, $cy - $ix, $cx - $ix, $cy - $ix, $fill );
the reference to "$ix" in the parameters of each call (just before the ", $fill
" parameter) should be sometimes "$iy".
This algorithm uses the Bresenham midpoint algorithm for circles, but computing successive pixels
positions ($ix, $iy) incrementally in the first octant, relative to the circle center ($cx, $cy),
then applying the 8 symetries by swapping them or changing signs.
A similar algorithm exists for ellipses: it uses quadrants symetries instead of octants when the
ellipse focal axis is aligned or orthogonal to the two image axis, be subdividing each quadrant in
two regions (deminited by the point on the arc where the tangent has a unitary slope).
For general ellipses (rotated arbitrarily in the plane), there are also 4 quadrants symetries, but
they are a bit more complex to compute, as you need to compute the rotations, for this reason
you'll only be able to use 2 symetries, but the incremental algorithm still exists: you may
think that this would be based on the evaluation of the sum of lengths from the two focal points,
which is contant; however the sum of two distance cannot be squared so easily (you would need to
compute the square of both distances, then take their respective square root before adding them and
testing the difference with the exact length. A cleaner solution uses NURBS (Non-Uniform Rational
B-splines) because they are numerically stable and still very fast to compute (you only need some
floatting point for the knot constants that separate each quadrant, which is then computed using a
simple quadratic parametric equation of the ellipse instead of the implicit equation, given that the
quadratic (polynomial) equation has first and scond derivatives that are easy to bound in order to
get the needed precision and reduce the number of unnecessary pixel plots : such the parametric
eqaution will draw points along the arc with a movement speed varying between 1 and 4 subpixel
distance per incremental step, but in fact only between 1 and 2 subpixels when you subdivide the
quadrant in two regions).
Alternatively, you may also draw an antialised "straight" ellipse with a double
resolution, and then rotate the antiliased image while also rescale it at half size, and at the same
time combining it to the target: depending on implementations (and computing language used), it may
be faster (but it may require more memory for the intermediate image at scale 2)...
----
Server IP: 69.147.83.197
Probable Submitter: 79.82.50.170
----
Manual Page -- http://www.php.net/manual/en/function.imageantialias.php
Edit -- https://master.php.net/note/edit/95472
Del: integrated -- https://master.php.net/note/delete/95472/integrated
Del: useless -- https://master.php.net/note/delete/95472/useless
Del: bad code -- https://master.php.net/note/delete/95472/bad+code
Del: spam -- https://master.php.net/note/delete/95472/spam
Del: non-english -- https://master.php.net/note/delete/95472/non-english
Del: in docs -- https://master.php.net/note/delete/95472/in+docs
Del: other reasons-- https://master.php.net/note/delete/95472
Reject -- https://master.php.net/note/reject/95472
Search -- https://master.php.net/manage/user-notes.php