Thank u Danny Kodicek...
and i am presenting the solution to solve SSS triangle...
/////////SOLVE TRIANGLE ///////////////////////////////////////
///pass the instance names of there movieclips on the stage
//this function returns a Solution Object
//Solution object has:
//a-side1
//b-side2
//c-side3
//A-angle1
//B-angle2
//C-angle3
function solveTriangle(a_mc, b_mc, c_mc) {
a = distance(b_mc, c_mc);
b = distance(c_mc, a_mc);
c = distance(a_mc, b_mc);
//////find Angle A
var A = (Math.pow(b, 2)+Math.pow(c, 2)-Math.pow(a, 2))/(2*b*c);
A = Degree(Math.acos(A));
//trace(A);
/////find Angle B
var B = (Math.pow(a, 2)+Math.pow(c, 2)-Math.pow(b, 2))/(2*a*c);
B = Degree(Math.acos(B));
//trace(B);
var C = 180-(A+B);
//trace(C);
A = Math.round(A);
B = Math.round(B);
C = Math.round(C);
var solution = {a:a, b:b, c:c, A:A, B:B, C:C};
return solution;
}
function distance(p1, p2) {
//returns pixels
var dx = p2._x-p1._x;
var dy = p2._y-p1._y;
var dis = Math.pow(dx, 2)+Math.pow(dy, 2);
var dis = Math.sqrt(dis);
return dis;
}
function Degree(rad) {
return (180/Math.PI)*rad;
}
function Radian(deg) {
return (Math.PI/180)*deg;
}
////////////end//////////////////////////////////////////////
enjoy
-Pandian
Danny Kodicek wrote:
I am having 3 movie Clips named point1_mc, point2_mc, point3_mc in the
stage. They are arranged in such a way to form a triangle...
Now how can i get those 3 angles and sides formed by these points.?
Sides are given by the lengths of the vectors between the points (eg:
x = point1_mc._x - point2_mc._x, y = point1_mc._y - point2_mc._y, so
side length =sqrt(x*x + y*y) )
Once you have these sides, you can use the cosine rule to find the
angles: If you know the three sides a,b,c, the angle A between the
sides b and c is given by a*a = b*b + c*c - 2*b*c*cosA.
To get acos(A), you need to use atan(A): acos(A)=atan(A/sqrt(1 - A*A))
Best
Danny
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders