guide my rectangle to the center of my circle with the correct orientation

hi, i’m searching to guide rectangle as a radius of the circle.

But that don’t work…Could you help me please ?

local circlecenter=display.newCircle(100,100,10) --the center local function draw(posx,posy)     local Rect=display.newRect(posx,posy,100,10)     X=Rect.x-circlecenter.x     Y=Rect.y-circlecenter.y     V=math.atan2(X,Y)--angle in radian     P=math.deg(V) --angle in degree     Rect.rotation=P --orientation of my rect     print(P) end draw(400,40)

finding by myself for those interesting :

local circlecenter=display.newCircle(100,100,10) local function draw(posx,posy)     local Rect=display.newRect(posx,posy,100,10)     X=Rect.x-circlecenter.x     Y=Rect.y-circlecenter.y     local angle = math.atan2(Y,X)     angleDeg=math.deg(angle)     Rect.rotation=angleDeg end draw(-20,400)

 

For help the others :slight_smile:

A function to simulate energy who are accumulate next a circle

local circlecenter=display.newCircle(100,100,10) local energy={} for i=1,20 do radius =100 a=math.random(-314,314)\*.01 x = circlecenter.x + radius \* math.cos(a) y = circlecenter.y+ radius \* math.sin(a)     energy[i]=display.newRect(x,y,10,1) end local function draw(element,i)     X=element[i].x-circlecenter.x     Y=element[i].y-circlecenter.y     local angle = math.atan2(Y,X)     angledeg=math.deg(angle)     element[i].rotation=angledeg     transition.to(energy[i], {time=1000,x=circlecenter.x,y=circlecenter.y}) end for i=1,#energy do draw(energy,i) end

 

finding by myself for those interesting :

local circlecenter=display.newCircle(100,100,10) local function draw(posx,posy)     local Rect=display.newRect(posx,posy,100,10)     X=Rect.x-circlecenter.x     Y=Rect.y-circlecenter.y     local angle = math.atan2(Y,X)     angleDeg=math.deg(angle)     Rect.rotation=angleDeg end draw(-20,400)

 

For help the others :slight_smile:

A function to simulate energy who are accumulate next a circle

local circlecenter=display.newCircle(100,100,10) local energy={} for i=1,20 do radius =100 a=math.random(-314,314)\*.01 x = circlecenter.x + radius \* math.cos(a) y = circlecenter.y+ radius \* math.sin(a)     energy[i]=display.newRect(x,y,10,1) end local function draw(element,i)     X=element[i].x-circlecenter.x     Y=element[i].y-circlecenter.y     local angle = math.atan2(Y,X)     angledeg=math.deg(angle)     element[i].rotation=angledeg     transition.to(energy[i], {time=1000,x=circlecenter.x,y=circlecenter.y}) end for i=1,#energy do draw(energy,i) end