Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!cme!cam!miller From: miller@cam.nist.gov (Bruce Miller) Newsgroups: comp.graphics Subject: Re: 3-D Rotation Algorithm Summary: save the trigs Keywords: fixed-point log-base-2 Message-ID: <1315@kar.cam.nist.gov> Date: 11 Oct 89 22:59:37 GMT References: <6734@hubcap.clemson.edu> <15026@bloom-beacon.MIT.EDU> Organization: National Institute of Standards & Technology, Gaithersburg, MD Lines: 33 In article <15026@bloom-beacon.MIT.EDU>, ihaka@diamond.tmc.edu (Ross Ihaka) writes: > In article <6734@hubcap.clemson.edu> bo@hubcap.clemson.edu (Bo Slaughter) writes: > |I have written a program in Turbo Pascal to take a simple line drawing > |and rotate in any of the 3 demensions. ... > |using the simple formula (and variations thereof): > | X'=X*cos(THETA)-Y*sin(THETA) > | Y'=X*sin(THETA)+Y*cos(THETA) > | > |My problem is that this is extremely slow for any medium sized drawing > > Here is a trick you can use to get fast rotations when the angle is small. > Approximation for sin(theta) and cos(theta) > sin(theta) ~ theta > cos(theta) ~ 1 - theta^2 / 2 > ... > xnew = x - (x>>other) - sgn * (y>>l2theta); > ynew = sgn * (x>>l2theta) + y - (y>>other); > Ross Ihaka Forgive me if I'm on the wrong track; no insult intended. If you are calling sine & cosine for *each* point you transform, that is where your problem is. The rotation angles, and hence the sines & cosines of them, are the same for all the points you want to transform, so you should just compute them once and use them many times. On the other hand, if you *have* saved the trig values then your only savings by using the suggested algorithm is that you halve the number of multiplications. But repeating the process for non-infinitesimal angles is likely to eat into the savings, [never mind the fact that repeated applications is actually a spiral and not a rotation... well formally, anyway :)] So, i dont think you gain much for this application, for others definitely. Why dont you go a step further and look up homogeneous transformations in most graphics texts; they are a bit tedious to construct initially, but you can combine all the rotations, translations & scale into one. Bruce