I wrote a simple code to rotate one point around another, based on this formula.
For some reason, each time this formula is run, the point rotates as expected, but also gradually converges on the center point. I initially had it running in love.update, but I changed it to rotate 30 degrees every time the space bar is pressed, so that I could see more clearly what was happening.
function love.load()
origin = {}
origin.x = 200
origin.y = 200
point = {}
point.x = 100
point.y = 100
end
function love.draw()
love.graphics.circle("fill", origin.x, origin.y, 4)
love.graphics.circle("fill", point.x, point.y, 2)
end
function love.keypressed(key)
if key == "space" then
rotatePoint()
end
end
function rotatePoint()
angle = math.rad(30)
cos = math.cos(angle)
sin = math.sin(angle)
point.x = cos * (point.x - origin.x) - sin * (point.y - origin.y) + origin.x
point.y = sin * (point.x - origin.x) + cos * (point.y - origin.y) + origin.y
end