• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Orbiting point with changing angle value

E

Elgarion

Guest
Hello everyone,

I'm stuck with a math problem. At first I thought it would be simple, but I can't figure it out :

Imagine a circle A, with a point B orbiting on it.

Mechanically, the program should take the point B at position 1 (B1) and move it to a certain angle, relatively to a center A, in position 2 (B2). We know the coordinates Bx1, By1, Ax, Ay and the angle.

In summary :
- I have the orbiting point B : Bx1 and By1
- I have the center A : Ax and Ay
- I have the angle, in degrees
= > I need the values Bx2 and By2 of B's new position.
I hope it's clearer. Thank you so much for your effort!


I tried with the code below, but things get quite clunky.

Code:
// for any 'my angle' variable ranging from 0 to 359
my_angle = 90 // example

// determining the center
temp_X = Bx - Ax ;
temp_Y = By - Ay;
               
NewPosition_Bx = Ax + (temp_X * cos(my_angle)) - (temp_Y * sin(my_angle))
NewPosition_By = Ay + (temp_X * sin(my_angle)) + (temp_Y * cos(my_angle))
Any clue ?

EDIT : I modified this post in order to make it clearer.
 
Last edited by a moderator:
E

Elgarion

Guest
Why are you rounding? If you want a rounded value, just round NewPosition_Bx and NewPosition_By.
Tbh I don't remember, I guess I wanted to simplificate my calculus at an intermediary point. But I don't think the rounded values are the real problem, here (but thanks anyway, the rounded value are probably unecessary, indeed)

Edit : no you're right, rounding was a mistake. But my formula doesn't work anyway... Is there a better way to do it?
 
Last edited by a moderator:

Simon Gust

Member
Try this code, I think it does the same.

CREATE
Code:
angle = 0;
DRAW
Code:
angle += 0.1;

var x1 = 100;
var y1 = 100;
var r = 30;

var x2 = x1 + lengthdir_x(r, angle);
var y2 = y1 + lengthdir_y(r, angle);

draw_circle(x1, y1, r, 1);
draw_circle(x2, y2, 3, 0);
To demonstrate, I let the point orbit the large circle at a rate of 1rpm (angle += 0.1)
 
E

Elgarion

Guest
Nice ! I think I'm getting closer. But I have an other problem : in your example, I think that the starting point is the angle (0). Could you tell me how you would do that with a starting point with coordinates, and a +1 angle every step?

To be more accurate in my problem description, at first we only know the coordinates of point A (center) and the point B. The point B must go around the point A (clockwise) at a certain speed (that's the value I put in the angle)

Thanks again!
 

Simon Gust

Member
The radius will be the distance between A and B in that case?
CREATE
Code:
angle = 0;
Ax = 100;
Ay = 100;
Bx = random_range(50, 150);
By = random_range(50, 150);
DRAW
Code:
angle -= 1;

var r = point_distance(Ax, Ay, Bx, By);

Bx = Ax + lengthdir_x(r, angle);
By = Ay + lengthdir_y(r, angle);

draw_circle(Ax, Ay, r, 1);
draw_circle(Bx, By, 3, 0);
Trying to emulate a situation where B could be anywhere.
 
E

Elgarion

Guest
Yes, but if my understanding is correct, in your draw part, you do not take in account the original coordinates of B that you put in the create ?

Mechanically, the program should take the point B at position 1 (B1) and move it to a certain angle, relatively to a center A, in position 2 (B2). We know the coordinates Bx1, By1, Ax, Ay and the angle.

So, to follow you example, we would have in create :

CREATE :
Code:
Ax = 100;
Ay = 100;
Bx1 = 200;
By1 = 100;
angle = 90
Then I'd like an other point to be drawn (or the first moving, doesn't really matter for the exercise ^^), in Bx2 and By2 coordinates that take in account the angle of 90. It should be (for these precise numbers) : Bx2 = 100 ; By2 = 200 (the point B is moved by 90°)

In summary :
- I have the orbiting point B : Bx1 and By1
- I have the center A : Ax and Ay
- I have the angle, in degrees
= > I need the values Bx2 and By2 of B's new position.
I hope it's clearer. Thank you so much for your effort!
 
Last edited by a moderator:
Top