Skip to content

Instantly share code, notes, and snippets.

@M-Bryant
Last active August 29, 2015 13:56
Show Gist options
  • Save M-Bryant/8946243 to your computer and use it in GitHub Desktop.
Save M-Bryant/8946243 to your computer and use it in GitHub Desktop.
Rotate an xy cooordinate about a specified origin
def RotateXY(x,y,xc=0,yc=0,angle=0,units='DEGREES'):
"""Rotate an xy cooordinate about a specified origin
returning a new xy cooordinate
x,y xy coordinates
xc,yc center of rotation
angle angle
units "DEGREES" (default) or "RADIANS"
"""
import math
x = x - xc
y = y - yc
if units == 'DEGREES':
angle = math.radians(angle)
xr = (x * math.cos(angle)) - (y * math.sin(angle)) + xc
yr = (x * math.sin(angle)) + (y * math.cos(angle)) + yc
return xr, yr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment