March 10th, 2013, 11:58 AM

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!
March 10th, 2013, 12:16 PM

If you google for Bresenham's Algorithm, you may find what you need.
March 10th, 2013, 04:05 PM

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(xx0,2)+pow(yy0,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 */
/* r: circle radius */
array[row][col] = (ra/2 < d) && (d < r + a/2);
[code]
Code tags[/code] are essential for python code and Makefiles!