# PHP help needed for 3D pie charts.November 8, 2004 9:25 AM   Subscribe

I'm writing some php functions to produce graphics of 3D pie charts. I don't remember enough trig to actually pull this off. [more inside]

First - Yes, I know JpGraph does this. But I'd really prefer to do it the hard way.

I'm well versed in how to create graphics with php, but I lack enough knowledge of trig to even know where to look for the equation I need. Googling has led me to several good sites with trig tutorials, but I don't want or need to spend the next week relearning trig just to get one equation.

I need to solve:

I know the height, width, and center point of an ellipse. I need to know the coordinates of an arbitrary point on that ellipse if I know the angle of a line running from the center to that point.

I'm sure I could Google for that, or go down to the book store and look it up, but I don't even know what it's called. Please help. Pointers to what I'm looking for would be great. Ditto for advise on other trig stuff I need but don't know it.
posted by y6y6y6 to Computers & Internet (7 answers total)

Sounds like you want the equation for an ellipse in polar coordinates. As I remember it's pretty messy.
posted by cardboard at 9:28 AM on November 8, 2004

Mathworld.
Equations 19-21 looks like the right ones, though I just skimmed.
posted by cardboard at 9:30 AM on November 8, 2004

it's easiest to work on a circle and then squash it to the ellipse later by just scaling y. that doesn't answer your question directly, but if you look at your code, you'll be able to rewrite it pretty simply.

just do everything as for a circle, with points (x,y), then plot at points (x, 0.9*y) or (x, 0.8*y) or whatever you want to get the ellipse shape you like (you can put this scaling inside routines that do the actual plotting and then all your code just works with easy circles).
posted by andrew cooke at 9:34 AM on November 8, 2004

(in which case, of course, if the angle is theta (measured anti-clock from x axis) and the centre at (ox, oy) and the radius r, then the point you are asking for is (ox+r*cos(theta),oy+r*sin(theta)) and if you wanted ellipses with a minor radius half the major radius then you'd plot a point at (ox+r*cos(theta),oy+0.5*r*sin(theta)) assuming that you want the ellipse centred at (ox,oy) and not (ox,0.5*oy) (so you only scale y relative to oy).

does that make sense?
posted by andrew cooke at 10:25 AM on November 8, 2004

)
posted by andrew cooke at 10:26 AM on November 8, 2004

Got it.