## enlightenment-devel

 [E-devel] drawing circles. From: ronny abraham - 2002-08-25 23:01:22 ```Hi, I've only browsed through the Evas code, and that was a while ago, so I don't know if you have this in the new code. In any case, I think people will get a kick out of this. I found the code in "mathematical elements for computer graphics" by rogers & adams. pg 215-16 Anyway, I'm going to go through the math of it, so just bear with me. I'll try to paraphrase as much as I can, but their style is very concise, so there isn't much I can do to improve on it. given a circle of radious r x = rcos(theta) y = rsin(theta) 0 <= theta <= pi assume a fixed number of points equally spaced apart are used to represent the circle delta_theta = 2 * pi/num_points the intial points are: x_0 = rcos(0) y_0 = rsin(0) from that you can do this: x_i+1 = rcos( theta_i + delta_theta ) y_i+1 = rsin( theta_i + delta_theta ) where theta_i is the angle we used for the last points ( x_i and y_i )we got. x_i+1 and y_i+1 are the current points we're trying to find. sum of angles formula gives us: x_i+1 = r( cos(theta_i) cos(delta_theta) - sin(theta_i) sin(delta_theta) ) y_i+1 = r( cos(theta_i) sin(delta_theta) - cose(delta_theta) sin(theta_i) ) if we take the original equations, with theta as theta_i x_i = rcos(theta_i) y_i = rsin(theta_i) we then get: x_i+1 = x_i * cos( delta_theta ) - y_i * sin(delta_theta) y_i+1 = y_i * sin( delta_theta ) - y_i * cos(delta_theta) the nifty thing about all this, is that you only need to compute: delta_theta cos(delta_theta) sin(delta_theta) ONCE. Which allows us to kick out the time-intensive trig stuff. I think that this makes having a circle function in evas very possible since it's fast. Of course, if it already exists, then at least this email was (hopefully) entertaining. :D ```
 Re: [E-devel] drawing circles. From: Moritz Angermann - 2002-08-26 04:09:49 ```if you talk about evas(2|1) i think you'r right, about evas(1|0.66) i don'T know but i think the Berenham algorithm would be better since it's faster ( when i tryed it ) here is the 'php' source wich should be easily understandable. function circle(\$center_x,\$center_y,\$r,\$color){ global \$img; \$d = 3-(2*\$r); \$y = \$r; for(\$x=0;\$x<=\$y;\$x++){ imagesetpixel(\$img['src'],\$center_x+\$x, \$center_y+\$y, \$color); imagesetpixel(\$img['src'],\$center_x+\$x, \$center_y-\$y, \$color); imagesetpixel(\$img['src'],\$center_x-\$x, \$center_y+\$y, \$color); imagesetpixel(\$img['src'],\$center_x-\$x, \$center_y-\$y, \$color); imagesetpixel(\$img['src'],\$center_x+\$y, \$center_y+\$x, \$color); imagesetpixel(\$img['src'],\$center_x+\$y, \$center_y-\$x, \$color); imagesetpixel(\$img['src'],\$center_x-\$y, \$center_y+\$x, \$color); imagesetpixel(\$img['src'],\$center_x-\$y, \$center_y-\$x, \$color); if(\$d < 0) \$d = \$d + ( 4 * \$x ) + 6; else{ \$d = \$d + 4 * (\$x - \$y) + 10; \$y = \$y -1; } } } i got a same running here: http://mindbox.mine.nu/~ss/imagery.php and there source here: http://mindbox.mine.nu/~ss/imagery_src.php regards On Mon, 2002-08-26 at 00:51, ronny abraham wrote: > > > Hi, I've only browsed through the Evas code, and that was a while ago, > so I don't know if you have this in the new code. In any case, I think > people will get a kick out of this. > > I found the code in "mathematical elements for computer graphics" by > rogers & adams. pg 215-16 > > Anyway, I'm going to go through the math of it, so just bear with me. > I'll try to paraphrase as much as I can, but their style is very > concise, so there isn't much I can do to improve on it. > > > given a circle of radious r > > x = rcos(theta) > y = rsin(theta) > > 0 <= theta <= pi > > > assume a fixed number of points equally spaced apart are used to > represent the circle > > delta_theta = 2 * pi/num_points > > the intial points are: > > x_0 = rcos(0) > y_0 = rsin(0) > > from that you can do this: > > x_i+1 = rcos( theta_i + delta_theta ) > y_i+1 = rsin( theta_i + delta_theta ) > > where theta_i is the angle we used for the last points ( x_i and y_i )we > got. > > x_i+1 and y_i+1 are the current points we're trying to find. > > > sum of angles formula gives us: > > x_i+1 = r( cos(theta_i) cos(delta_theta) > - sin(theta_i) sin(delta_theta) ) > > y_i+1 = r( cos(theta_i) sin(delta_theta) > - cose(delta_theta) sin(theta_i) ) > > > if we take the original equations, with theta as theta_i > > x_i = rcos(theta_i) > y_i = rsin(theta_i) > > we then get: > > x_i+1 = x_i * cos( delta_theta ) - y_i * sin(delta_theta) > y_i+1 = y_i * sin( delta_theta ) - y_i * cos(delta_theta) > > the nifty thing about all this, is that you only need to compute: > > delta_theta > cos(delta_theta) > sin(delta_theta) > > ONCE. > > Which allows us to kick out the time-intensive trig stuff. > > I think that this makes having a circle function in evas very possible > since it's fast. > > Of course, if it already exists, then at least this email was > (hopefully) entertaining. :D > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > enlightenment-devel mailing list > enlightenment-devel@... > https://lists.sourceforge.net/lists/listinfo/enlightenment-devel > -- - Moritz Angermann / mind - ------------------------------------------------------------------- This message is composed of 100% recycled electrons & photons only! ------------------------------------------------------------------- ```
 Re: [E-devel] drawing circles. From: Nathan Ingersoll - 2002-08-26 04:49:31 ```There isn't currently circle/ellipse code in evas, but there is in Imlib2. It uses an algorithm similar to the mid-point ellipse algorithm, but the floating point arithmetic has been transformed to integer. Most likely, something like this is the algorithm that would be used in evas (possibly with an optimization to use a Bresenham like algorithm for circles). RbdPngn --------------------------------------------------------------------------- | Nathan Ingersoll | Computer Science/Mathematics | | mailto: ningerso@... | University of Minnesota-Duluth | | http://umn.edu/~ningerso | http://www.d.umn.edu | --------------------------------------------------------------------------- ```