0 Favourites

More maths fun time!

  • 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?


  • 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


    h : hypotenuse, radio of your circle

    c_x,c_y : center of the circle

    a : angle of the circle

    x,y : your points

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

    Cheers though!

  • 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?

  • 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: en.bookfi.org/book/492577

  • Yes.. again trigonometry

    tan definition:

    tan angle = opposite / adjacent

    atan is the inverse of tan, so

    angle = atan (opposite / adjacent)

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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?

  • 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

    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

    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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)