[comp.sys.mac.programmer] Rotating PICTs or BitMaps by arbitrary angle

mkelly@cs.uoregon.edu (Michael A. Kelly) (11/03/90)

Hello peoples.  Has anyone figured out a fast way to rotate a PICT or
BitMap by an arbitrary angle?  I can figure out how to do it slowly, but
I need to rotate a small (e.g. 40x40) PICT (or BitMap) at least one revolution
per second.

Source code, pseudocode, idle speculation welcome.

Thanks,

Mike.
--
Michael A. Kelly                 | "Fish heads, fish heads,
Internet: mkelly@cs.uoregon.edu  |  Roly-poly fish heads,
America Online: Michael792       |  Fish heads, fish heads,
Compu$erve: 73567,1651           |  Eat them up, yum!"      - Barnes & Barnes

jmunkki@hila.hut.fi (Juri Munkki) (11/04/90)

In article <1990Nov3.122649.12277@cs.uoregon.edu> mkelly@cs.uoregon.edu (Michael A. Kelly) writes:
>
>Hello peoples.  Has anyone figured out a fast way to rotate a PICT or
>BitMap by an arbitrary angle?  I can figure out how to do it slowly, but
>I need to rotate a small (e.g. 40x40) PICT (or BitMap) at least one revolution
>per second.
>
>Source code, pseudocode, idle speculation welcome.

Take a look at UMPG (Usenet Macintosh Programmers' Guide). In this case,
you will find a complete program that will rotate either a bitmap or a
PICT to an arbitrary angle.

Now that the version 1.0 is out, I guess this is good advice to anyone
who needs sample source code or help in Mac programming. Take a look at
the guide first, and then ask for help from this newsgroup.

The guide is available from sumex-aim.stanford.edu with anonymous ftp:
-r   292153 Oct 21 18:21 ./tech/usenet-mac-prog-guide-part1.hqx
-r   291192 Oct 21 18:21 ./tech/usenet-mac-prog-guide-part2.hqx

Another possibility for rotating bitmaps is described in Graphics Gems
by Andrew Glassner (actually edited by him). It describes a method where
you rotate a bitmap by doing three shear operations. This book is just
as vital for graphics programmers as UMPG is for Macintosh programmers.

   ____________________________________________________________________________
  / Juri Munkki	    /  Helsinki University of Technology   /  Wind  / Project /
 / jmunkki@hut.fi  /  Computing Center Macintosh Support  /  Surf  /  STORM  /
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

francis@daisy.uchicago.edu (Francis Stracke) (11/06/90)

In article <1990Nov3.122649.12277@cs.uoregon.edu> mkelly@cs.uoregon.edu (Michael A. Kelly) writes:
>Hello peoples.  Has anyone figured out a fast way to rotate a PICT or
>BitMap by an arbitrary angle?  I can figure out how to do it slowly, but
>I need to rotate a small (e.g. 40x40) PICT (or BitMap) at least one revolution
>per second.

Fastest way to rotate a PICT will probably (depending on how complex)
be to read the actual coordinates it stores & rotate those.
Remember to rotate around the center of the picture, in its own
local coords (i.e., within the rectangle specified in the header).
Formula for rotating ( (x,y) is the old loc., (x0,y0) is the
center, (h,k) is the new loc, th is the angle ):

	h=x0+(x-x0)*cos(th)-(y-y0)*sin(th)
	k=y0+(x-x0)*sin(th)+(y-y0)*cos(th)

(you get this from the sin/cos addition formulae)

I tell you three times: fastest way is to do it beforehand &
store the results!
| Francis Stracke		| My opinions are my own.  I don't steal them.|
| Department of Mathematics	|=============================================|
| University of Chicago		| Non sequiturs make me eat lampshades	      |
| francis@zaphod.uchicago.edu	|   				       	      |