Hi I need to plot a pie on an LCD screen as an indicator of time remaing for a process. I have searched around alot on this issue, and have found the midpoint algorithm which I can use to plot a complete circle, both filled and outlined. But I can't find anything on drawing segments. Could someone point to me to information on how to achieve this please. Andrew --------------------------------------- Posted through http://www.EmbeddedRelated.com
Drawing pieslice (segement) on and LCD
Started by ●August 25, 2014
Reply by ●August 25, 20142014-08-25
On Mon, 25 Aug 2014 12:52:25 -0500, ajellis wrote:> Hi > > I need to plot a pie on an LCD screen as an indicator of time remaing > for a process. > > I have searched around alot on this issue, and have found the midpoint > algorithm which I can use to plot a complete circle, both filled and > outlined. But I can't find anything on drawing segments. > > Could someone point to me to information on how to achieve this please.It's not trivial, but it's not something that should be impossible for someone who passed their math classes in college, either. If you're in the circle, AND the angle of the line from the pixel to the center is inside the area to be filled in, fill in the pixel. Otherwise, don't. Alternately, fill in the circle by filling in lines that extend radially from the center outward, and spaced close enough to get full coverage. Fill in with a for-loop that goes from the minimum angle to be filled up to the maximum. You don't mention how much processor time you have to spend on this -- it'll be easy to do with sines and cosines, more complicated if that takes too much time. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●August 25, 20142014-08-25
On 8/25/2014 2:34 PM, Tim Wescott wrote:> On Mon, 25 Aug 2014 12:52:25 -0500, ajellis wrote: > >> Hi >> >> I need to plot a pie on an LCD screen as an indicator of time remaing >> for a process. >> >> I have searched around alot on this issue, and have found the midpoint >> algorithm which I can use to plot a complete circle, both filled and >> outlined. But I can't find anything on drawing segments. >> >> Could someone point to me to information on how to achieve this please. > > It's not trivial, but it's not something that should be impossible for > someone who passed their math classes in college, either. > > If you're in the circle, AND the angle of the line from the pixel to the > center is inside the area to be filled in, fill in the pixel. Otherwise, > don't. > > Alternately, fill in the circle by filling in lines that extend radially > from the center outward, and spaced close enough to get full coverage. > Fill in with a for-loop that goes from the minimum angle to be filled up > to the maximum. > > You don't mention how much processor time you have to spend on this -- > it'll be easy to do with sines and cosines, more complicated if that takes > too much time.I would think the trig method would be a bit more than is needed. Rather than draw many, many lines with a lot of overlap I would think the way to draw a pie chart is to plot the start radius, the end radius, connect with the arc and then use an area fill algorithm. A table lookup can be done to get the endpoint of the radii which only uses trig to generate the table. I haven't looked for an arc generating algorithm but I expect sine/cosine is not needed for that. -- Rick
Reply by ●August 25, 20142014-08-25
On 8/25/2014 10:52 AM, ajellis wrote:> I need to plot a pie on an LCD screen as an indicator of time remaing for a > process. > > I have searched around alot on this issue, and have found the midpoint > algorithm which I can use to plot a complete circle, both filled and > outlined. But I can't find anything on drawing segments. > > Could someone point to me to information on how to achieve this please.What are you looking for: an algorithm to plot a pie slice? or, an algorithm to *fill* a plotted pie slice? Do you need an algorithm that works given *any* initial conditions (initial orientation of the slice, initial "non-zero" percentage complete, etc.)? Does it have to be able to advance in arbitrary increments (always monotonic?)? Does it need to be reoriented after each update (vs. just "building" on what was complete as of the "previous iteration")? Computer graphics algorithms are notoriously clever -- typically by *not* trying to be "general" (e.g., why redraw the 12% portion of the circle from scratch if you are now at 13%?).
Reply by ●August 25, 20142014-08-25
On Mon, 25 Aug 2014 16:40:54 -0400, rickman wrote:> On 8/25/2014 2:34 PM, Tim Wescott wrote: >> On Mon, 25 Aug 2014 12:52:25 -0500, ajellis wrote: >> >>> Hi >>> >>> I need to plot a pie on an LCD screen as an indicator of time remaing >>> for a process. >>> >>> I have searched around alot on this issue, and have found the midpoint >>> algorithm which I can use to plot a complete circle, both filled and >>> outlined. But I can't find anything on drawing segments. >>> >>> Could someone point to me to information on how to achieve this >>> please. >> >> It's not trivial, but it's not something that should be impossible for >> someone who passed their math classes in college, either. >> >> If you're in the circle, AND the angle of the line from the pixel to >> the center is inside the area to be filled in, fill in the pixel. >> Otherwise, don't. >> >> Alternately, fill in the circle by filling in lines that extend >> radially from the center outward, and spaced close enough to get full >> coverage. Fill in with a for-loop that goes from the minimum angle to >> be filled up to the maximum. >> >> You don't mention how much processor time you have to spend on this -- >> it'll be easy to do with sines and cosines, more complicated if that >> takes too much time. > > I would think the trig method would be a bit more than is needed. Rather > than draw many, many lines with a lot of overlap I would think the way > to draw a pie chart is to plot the start radius, the end radius, > connect with the arc and then use an area fill algorithm. A table > lookup can be done to get the endpoint of the radii which only uses trig > to generate the table. I haven't looked for an arc generating algorithm > but I expect sine/cosine is not needed for that.I was trying for something conceptually simple, given that the OP couldn't figure it out for himself. Yes, there's lots of ways to do it that don't involve trig, but do involve more lines of code, more figurin' and actual honest-to-gosh THINKING. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●August 25, 20142014-08-25
>On 8/25/2014 10:52 AM, ajellis wrote: >> I need to plot a pie on an LCD screen as an indicator of time remaingfor a>> process. >> >> I have searched around alot on this issue, and have found the midpoint >> algorithm which I can use to plot a complete circle, both filled and >> outlined. But I can't find anything on drawing segments. >> >> Could someone point to me to information on how to achieve this please. > >What are you looking for: an algorithm to plot a pie slice? or, >an algorithm to *fill* a plotted pie slice? > >Do you need an algorithm that works given *any* initial conditions >(initial orientation of the slice, initial "non-zero" percentage >complete, etc.)? > >Does it have to be able to advance in arbitrary increments (always >monotonic?)? > >Does it need to be reoriented after each update (vs. just "building" >on what was complete as of the "previous iteration")? > >Computer graphics algorithms are notoriously clever -- typically by >*not* trying to be "general" (e.g., why redraw the 12% portion of >the circle from scratch if you are now at 13%?). >Hi everyone, Thank you for your replies. I am using an AT32UC3B0512 microcontroller. I need the algorithm to advance monotonically ie start with a vertical line from the centre of the circle to the outside edge, then to be able to grow in steps of 1° until the circle is complete. Andrew --------------------------------------- Posted through http://www.EmbeddedRelated.com
Reply by ●August 25, 20142014-08-25
On Mon, 25 Aug 2014 17:46:11 -0500, ajellis wrote: [ ... ]> I am using an AT32UC3B0512 microcontroller. > > I need the algorithm to advance monotonically ie start with a vertical > line from the centre of the circle to the outside edge, then to be able > to grow in steps of 1° until the circle is complete.It might work to use the midpoint algorithm to calculate the next undrawn circumferential point. You could guesstimate how much progress that would represent, and when you've progressed that much, use Bresenham's line algorithm to draw a line from the vertex of the pie to that circumferential point. Rinse and repeat. Mel.
Reply by ●August 25, 20142014-08-25
On 8/25/2014 3:46 PM, ajellis wrote:>> On 8/25/2014 10:52 AM, ajellis wrote: >>> I need to plot a pie on an LCD screen as an indicator of time remaing > for a >>> process. >>> >>> I have searched around alot on this issue, and have found the midpoint >>> algorithm which I can use to plot a complete circle, both filled and >>> outlined. But I can't find anything on drawing segments. >>> >>> Could someone point to me to information on how to achieve this please. >> >> What are you looking for: an algorithm to plot a pie slice? or, >> an algorithm to *fill* a plotted pie slice? >> >> Do you need an algorithm that works given *any* initial conditions >> (initial orientation of the slice, initial "non-zero" percentage >> complete, etc.)? >> >> Does it have to be able to advance in arbitrary increments (always >> monotonic?)? >> >> Does it need to be reoriented after each update (vs. just "building" >> on what was complete as of the "previous iteration")? >> >> Computer graphics algorithms are notoriously clever -- typically by >> *not* trying to be "general" (e.g., why redraw the 12% portion of >> the circle from scratch if you are now at 13%?).> I am using an AT32UC3B0512 microcontroller. > > I need the algorithm to advance monotonically ie start with a vertical line > from the centre of the circle to the outside edge, then to be able to grow > in steps of 1° until the circle is complete.Why 1 degree? Why not 1%? How large is the circle (a very large diameter requires more finesse than a smaller one)? How quickly (in calendar time) is the whole process going to happen (i.e., if the whole thing takes 3 seconds, then why other with 1 degree increments that the user will never see in the time it takes for the next update to come along) Ask yourself what you know about circles that can make your job easier! And, how your knowledge of what you have ALREADY DRAWN can be exploited to draw what needs to be ADDED ;-)
Reply by ●August 25, 20142014-08-25
Hi Mel, On 8/25/2014 5:03 PM, Mel Wilson wrote:> On Mon, 25 Aug 2014 17:46:11 -0500, ajellis wrote: > [ ... ] >> I am using an AT32UC3B0512 microcontroller. >> >> I need the algorithm to advance monotonically ie start with a vertical >> line from the centre of the circle to the outside edge, then to be able >> to grow in steps of 1° until the circle is complete. > > It might work to use the midpoint algorithm to calculate the next undrawn > circumferential point. You could guesstimate how much progress that > would represent, and when you've progressed that much, use Bresenham's > line algorithm to draw a line from the vertex of the pie to that > circumferential point. Rinse and repeat.Better to draw from the circumference inward. When you hit a pixel having the color you are drawing, you know you are done -- even if you haven't reached the center! (hand-waving)
Reply by ●August 25, 20142014-08-25
"ajellis" <74158@embeddedrelated> writes:> I need the algorithm to advance monotonically ie start with a vertical > line from the centre of the circle to the outside edge, then to be > able to grow in steps of 1° until the circle is complete.What is the diameter of the circle in pixels? How many different angles do you want to be able to show? That cpu has 512KB of flash, which is a lot. Maybe you can just precompute the coordinates of the circle and store them in a flash table, and similarly the endpoints of the circular segments for each angle you want to draw in one quadrant (say 16 of them) and do some range reduction and reflection for the other quadrants. So that would let you show the "pie" growing in 64 steps. If you want to compute on the fly you can use Bresenham's circle algorithm, or more generally, possibly CORDIC. Or just use some trig library if you don't care about speed and space.







