A Flash Developer Resource Site

# Thread: Finding centre coordinates of a circle

1. ## Finding centre coordinates of a circle

Hi!

I'm trying to rotate objects around a certain point, but I don't know how to calculate the position of it..

As the title mentions, it's got something to do with a circle, so instead of trying to explain everything in words, here is a simple representation of the situation:

Things I know:
- width and height of the screen
- position of the top of the circle inside of the screen

Things I might be able to know (needs testing):
- positions of intersection points of the circle with the left and right side of the screen

So how do I get the x and y position of O?

2. if you know the interesction points with the circle and the left and right of the screen, you can compute the center from those and the top points: http://local.wasp.uwa.edu.au/~pbourk...y/circlefrom3/

it seems strange that you don't have more information than this though, can you explain what exactly you're working with?

Let me further explain myself then!

So on the bottom screen I have a part of a circle, that I stretch to fit the width of the screen, thus changing the size of the circle.
Since it's not a complete circle, I can't determine where it's origin lies just by checking, and the radius is also not directly determinable..

I want to be able to rotate the object from outside of the screen onto the circle part (doesn't have to be an exact circular rotation, but the closer the better), to give the illusion that the circle itself is rotating.

Hope this helps

I did find this somewhere:

h = r - d
d = sqrt(4r2-c2)/2 = r cos(theta/2) = c cot(theta/2)/2

Would that serve to my purposes?

4. Originally Posted by florianvanthuyn
Since it's not a complete circle, I can't determine where it's origin lies just by checking, and the radius is also not directly determinable..
yes you can, read post #2 again.

5. The formula for a circle:

(x-h)^2+(y-k)^2=r^2

(h,k) is the center

You will need to know the distance formula too:

d= sqrt[(x2-x1)^2+(y2-y1)^2]

p1= (x1,y1)

p2 is (x2,y2)

p1 means "first point"
p2 means "second point"

The distance between two points is the squaroot of the square of the differnce of the x values of the points minus the square of the difference of the y values of the points.

You can use:

trace(obj.x)

to see the object's x position and:

trace(obj.y)

to get the objects y position. This should give you a point (x,y) which should be the center of the object.

To get the center of your stage you just take the width and divide by 2 and the same with the height. All you have to do is make your object's x and y position match the stage's center

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap