Search code examples
postscript

Rotate in Postscript with center of object as reference


Assume that I have a square object in postscript. How do I rotate the square with the center of the square as the reference angle, instead of the bottom left corner of the square ?


Solution

  • Assuming your square is still being plotted from its lower left corner, then Ken's comment gives the general idea, but also you'll need to undo the translation after rotating.

    /Sq {0 0 moveto 0 100 lineto 100 100 lineto 100 0 lineto closepath} def
    
    gsave
    
    50 50 translate
    45 rotate
    -50 -50 translate
    Sq stroke
    
    grestore