Jump to content

Circles and Computers


Shadow

Recommended Posts

Hey all,

 

While this is a sort of computer oriented problem, I decided to put it in General Mathematics, because the answer to this question will be a math answer. So on we go.

 

When you tell the computer to draw a circle with a diameter x on the screen, it won't draw a perfect circle. Why? Well, let's skip the "Pi is irrational part" for a second. The screen is made of pixels. Pixels are squares. So, ultimately, the shape we see is lots of tiny squares put together so as to form something resembling a circle. But it's not a circle. It's squares. Now here's what I need; how does a computer know, based on the diameter of the circle that we want it to draw, how many squares to draw, and what shape to make? I'm writing a program where I need to be able to say "Okay, the diameter is two (in pixels), so that means that we're going to have 5 squares, and it will look like a plus sign.". So I took a squared paper, and tried to draw the shapes up myself, and to be honest, I'm pretty sure I got 'circles' with diameters three and four (in squares) right, but anything higher than that, and I don't have a clue how it's supposed to look.

 

Could anybody here tell me, given a radius x, how many pixels, or "squares" the computer needs to draw to form the shape we perceive to be a circle? And how that shape looks? Or at least tell me how to draw up the shapes myself, I can calculate the formula from there.

 

Cheers,

 

Gabe

Link to comment
Share on other sites

Your problem is that pixels often aren't truly square. The amount of deviance from square depends on your particular display device. CRT monitors may be able to be calibrated so that they display everything in the correct aspect ratio by altering the controls.

Link to comment
Share on other sites

But the computer doesn't know that. When I send a computer the command to draw a circle, it tells the monitor "Light up this spot, this spot, and that spot". It doesn't care if the spots are square or not. I'm just using square as an approximation. What I need to know is, given a diameter of x, how many and which pixels will "light up"...

 

Cheers,

 

Gabe

Link to comment
Share on other sites

Oh right, somehow I got the idea that you were just complaining it didn't look right.

 

Right, so are you wanting to know how many pixels are contained within the circle, or how many pixels are required to form the perimeter?

 

The number inside the circle will be close to the area of the circle, the number on the perimeter close to the standard calculation for perimeter. These get more accurate as the size of the circle increases, but for the perimeter specifically, you'll tend to get overlapped pixels, maybe missed pixels, depending on how it decides whether to draw them or not.

 

But, I get the feeling you don't really care about that and are just looking for a way to draw a circle, so you need the equation for a circle... http://en.wikipedia.org/wiki/Circle

 

However many high level programming languages have an easy way to do this, whether included in the syntax of the language itself or as part of the standard libraries.

Link to comment
Share on other sites

Nope, I do care about the pixels. That's why I'm asking. I know how to draw a circle, but I don't know how many pixels one will contain. I need to know which pixels overlap, which don't, in other words, how it decides to draw them. I guess it'd be easier for me to say why I need this.

I'm writing a program that simulates stars, specifically how gravity affects their movement. However, at some point, some of them will collide. And, as you can probably guess, simulating the collisions of the stars is not something easy to do. In fact, for a 17 year old with a not-that-powerful computer and not-that-great-programming/physics/whatever knowledge, it's impossible. So I decided to make my own workaround; whenever the stars get close enough, the program starts treating them like lots of small particles. One particle will be one pixel. And here comes the problem; if I have a star with a diameter of x pixels, how many pixels will it contain?

 

Cheers,

 

Gabe

 

EDIT: I've been doing some drawings, based on intuition, and here's what I got:

 

Radii 2-8

 

Radius 9

 

Am I on the right track?

Edited by Shadow
multiple post merged
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.