commons@Sunburn.Stanford.EDU (Peter Commons) (04/13/91)
I'm looking for references, code, algorithms and the like that would help me rotate a 2D polygon or region around its center. It doesn't have to be fast; the better it looks, the preferable it would be. If anyone has any ideas, I would greatly appreciate it. -- Peter Commons commons@cs.stanford.edu Computer Science Department, Stanford University
smoke@well.sf.ca.us (Nicholas Jackiw) (04/15/91)
In article <1991Apr12.225807.6607@neon.Stanford.EDU> commons@Sunburn.Stanford.EDU (Peter Commons) writes: >I'm looking for references, code, algorithms and the like that would help me >rotate a 2D polygon or region around its center. It doesn't have to be fast; >the better it looks, the preferable it would be. If anyone has any ideas, >I would greatly appreciate it. For polygons, apply the following procedure to each vertex. The procedure, for clarity, assumes globals (or lexically superscoped values) CenterX and CenterY, the point about which you wish to rotate, and GlobalRotate, an angle in whatever units your Sin and Cos functions take (probably radians). procedure RotatePt_INT (var aPt: point); var h, v: integer; begin h := aPt.h - CenterX; v := aPt.v - CenterY; aPt.h := trunc(h * Cos(GlobalRotate) + v * Sin(GlobalRotate)) + CenterX; aPt.v := CenterY + trunc(v * Cos(GlobalRotate) - h * Sin(GlobalRotate)); end; If by "regions" you mean authentic QuickDraw regions, good luck. It *is* possible to extract a vertex list from a region, but it will hardly be compact (for non-orthogonal edges, you can count on getting one-vertex per scanline). Alternately, you could simply draw the region into an offscreen bitmap and rotate the bits (Best Of MacTutor has a nifty recursive algorithm for this somewhere). Hope this is the sort of thing you had in mind. > > > >-- >Peter Commons >commons@cs.stanford.edu >Computer Science Department, Stanford University -- --- * --- Nicholas Jackiw Smoke@well.sf.ca.us | Jackiw@cs.swarthmore.edu Key Curriculum Press, Inc. Applelink: D3970 | (415) 548-2304 --- * ---