title: Drawing the slices of a 3D pie chart in the right order
body: <p>I'm trying to fix up an old application: I have a function that takes a pair of angles and draws a 3d slice of an exploded pie chart. I also have functions that take a collection of numbers, generate the angles and call the slice drawing function repeatedly until the entire pie is drawn.</p>
  
  <p>Repeated calls to the slice drawing function draw over the top of existing slices and the order is never quite right. My question is how can I guarantee that the pieces nearest the viewer will be drawn last so the pieces overlap correctly?</p>
  
  <pre><code>function drawSlice(startAngle, endAngle)
    // draws a slice as shown in picture
  
  
  function drawPie(list of angles to make up pie)
    for each angle in angles
      drawSlice(angle)
  
  // example usage
  drawPie([30,15,40,10,5])
  </code></pre>
  
  <p>A slice looks like:
  <a href="http://img233.imageshack.us/img233/2627/slice.png" rel="nofollow noreferrer">alt text http://img233.imageshack.us/img233/2627/slice.png</a></p>