I have used flash for more than two years now but Iam still a newbie when it comes to all kinds of angles between points, the conversion of angles in flash script language, use of sin and other functions. If any one can post a hot post or maybe some links, then it might be very useful. Looking forward to some great post. Thank you!

Circular ... typical sin, cos, tan and their complements Degree ... Circular functions returned in degrees Hyperbolic ... advanced trigonometric functions

... utilizes Circular and Hyperbolic trig methods to support its complex number methods.

Ahab Tutorials ... a mirror of Brandon Williams' early tutorials ... Brandon's main field of interest these days is Algebraic Topology ... we won't get into that here!

Senocular's Trigonometry Tutorial is a short read to give you a quick synopsis of the methods applied in Flash ... it deals with 2-space, to be extended to 3-space ... thus it's found in his 3D tutorial section.

Also, you can checkout my Unit Circle app to see all Circular trig methods in action and a large list of trig identitites (no proofs though) ... the graph mapping tool is not quite finished, sorry! Actually, it's a Flash 5 app that won't be revisited ... anyone remember the complexity of trying to tweak 'onClipEvent' code??!! I've used an explicit line algorithm (f(x) = mx + b) without my AS2 class-included hack for 'divide by 0', so some vector depictions will explode at vertical. An explanation of the explicit, implicit, and parametric line algorithms that are included in the above Graphic class can be found at the Intersection between two lines Were-Here thread.

The commented stuff is only if your using an movie clip in the center of the stage. However, there are a lot of exceptions, so have fun with it.
Check out the attached file to see the code in action.

Last edited by OpethRockr55; 09-28-2005 at 05:35 AM.

Thanks guys. Actually Iam still in learning phase of AS 2.0 so that's kinda hard for me to understand. But I'll look back to this whenever I'll need it. thanks again Dickee!

Sorry for being late with the reply, my tooth has been aching from past few days :P

Edit: and also thanks for all the great links *reading*

Last edited by adit_ya_sharma; 09-30-2005 at 10:23 AM.

Your post creates the opportunity to explore the functionality of an angle mapping algorithm, and may help Aditya with his quest!

Although your ragdoll app performs as expected, your posted code snippet is incomplete ... copy and pasting it to an onstage mc doesn't work. Try this instead:

Code:

this.createEmptyMovieClip("clip",1);
with (clip)
{
_x = 275;
_y = 200;
lineStyle(5);
moveTo(-20,0);
lineTo(20,0);
moveTo(0,-10);
lineTo(20,0);
lineTo(0,10);
clip.onMouseMove = function()
{
xDiff = _root._xmouse-this._x;
yDiff = _root._ymouse-this._y;
rot = this._rotation = Math.floor(Math.atan2(yDiff,xDiff)*180/Math.PI);
// these 2 lines change Flash CW rotation to Math-friendly CCW rotation
// and also alter the negative 0-180 results of atan2
if (rot>0) rot -= 360;
rot *= -1;
}
}

1. ??? I'm not sure why you've used '*-1' here. The atan's x,y input is actually depicting a direction vector from the mc (0,0) to the mouse. Your scheme won't do this (see #2), and with the y at '*-1' could be wildly incorrect.

2. Notice in both my code and in your posted ragdoll fla's 'relax' method, the input to the angle function uses the difference from the mouse x and y to the clip x and y ... your code uses the actual mouse position rather than this difference, which will blow up each 'mouseMove'.

3. This commented code adjusts the atan results to account for which of the 4 quadrants the actual angle resides. The simplification in my code is due to the use of atan2, which only requires adjustment at -/+ 180 degrees, instead of atan's 4 x 90 degree complexity.

Your revised code:

Code:

onClipEvent (mouseMove) {
x = _root._xmouse-this._x;
y = _root._ymouse-this._y;
angle = Math.atan(y/x)/(Math.PI/180);
this._rotation = angle*-1;
updateAfterEvent();
}

Notice, however, that both my atan2 clip code and your revised atan clip code function correctly without the sector hacks, since the new angle calculation only differs from the previous by a small amount, thus negating the need for the hacks. The hacks only come into play when angle measurements exceed the 90 degree boundaries for atan and 180 degrees for atan2.

Checkout my old F5 app dragLineAtan2 View | Source to compare the values for atan and atan2 ... it's a little hard to follow, but check the various field results while you drag one point around the other.

I don't know if this was essentially necessary, but it sure helped me out when I began to model this ragdoll.

2. This code is a version of one of my early angle escapades that WAS mouse based. The _mousex and _mousey are replaced with each joint's connective partner. Let's take the hand to the elbow. The relax function INSIDE the hand calls up the coordinates of the joint it's connected to, the elbow, and uses those coordinates in place of the mouse coordinates.

3. That seems like a good idea with the atan2. I've never tried it and it should make things much easier for me.

So thanks for your input and hope that clears somethings up for both you and adit_ya.

Last edited by OpethRockr55; 09-30-2005 at 03:48 PM.

Hey guys, thanks for everything. Iam finally beginning to see the matrix of this. I was reading a tut. on some site regarding the calculation of angles between a point and mouse co-ordinates. There the code was almost the same as you guys have done it, but in _y difference, it was written like this:-

yDiff =-1*( _root._ymouse-this._y);

and the explanation was that since the cartesian coordinate system in flash was opposite for y axis, we will find the negative of it to find the proper difference. Any comments on this please.

Thanks guys. Actually Iam still in learning phase of AS 2.0 so that's kinda hard for me to understand. But I'll look back to this whenever I'll need it. thanks again Dickee!

Sorry for being late with the reply, my tooth has been aching from past few days :P

Edit: and also thanks for all the great links *reading*