Do you have a question? Post it now! No Registration Necessary
- Subject
- Posted on
- Video circle generator
- 04-21-2006
Re: Video circle generator
As long as you only want one circle, this can be done fairly easily.
For each generated pixel, calculate x^2 + y^2, and compare with r^2. If
smaller than r^2, you're inside the circle, otherwise you're outside.
Updating x^2 + y^2 is simple because you can use the previous result:
(x+1)^2 = x^2 + 2x + 1, so it only involves an addition. r^2 can be
supplied as a pre-calculated parameter.
For multiple circles, you can instantiate multiple copies, and mix the
outputs.
Re: Video circle generator
For a single line, the Y distance from center is known - it's from your
line count - and you know the desired radius so your unknowns are the
leading and trailing edges for either a filled circle or an outline.
X^2+Y^2=R^2 or X = +/-sqrt(r^2-Y^2)
Here you just need to think of the center as 0,0 and make adjustments
accordingly. The calculation only needs to be done once per line rather
than for each generated pixel which means you have a full scan line's
worth of time to do a calculation; serial aritmatic anyone?
If you don't need to ultra-tiny solution, the raw math is pretty simple
in an FPGA with embedded multipliers and a simple square root algorithm.
Re: Video circle generator
Yes, it can. In fact, it doesn't take much logic if you think outside
the box a little bit. Google "Bresenham circle" to find Bresenham's
circle drawing algorithm. No need for multiplies and square
roots...this does it with adds and subtracts by taking advantage of the
incremental algorithm for drawing a circle on a raster.
Re: Video circle generator
Hi Fred,
Circle are in fact very easy to draw (or "scan convert", in the lingo). You
can do it without any square-roots or even multiplies (except by 2). The
algorithm due to Bresenham has been around for some time. Here's a good
tutorial page:
http://www.cs.unc.edu/~mcmillan/comp136/Lecture7/circle.html
The basic algorithm can easily be adapted to do filled circles.
Have a lot of fun,
-Ben-
Circle are in fact very easy to draw (or "scan convert", in the lingo). You
can do it without any square-roots or even multiplies (except by 2). The
algorithm due to Bresenham has been around for some time. Here's a good
tutorial page:
http://www.cs.unc.edu/~mcmillan/comp136/Lecture7/circle.html
The basic algorithm can easily be adapted to do filled circles.
Have a lot of fun,
-Ben-
Re: Video circle generator
If you already have an X and Y register from your video driver, and a
starting-new-line signal, then you can manage with two adders and a
comparator.
Have a register initialised to cx^2+cy^2 at the start of the frame.
At the start of each line, add 2*(y-cy)+1 to the register.
At every pixel, add 2*(x-cx)+1 to the register.
If the register value is less than a threshold, light the pixel,
otherwise don't.
Tom
Site Timeline
- » Using another crystal oscillator..
- — Next thread in » Field-Programmable Gate Arrays
- » is Rocket io complaient with IEEE 802.3ae standard
- — Previous thread in » Field-Programmable Gate Arrays
- » Schematic FPGA Design on twitch
- — Newest thread in » Field-Programmable Gate Arrays
- » What to do with an improved algorithm?
- — Last Updated thread in » Field-Programmable Gate Arrays
- » 3.5mm Klinkenstecker Ersatz -> Empfehlung Bluethooth Audio Modul
- — The site's Newest Thread. Posted in » Electronics (German)
- » Réception réseau Free [FU2 Bricolage]
- — The site's Last Updated Thread. Posted in » Electronics (French)