Angles and circles

I need to calculate the co-ordinates of a point on the outer edge of a circle given the radius and the angle.

If the center of the circle is (0,0), I belive this is how to do it:

xCoord = (Math.cos(Math.toRadians(180)))*radius;

yCoord = (Math.sin(Math.toRadians(180)))*radius;

However, the center co-ordinates of my circle are 250,250 'cos it's been painted on a canvas. I'd prefer to not have to convert the actual co-ordinates of the canvas to make 250,250 be 0,0 - I've seen it done but it'll introduce negative co-ordinates into my program, which I don't really want.

Anyways, how would I alter my forumae to calculate the x and y points given that the origin/center of the circle is (250,250)?

[741 byte] By [nealbo101a] at [2007-11-26 20:14:55]
# 1

While calculating calculate taking the center as 0 and 0 i.e. (0,0). Once you find the answer with (0,0) as center just add 250 to both the x and y-coordinates you have found out.

If your center has moved (250,250) co-ords then so hasl the point on the circumference too.

Message was edited by:

qUesT_foR_knOwLeDge

qUesT_foR_knOwLeDgea at 2007-7-9 23:21:22 > top of Java-index,Java Essentials,New To Java...
# 2
Just add the center coordinates to the calculated coordinates! (xCoord = xCoord + 250; yCoord = yCoord + 250;)
ProggerFromKupfera at 2007-7-9 23:21:22 > top of Java-index,Java Essentials,New To Java...
# 3
I tried that before posting but it didn't seem to have the correct effect - the calculation places images within the circle and outside of the circle. Is my initial calculation correct?
nealbo101a at 2007-7-9 23:21:22 > top of Java-index,Java Essentials,New To Java...
# 4

the formulas are correct. adding both 250 solves the first problem.. but the point that you may have misunderstood may be:

Simply while placing images (or something else) to x,y the component you paint start from x,y..So that left , top point of your image will be on x,y. So the left-top point of your image will be on the circle... Not the center of your image will be on the circle... Due to the angle your images may be painted in or out of the circle.

so for ex if your images size is width: W, height: H>>

try thisx=(your x formula +250)-W/2;

y= (your y formula +250)-H/2;

(the center point of your image will be on the circle)

hope helps..

Message was edited by:

serdarr

serdarra at 2007-7-9 23:21:22 > top of Java-index,Java Essentials,New To Java...
# 5

Hi friends

Last post is very good.

I will just like to add that for such a problems you should try to send some code snippets.

Secondly the kind of issue e.g if you are trying to make a watch which requires same kind of functionality the image must sart from origin and should ends on circumference.

So sometime it is better to send aim if your problem.

I think last post will definitely help u

amit.naranga at 2007-7-9 23:21:22 > top of Java-index,Java Essentials,New To Java...