Re: Rotation of 2D graphics
- To: mathgroup at smc.vnet.net
- Subject: [mg26445] Re: Rotation of 2D graphics
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 21 Dec 2000 01:51:47 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <91pjqi$601@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, say you have a 2d matrix m for the rotation and a center c define a function rotate[p:{_?NumericQ,_?NumericQ}]:=c+Dot[m,p-c] and you with to rotate the 2d graphics gr gr /. {Point[p_]:> Point[rotate[p]], h:(Line|Polygon)[pts_]:> h[rotate /@ pts], Text[a_,p_,opt___]:> Text[a,rotate[p],opt} and you graphics is rotated. Put all together with Rotate2D[gr_Graphics, angle_?NumericQ, c : {_?NumericQ, _?NumericQ}] := Module[{m, rotate}, m = N[{{Cos[angle], -Sin[angle]}, {Sin[angle], Cos[angle]}}]; rotate[p : {_?NumericQ, _?NumericQ}] := c + Dot[m, p - c]; gr /. {Point[p_] :> Point[rotate[p]], (h : Line | Polygon)[pts_] :> h[rotate /@ pts], Text[a_, p_, opt___] :> Text[a, rotate[p], opt]} ] Yo still need some rules to rotate ContourGraphics[] and DensityGraphics[] and to transform Disc[] and Cricle[] ... gg=FullGraphics[Plot[Sin[x], {x, -Pi, Pi}] and Show[Rotate2D[gg, -Pi/4, {0, 0}]] will rotate it. Regards Jens Stephen Sheppard wrote: > > I have some graphics generated by showing several 2d plots, and I would like > to be able to spin these about a specified point. This is very easy if > everything has been generated using primitives like Line, Point, etc. What > I would like to be able to do is to take an entire image that can be viewed > using "Show" and rotate it by r radians about the point {x,y}. Something > like: > > Show[%] > > ShowRotate[%,r,{x,y}] > would then produce the graphic with everything (including the axes, labels, > etc.) rotated. > > Any suggestions? I would be happy if this were obvious. > > Stephen Sheppard > Department of Economics > Williams College