function lathe_polygons ($equation, $start_x, $end_x, $detail
{
$degrees = 360/$detail
$step = ($end_x$start_x)/$detail
$max_y = 0;
for ($ii=0;$ii<=$detail$ii++) {
$x = $start_x+($ii$step);
$y0 = evaluate_for_x$equation, $x);
if (!is_nan$y0) && !is_infinite$y0)) {
if ($y0 > $max_y) $max_y = $y0
for ($jj=0;$jj$detail$jj++) {
$y = $y0 * sindeg2rad$degrees$jj));
$z = $y0 * cosdeg2rad$degrees$jj));
// the top of the shape
/*if ($ii==0) {
$sides[-1][] = $x;
$sides[-1][] = $y;
$sides[-1][] = $z;
}*/
// the bottom of the shape
/*if ($ii==$detail) {
$sides[-2][] = $x;
$sides[-2][] = $y;
$sides[-2][] = $z;
}*/
// the sides of the shape
if ($ii$detail) {
$poly = $ii$detail$jj+1;
$sides$poly][6] = $x
$sides$poly][7] = $y
$sides$poly][8] = $z
$poly = $ii$detail+(($jj$detail-1) % $detail)+1;
$sides$poly][9] = $x
$sides$poly][10] = $y
$sides$poly][11] = $z
}
// the sides of the shape
if ($ii>0) {
$poly = ($ii-1)*$detail$jj+1;
$sides$poly][3] = $x
$sides$poly][4] = $y
$sides$poly][5] = $z
$poly = ($ii-1)*$detail+(($jj$detail-1) % $detail)+1;
$sides$poly][0] = $x
$sides$poly][1] = $y
$sides$poly][2] = $z
}
}
}
}
$sides = array_values$sides);
return $sides
}