Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Custom circle function

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 8th Dec 2005 10:17
I didn't like the normal circle command because you couldn't fill it in or change the thickness of the line. So here's one that I made. (read the instructions when you run it)



Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Dec 2005 19:29 Edited at: 8th Dec 2005 19:30
It's not that I want to break down your code, but I think I found kindof a faster algorithm.

What you do, is going off the whole boxed area of the circle and check for every point if the point is on the circles line. However, small circles are good, but when going to big circles, this causes a major slowdown.

So, I started searching. What if we worked with lines? Boxes are out of the question because we have to deal with an empty centre. (Not for filled circles). Ok, this works. And it can even faster. As you know, a circle has infinite symmetry-axes, wich allows us to do only 1 calculation for the 4 quadrants and quadruple speed.

The algorithm:
- go off the i from center to radius.
- find the height with the calculation sqrt(rad^2 - i^2). This is used in every loop anyway.
- if i < r - t or in other words, the smaller circle "hole", then you have to create a broken line.
The smaller height will be sqrt(srad^2 - i^2) which will never be negative because i has to be smaller than r - t.
- else, you can draw a complete line from height to -height.



The filled circle code looks like it but is much faster and shorter. (Also off topic so I wont post it )

Immunity and Annihalation makes Immunihalation...
MonoCoder
18
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 13th Dec 2005 18:22
Thanks, Zotoaster and Sven B, once again I'm that much closer to making an effective painting package. Does anyone know how... no wait, best not.

I am paranoid. No more can I say.

Login to post a reply

Server time is: 2024-11-23 10:31:05
Your offset time is: 2024-11-23 10:31:05