Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another small filled circe sub (not as fast as fcirc)
#2
The trick with fcirc is that it takes advantage of a circle's mirror-like properties.  You get one point, you've got 8.


For example, let's imagine a circle 100 pixels tall and 100 pixels wide.  (It's got a radius of 50.)

From the very start, we can see that mirroring at work.  
On the X axis, you're going to go 50 pixels left of the center to plot that first set of circle coordinates. 
You're also going to go 50 pixels right from the center to plot that first set of circle coordinates.
And, on the Y axis, you're going to 50 pixels up to plot a point
and 50 pixels down to plot a point.

Knowing one offset (0 from center), you now easily have 4 points of the circle's perimeter. 

Now, if you go one offset away from center, such as UP one point on the Y-axis, you can calculate the X-point once for the matching coordinate for the triangle with 1 height, 50 hypotenuse, and a 90 degree angle...
That point is valid for 1 pixel up from the center, and right that amount.
That point is also valid for 1 pixel up from the center, and left that amount.
That point is valid for 1 pixel down from the center, and right that amount.
That point is valid for 1 pixel down from the center, and left that amount.
...
And if we inverse our X/Y as we're looking at a perfect mirror here,
That point is valid for 1 pixel right from the center, and up that amount.
That point is also valid for 1 pixel right from the center, and down that amount.
That point is valid for 1 pixel left from the center, and up that amount.
That point is valid for 1 pixel left from the center, and down that amount.

You calculated one math point, and in return, you got 8 circle coordinates!

You're not drawing one line at a time, you're drawing a line in ALL FOUR QUADRANTS at a time.  


Minimum points of calculation needed, so maximum performance.

And that's basically how fcirc works in a butshell.  Wink
Reply


Messages In This Thread
RE: Another small filled circe sub (not as fast as fcirc) - by SMcNeill - 08-28-2024, 06:34 AM



Users browsing this thread: 27 Guest(s)