Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.graphics Subject: Re: looking for a fast ellipse algorithm Message-ID: <446@lakart.UUCP> Date: 28 Feb 89 15:00:17 GMT References: <12374@dartvax.Dartmouth.EDU> Organization: Lakart Corporation, Newton, MA Lines: 50 earleh@eleazar.dartmouth.edu (Earle R. Horton) sez: > I would like to see an ellipse algorithm which allows me to > specify the axes of the ellipse as something other than horizontal and > vertical. Something like this: > > - __/ > - / /\ > -/ / / > / / /- > \_/_/ - > / - > / minor axis > major axis > > Anybody got one? OK - now let's see. It's about 15 years since I did this in high school. To rotate points in (x, y) space about the origin through an angle a, you need to take the vector (x, y) and multiply it by the matrix. ( cos(a) -sin(a) ) ( sin(a) cos(a) ) i.e. transfer the point to: x' = cos(a) * x - sin(a) * y y' = sin(a) * x + cos(a) * y This rotates about the origin, to rotate about another point (p, q), you need to add some constant (I think it's -1 * where (p, q) gets transformed to) So assuming I'm correct in the above guess, you'd add as follows. x'' = x' - (cos(a) * p - sin(a) * q) y'' = y' - (sin(a) * p + cos(a) * q) NOW since you're rotating by a fixed angle, and doing a fixed transform, you evaluate cos(a) and sin(a), and the constants for the x' to x'' subtraction beforehand, and just do the transform on the fly. Yes, I know it isn't going to win any speed prizes (4 multiplies, 3 adds and a subtract per point), but it should work. >>>>> N.B. <<<<< This is _VERY_ rusty, so anyone can feel free to correct the matrix or the transforms above. The basic theory is sound, it's just that I haven't dug this maths out in a while. (A long while :-) ) -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+