Video circle generator

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I would like to use a FPGA to create some simple test patterns.  One of
which is a circle with a variable diameter.  I'm not sure where to start.
Can this be realistically be done in an FPGA using minimal resources?



Re: Video circle generator

Quoted text here. Click to load it

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
Quoted text here. Click to load it

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
Quoted text here. Click to load it
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,

Quoted text here. Click to load it

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
Ben Jones schrieb:
Quoted text here. Click to load it
 You
Quoted text here. Click to load it
Not even that because
2(x+1) + 1 = (2x+1) + 2
You need a total of two adders and one comparator per ordinate.

Kolja Sulimma


Re: Video circle generator
Quoted text here. Click to load it

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






Re: Video circle generator

Quoted text here. Click to load it

I greatly appreciate the responses here.  It's made life a great deal
easier!

Many thanks again.



Site Timeline