orbiting object around point using touch (non physics)

i have a formula which allows an object to rotate around a centre point

this works fine, however i now want this to be based on a user dragging the object and it will perform the same orbit but the user will drag the object to make it orbit and it will be locked to this orbit

here is my code

local circleD = 320 local circle = display.newCircle(display.contentWidth/2,display.contentHeight/2,circleD) circle:setReferencePoint(display.CenterReferencePoint) local circleC = math.pi \* circleD       local square = display.newRect(0,0,200,200) square.x, square.y = 320,320 square:setFillColor(100,255,55)       local degrees = 1 function rotate (event)   local rads = degrees \* (math.pi / 180.0)     square.x = display.contentHeight/2 \* math.cos(rads) + (display.contentWidth/-1)     square.y = display.contentHeight/2 \* math.sin(rads) + (display.contentHeight/2)     degrees = degrees + 5     print (square.x, square.y)      end     Runtime:addEventListener("enterFrame", rotate)

I have managed to add a touch event that will do the dragging, but when I add a 2nd square, it will rotate around its own circle and not follow the first square in a snake a like effect.

I need it to follow the first, to give itsĀ  a ferris wheel effect.

local circleD = 320 local circle = display.newCircle(display.contentWidth/2,display.contentHeight/2,circleD) circle:setReferencePoint(display.CenterReferencePoint) local circleC = math.pi \* circleD local squares = display.newGroup() local square = display.newRect(0,0,200,200) square.x, square.y = 320, 600 square:setFillColor(100,255,55) squares:insert(square) local square2 = display.newRect(0,0,200,200) square2.x, square2.y = 320, 320 square2:setFillColor(999,255,55) squares:insert(square2) local function onTouch( event )     local t = event.target     local phase = event.phase     if "began" == phase then         local parent = t.parent         parent:insert( t )         display.getCurrentStage():setFocus( t )         t.isFocus = true         t.x0 = event.x - t.x         t.y0 = event.y - t.y     elseif t.isFocus then         if "moved" == phase then             t.x = event.x - t.x0             t.y = event.y - t.y0                               local degrees = event.y                          local rads = degrees \* (math.pi / 180.0)                 t.x = display.contentWidth/2 \* math.cos(rads) - 100                 t.y = display.contentHeight/2 \* math.sin(rads) - 100                 degrees = degrees + 5                print (square.x, square.y)                                                             elseif "ended" == phase or "cancelled" == phase then             display.getCurrentStage():setFocus( nil )             t.isFocus = false         end     end     return true end squares:addEventListener( "touch", onTouch )  

I have managed to add a touch event that will do the dragging, but when I add a 2nd square, it will rotate around its own circle and not follow the first square in a snake a like effect.

I need it to follow the first, to give itsĀ  a ferris wheel effect.

local circleD = 320 local circle = display.newCircle(display.contentWidth/2,display.contentHeight/2,circleD) circle:setReferencePoint(display.CenterReferencePoint) local circleC = math.pi \* circleD local squares = display.newGroup() local square = display.newRect(0,0,200,200) square.x, square.y = 320, 600 square:setFillColor(100,255,55) squares:insert(square) local square2 = display.newRect(0,0,200,200) square2.x, square2.y = 320, 320 square2:setFillColor(999,255,55) squares:insert(square2) local function onTouch( event )     local t = event.target     local phase = event.phase     if "began" == phase then         local parent = t.parent         parent:insert( t )         display.getCurrentStage():setFocus( t )         t.isFocus = true         t.x0 = event.x - t.x         t.y0 = event.y - t.y     elseif t.isFocus then         if "moved" == phase then             t.x = event.x - t.x0             t.y = event.y - t.y0                               local degrees = event.y                          local rads = degrees \* (math.pi / 180.0)                 t.x = display.contentWidth/2 \* math.cos(rads) - 100                 t.y = display.contentHeight/2 \* math.sin(rads) - 100                 degrees = degrees + 5                print (square.x, square.y)                                                             elseif "ended" == phase or "cancelled" == phase then             display.getCurrentStage():setFocus( nil )             t.isFocus = false         end     end     return true end squares:addEventListener( "touch", onTouch )