[Math] “Plotting” an equation

algorithmscomputer sciencegraphing-functions

I have an equation like

$$
(x – a)^2 + (y – b)^2 = r^2
$$

that represents a circle.

I need to "plot" it very basically with a programming language. Computer graphics coordinate generally use the "lower-right" quadrant of a Cartesian plane (0, 0 being top left).

I want my circle to have its center in (200, 200) and a radius of, say, 100. All measures given in pixels.

I need to do this step by step, within a loop. So, if the loop is 100 times, i need to know at each iteration at what x and y coordinate to draw a pixel. How to this? With my center and radius, the above equation is like this

$$
(x – 200)^2 + (y – 200)^2 = 1000
$$

but still I can't figure out how to express any "advancement" of my virtual plotting device. Thanks

EDIT

My question specifically asked for the equation of a circle, but it was just an example. I have the same problem with parabolas, sins…

Best Answer

Any reasonably correct method of plotting involves interval arithmetic. At a very rough level, it involves keeping track, for a given resolution, of intervals in which no pixel is part of the plot, intervals in which every pixel is, intervals yet to be analysed, and so on, updating and colouring pixels only when sure.

You can read this very readable paper:

Tupper is the author of the program GrafEq which when I used it many years ago impressed me by getting graphs correctly that most other graphing programs would have trouble with. (See e.g. its rogue's gallery. or other links on the site.) It's a very nice paper. There have presumably been improvements since 2001, but it's shocking how many graphers even today don't even do as much as this paper describes clearly.

Related Question