# More maths fun time!

Get help using Construct 2

### » Tue Jun 11, 2013 3:42 am

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!
B
5
S
1
Posts: 85
Reputation: 545

### » Tue Jun 11, 2013 4:31 am

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'
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

x = h * cos (a) + c_x
y = h * sin (a) + c_y
where
c_x,c_y : center of the circle
a : angle of the circle
B
4
Posts: 16
Reputation: 236

### » Tue Jun 11, 2013 4:35 am

Thanks, I actually figured it out myself just seconds before your post!

Cheers though!
B
5
S
1
Posts: 85
Reputation: 545

### » Tue Jun 11, 2013 4:58 am

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?
B
5
S
1
Posts: 85
Reputation: 545

### » Tue Jun 11, 2013 5:14 am

Ok.. if you are interested on knowing more about this fun geometrical things, and have the time, take a look at the Euclid's Elements: http://en.bookfi.org/book/492577nosemeocurrenada2013-06-11 05:16:18
B
4
Posts: 16
Reputation: 236

### » Tue Jun 11, 2013 5:18 am

Yes.. again trigonometry
tan definition:
tan angle = opposite / adjacent
atan is the inverse of tan, so
angle = atan (opposite / adjacent)
B
4
Posts: 16
Reputation: 236

### » Tue Jun 11, 2013 5:21 am

Bearing in mind that the circle itself is rotating as (o1) rotates around it.
btw, what do you mean with this ? something like the earth rotating around the sun while the moon rotates around the earth?
B
4
Posts: 16
Reputation: 236

### » Tue Jun 11, 2013 5:54 am

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 modificationsnosemeocurrenada2013-06-11 06:02:37
B
4
Posts: 16
Reputation: 236