Rotation Around a Point

There are lots of code example that show rotation or a 2D point around the origin but what about around some arbitrary point? This is important if you are translating airfoils into G-Code...

To do a rotation around a point without matrix math you translate the point to rotate around the origin (0,0,0), then rotate the point, and translate it back.

So basically you subtract the location of the rotation point from the x coordinate, rotate the new point, and add the location of the rotation point back.

Here it is in Python

from math import *
def rotate2d(degrees,point,origin):
"""
A rotation function that rotates a point around a point
to rotate around the origin use [0,0]
"""
x = point[0] - origin[0]
yorz  = point[1] - origin[1]
newx = (x*cos(radians(degrees))) - (yorz*sin(radians(degrees)))
newyorz  = (x*sin(radians(degrees)))   (yorz*cos(radians(degrees)))
newx  = origin[0]
newyorz   = origin[1]

return newx,newyorz

Comments

Popular posts from this blog

DIY CNC Milling Machine Control Panel for EMC2

Power Supply for CNC

Maintenance of a 30 Year Old CNC Milling Machine