Subj : Re: fill in a segment of a circle on a graph To : comp.programming From : Willem Date : Mon Sep 05 2005 05:22 pm aiiadict@gmail.com wrote: ) hi, ) ) segment of circle = 45degree (constant) "pie slice" ) radius of circle = variable, and known ) angle = variable and known (this the angle of line running through ) center of the pie slice, the slice extending 22.5 degrees to each side ) of this line) ) ) ) goal: ) ) 0,0 on a graph is the center of the circle ) ) input: ) ) 1)angle = 0 degrees for example, compass direction North ) 2)radius (30, for example) ) ) what coordinates would be included in this slice? ) ) I want the coordinates of all cells outlined by the circle segment. ) ) I could draw the arc, and the edges of the slice, and then use ) some sort of fill routine. I thought perhaps someone here would ) know a neat algorithm. ) ) Bresenhams algorithm looks like it would work, but I haven't ) figured out the code yet. Trying to get it to do any segment ) of an arc is taking me a while to figure out. If you can draw the arc and the edges, you can do a walk around the edge. You need a list a 'left' and a 'right' for each x line. At every crossing of an x line, store the current y coordinate. Then, at the end, walk the list and draw x lines from 'left' to 'right'. (Yes that's a fill routine.) Alternatively, you could iterate over all coordinates (within a bounding box) and check them against the three simple equations for the three bounding lines. You can optimize this by making a skewed box that follows the left side of the shape as closely as possible, and by stopping the iteration of a scanline as soon as you jump from 'inside' to 'outside'. Dunno which is faster. SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT .