non-solid circles
BlitzMax Forums/BlitzMax Beginners Area/non-solid circles
| ||
I posted a question awhile back about making non-solid ovals,Here's code for making circles if anybody is interested.Graphics 640, 480 For angle = 0 To 359 x = 50 * Sin(angle) y = 50 * Cos(angle) Plot x + 320, y + 240 Next flip WaitKey() End Later, mudcat |
| ||
Yup I used to do it as x = 50*Cos(angle) and use the Sin for Y, but it's all the same. |
| ||
You also have to bare in mind that this is a dotted circle, not a continuous outline. |
| ||
For speed (but I don't think we will notice any increment...) you could use thisGraphics 640, 480 For angle = 0 To 179 x1 = 50 * Sin(angle) y1 = 50 * Cos(angle) x2 = 50 * Sin(angle+180) y2 = 50 * Cos(angle+180) Plot x1+ 320, y1+ 240 Plot x2 + 320, y2+240 Next Flip WaitKey() End You could improve the performace calculating 1/4 (90 degree) and so on |
| ||
There isnt any point calculating the Cos and Sine twice when those x and y coordinates are going to be an exact mirror of each other in some way (ie simmetrical). Have a look at this routine, it's fast and doesn't have gaps in it like the above routines would with larger radius. http://www.blitzbasic.com/codearcs/codearcs.php?code=1476 |
| ||
many thanks - it was just a suggestion to speed up things as Mudcat started with sin & cos math. In any case the solution you linked is faster! |
| ||
I am not expert but I suggest not to use sin() or cos() or any trigonometry if your program heavily calls them. Instead check this forum from AngelDaniel about non-floating point circle. Generally, all of these come from Bresenham algorithm. Search for Bresenham and you will find lots of good info how to avoid trigonometry or floating point operation that are expensive for CPU. http://www.blitz basic.com/Community/posts.php?topic=51749&hl=bresenhamo |
| ||
I don't know if the one I did is a Bresenham tecnique. As far as I know it is referred to as a Mid Point Circle Algorithm. I know that Bresenham is responsible for an integer-math-based line drawing algorithm, but not sure whether that one is to his credit or someone else. It should be faster though. You definitely want to avoid all those sin's and cos's despite the fact that some other well informed people have suggested that these are really fast on modern cpu's. I'm sure they can't be AS FAST as pure integer math, also avoiding all the multiplies, etc. |
| ||
If you have written that code for line, circle, without using Bresenham mid point idea, I realy admire you. Actually, your shl idea is great, a shrinking rectangle, I guess. I've never seen that in Bresenham's variations. |
| ||
I didnt write the code, mostly it is translated from an original pascal program. I modified a few bits, like the shifts or whatever, but that's for rendering purposes mainly. |