9 posts
• Page **1** of **1**

Hi again!

It's time for more funtime maths with circles! Or, well... I need help from those who are smarter than I.

OK, so I have a point on the edge of a circle. Let's say that point is at 0 degrees on the circle. I need to calculate the X and Y value of a point (n) degrees further round the edge of the circle.

Any ideas?

Cheers!

**Posts:**85**Reputation:**395

B

5
Do you know pythagorean theorem? well, if you take a pythagorean triangle with a fixed hypotenuse, and a fixed origin point, and only draw the other point of the hypotenuse for every possible angle, you'll get a circle.

Taking that on account.. your problem is easily solved, remembering trigonometry and that fun word 'sohcahtoa'

h : hypotenuse, radio of your circle

c_x,c_y : center of the circle

a : angle of the circle

sin definition:

sin a = opposite / hypotenuse

we can think of the opposite as the difference in y from the center, so we have

sin a = y / h .. y = h * sin(a) , here i'm assumpting that the centre of the circle is 0.. i guess that isn't your case, so we just offset it

y = h * sin (a) + c_y

cos definition:

cos a = adjacent / hypotenuse = x / h

x = h * cos (a) + c_x

so, here is your answer

x = h * cos (a) + c_x

y = h * sin (a) + c_y

where

h : hypotenuse, radio of your circle

c_x,c_y : center of the circle

a : angle of the circle

x,y : your pointsnosemeocurrenada 2013-06-11 04:32:39

Taking that on account.. your problem is easily solved, remembering trigonometry and that fun word 'sohcahtoa'

h : hypotenuse, radio of your circle

c_x,c_y : center of the circle

a : angle of the circle

sin definition:

sin a = opposite / hypotenuse

we can think of the opposite as the difference in y from the center, so we have

sin a = y / h .. y = h * sin(a) , here i'm assumpting that the centre of the circle is 0.. i guess that isn't your case, so we just offset it

y = h * sin (a) + c_y

cos definition:

cos a = adjacent / hypotenuse = x / h

x = h * cos (a) + c_x

so, here is your answer

x = h * cos (a) + c_x

y = h * sin (a) + c_y

where

h : hypotenuse, radio of your circle

c_x,c_y : center of the circle

a : angle of the circle

x,y : your points

**Posts:**16**Reputation:**236

B

4
**Posts:**85**Reputation:**395

B

5
Although there is something I'm still struggling with...

So in your

x = h * cos (a) + c_x

y = h * sin (a) + c_y

formula, (a) is the angle of the circle. But what if I want it (a) to be relative the the position of an object on the edge of the circle. So if object (o1) is at 270 degrees, then I want to place object (o2) at 300 degrees. But if (o1) is at 300 degrees, the I want to place (o2) at 330, and so forth.

Ok, so do that I need to be able to calculate the current angle (a) of object (o1)... Bearing in mind that the circle itself is rotating as (o1) rotates around it. Ummm.... Can I do that?

So in your

x = h * cos (a) + c_x

y = h * sin (a) + c_y

formula, (a) is the angle of the circle. But what if I want it (a) to be relative the the position of an object on the edge of the circle. So if object (o1) is at 270 degrees, then I want to place object (o2) at 300 degrees. But if (o1) is at 300 degrees, the I want to place (o2) at 330, and so forth.

Ok, so do that I need to be able to calculate the current angle (a) of object (o1)... Bearing in mind that the circle itself is rotating as (o1) rotates around it. Ummm.... Can I do that?

**Posts:**85**Reputation:**395

B

5
ok, i think i understood your question. Are you asking for something like having two objects on the edge of a circle and spin them continuosly? if the answer is yes..

let's say o1.angle is always at 45 degrees from origin, and o2.angle always at 45 from o1. and let's do a somewhat generic pseudocode

angle_offset : the angle of 'origin'

angle_increment: spinning 'speed'

a <- b : set a to b

o.angle : the angle offset from the origin of the object

[CODE]

const angle_increment = 1

const o1.angle = 45

const o2.angle = 90

every tick:

for each object o:

o.x <- h * cos(o.angle + angle_offset) + c_x

o.y <- h * sin(o.angle + angle_offset) + c_y

angle_offset <- angle_offset + angle_increment

[/CODE]Note: the angle_offset assignment is outside the for each loop.

Edit: removed numbers from the executing code.. just remember, the less constants as numbers(1,2,3) and the more constants as variables (angle_increment) the happier you 'll be when adding modificationsnosemeocurrenada 2013-06-11 06:02:37

let's say o1.angle is always at 45 degrees from origin, and o2.angle always at 45 from o1. and let's do a somewhat generic pseudocode

angle_offset : the angle of 'origin'

angle_increment: spinning 'speed'

a <- b : set a to b

o.angle : the angle offset from the origin of the object

[CODE]

const angle_increment = 1

const o1.angle = 45

const o2.angle = 90

every tick:

for each object o:

o.x <- h * cos(o.angle + angle_offset) + c_x

o.y <- h * sin(o.angle + angle_offset) + c_y

angle_offset <- angle_offset + angle_increment

[/CODE]Note: the angle_offset assignment is outside the for each loop.

Edit: removed numbers from the executing code.. just remember, the less constants as numbers(1,2,3) and the more constants as variables (angle_increment) the happier you 'll be when adding modifications

**Posts:**16**Reputation:**236

B

4
9 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: ColombageEnPLS, Google [Bot], Yahoo [Bot] and 5 guests |