 # Drawing a path circle with actionscript and trigonometria

• 05-25-2005, 10:11 AM
albegago
Drawing a path circle with actionscript and trigonometria
Hi:

I want animate a dot following a circle path using action script.

(Yeah... its easy to draw a circle path and create a motion tween... but i want to animate it using action script)

Im using this formula:
* * * * * * * * * * * * * * * * * * * * * * * *

var r = 150;
// r is the radius value

mover = function()
{
if( this._x >= -1*r && this._x <= r-1 && this._y >= 0 && this._y <= r)
// x will increase by 2 if the dot is located
// at x=-150 and x<149
// y = 0 and y <= 150
{
this._x +=2;
// increase x by 2 px
this._y = Math.sqrt ((r*r) - (this._x * this._x));
// I determine the y position using the trigonometria circle formula
}
else
{
this._x -=2;
this._y = (Math.sqrt ((r*r) - (this._x * this._x))) * (-1);
// I determine the y position using the trigonometria circle formula
// x will decrease by 2 if the dot is not located
// at x=-150 and x<149
// y = 0 and y <= 150

}

}

c1._x = -1*r;
// The dot is posted at coord x=-150
c1._y = 0;
// The dot is posted at Y=0
c1.onEnterFrame = mover;

* * * * * * * * * * * * * * * * * * * * * * * *

The formula works well... more or less...

check it and see how the dot follow the circle path, put it jumps just in the middle of the circle.
• 06-03-2005, 11:32 PM
GrantUnwin
equation for circle:

(X-a)^2 + (Y-b)^2 = c^2

where:
|-a|=x co-ordinate of centre of circle
|-b|=y co-ordinate of centre of circle

set the position of the dot to be the radius distance above the centre point. (this way its definatly on the line). Then move accross the X co-ordinates using the formula to find the Y co-ordinate. Or vice versa. There will be 2 solutions but IF |(X POS - OLD XPOS)| is less than 0.1 then use that 1. if you get me. very early cant be bothered im sure you can figure it out. I hope this was a help.

formula for working out X co=ordinate with Y co-ordinate is:

X = ( SqRt[c^2 - (Y-b)^2] ) + a

where:
|-a|=x co-ordinate of centre of circle
|-b|=y co-ordinate of centre of circle