# Sine circle

### » Mon Jul 11, 2011 11:10 pm

Hey chaps

I am trying to make a circle path using sine on the x and y axis.
Thanks to Shviller, I know that, using the sine behaviour I can achieve this with a 25% offset on one axis. However I want to use events to control it, and I just can't get the timing right, I am not sure how to offset the values with events.

sin(timer*0.10) * 10

So I have something along these lines, and have tried all sorts of combinations of values.

sin(timer*0.025) * 10
sin(timer*0.025) * 2.5
sin(timer*0.10) * 2.5

So I am thinking that the offset is some other value, but I am not sure.

Anyone have any ideas?

B
9
S
2
G
4
Posts: 346
Reputation: 2,726

### » Mon Jul 11, 2011 11:52 pm

cos and sin expect a value in degree and return a value based on the unit circle (so they return [-1,+1])

To position something on a circle around a center:

x = center_X + cos(angle) * radius
y = center_Y + sin(angle) * radius

To move something circular around a center over time:

angle = angle + amountofchangepersecond * TimeDelta
x = center_X + cos(angle) * radius
y = center_Y + sin(angle) * radius

You may also change angle and/or radius independently for x and y which will have various effects, like shaping an ellipse instead of a circle and much more.tulamide2011-07-11 23:53:03
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Tue Jul 12, 2011 12:46 am

Oh you are absolutely fantastic Tulamide, always so helpful. I was specifically looking for elliptical shapes as well. Cheers!
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

### » Thu Oct 23, 2014 9:09 pm

@tulamide - lets say you have a square moving around the elliptical path, how do you angle it to aim always at the center?
B
92
S
44
G
17
Posts: 1,012
Reputation: 18,607

### » Fri Oct 24, 2014 5:30 am

That depends on the exact situation. In the example above, I made 3years ago, the angle is from the center's point of view. In this case it is easy: Just use the opposite angle. Easiest way to do so is by adding 180:

angle = angle + amountofchangepersecond * TimeDelta
x = center_X + cos(angle) * radius
y = center_Y + sin(angle) * radius
square_angle = angle + 180
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289