1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Posts
2
Rep Power
0

#### Shapes in PPM

Hey guys! I'm currently working on a project where I have to create shapes in a PPM file, obviously using code only. Boxes are easy, but how would I do, say, a circle? A triangle? Another random shape? I really want to put a circle in there.

I know. It's really easy. But I'm still learning. Also, since I'm learning, is there a way in which you could do it uncomplicated? Because if I were to use really crazy functions and stuff, something would look amiss.

Thanks guys!
2. If you google for Bresenham's Algorithm, you may find what you need.
3. An easy method, but computationally expensive:

associate each point in a 2D array with Cartesian x,y.

You might scale the indexes of H by W array to -1, 1.

Then for each index pair compute the formula value. If the equation is satisfied set the array value to 1.

For a circle assume you've made a linear map from indexes row, col to floating x, y.
Code:
`array[row][col] = radius == sqrt(pow(x-x0,2)+pow(y-y0,2))`
This, of course, won't plot any points whatsoever for any but contrived examples. Instead, compute points within an annular region.

Code:
```    /* a: annular width */
/* d: distance from circle center to this point in the array */