circular movement: simple math algorithm

yarekGmail
yarekGmail used Ask the Experts™
on
Hello experts
 I have to calculate dx and dy so player1 has a circular movement.
(look at the embed picture:   circular movement )

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You need to give us more information.

Is there one player and a target, or two players and a target?

There are an infinite number of circles that go through player1 and target.

Do you always want the center of the circle to be the midpoint between player1 and target.

What is going to be moving?  Is player1 constrained to move along the arc?

Author

Commented:
1) there is a RADIUS fixed: so I don't think there is a infinite number of solutions !
2) 1 player and 1 target
3) yes center of the circle = middle point as I draw
4) yes player1 is moving: that's why I put
player1.x+=dx;
player1.y+=dy;


regards
>>   4) yes player1 is moving: that's why I put
        player1.x+=dx;
        player1.y+=dy;

Except that you actually put   player2.y+=dy

That's why I was confused.

You have to know what the radius is.
Can you just call it R?

Are the player and the target always at the same height/y-coordinate?

You need either trig or simultaneous equations to find the center of the circle (Xo, Yo)

Once you have the center, the path of player1  can be described by:
     


player1.x  =  Xo  + R*[cos(w*t + to)]

   player1.y  =  Yo  + R*[sin(w*t + to)]

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
what is w ?
what is t ?
what is t0 ?

Commented:
A 2D function (a circle in this case) can have more than one representation...
i.e.
1)
 y=f(x) where for every x point there’s a function f() that give us y

2)
y=f(t)
x=g(t)
in this case there's an auxiliary variable t; giving different values to “t” we get all the possible pairs (x,y)

1) is used mostly for functions where for every x there’s only one correspondent y
2) is used mostly when the former restriction does not apply

a circle is a function that is almost always represented by 2)

the former expert gave you the general equation of a circle where "to" is a constant representing the initial value of "t"
w is called the "angular speed"  w=2*pi*f where f is the "frequency"
t as you know now is an auxiliary variable

the names come from the fact that those equation represent many times in physics rotary movements
then it results clear why w represents a speed and t really represents "time"

then if you want to draw a circle on a screen
you perform a loop in your code suplying t values to the eq then you get the (x,y) pairs and display them on the screen...





ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
Given points (p1.x,p1.y),(p2.x,p2.y) and radius R,
let D=sqrt((p1.x-p2.x)^2 + (p1.y-p2.y)^2)
the centre of the circle would be at
(c.x,c.y)=((p1.x+p2.x)/2 + (p1.y-p2.y)*z,(p1.y+p2.y)/2 + (p2.x-p1.x)*z)
where z=sqrt(R^2-(D/2)^2))*2/D
If the centre is at the midpoint of p1 and p2, then R=D/2

then for an infinitesimal movement counter clockwize around the circle from p
dx = (c.y-p.y)*dt
dy = (p.x-c.x)*dt
This becomes a perfect approximation as      dt approaches 0,
but for      dt too large, p      will tend to spiral out      from c
>>  what is w ?
       what is t ?
       what is t0 ?


Sorry I've been away.

w is meant to stand for angular frequency.  How fast the player moves on the circle.

The actual value of w depends on how fast you want the player to move, on whether you are
using degrees or radians, and on whether you are moving clockwise or counter clockwise.

t is time.

to is angular offset.

If you draw a circle using the sin and cos technique:

     x  =  sin(0)   =  0
     y  =  cos(0)  =  1  ==> Circle starts at 12 o'clock and goes clockwise.

If you want to be somewhere else at t=0, you need an offset.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial