Nice Alain!

On 12/14/06, Alain Rousseau <[EMAIL PROTECTED]> wrote:
 Speaking of Triangles, I made an utility Class to help me solve Triangle
problems
and the formulas are all taken from mathworld website

It will help you get the missing values of your triangles :

Hope it helps someone out there ...


Alain


/***************************************************************************
******
*
*       Triangle Solver
*
*       File: TriangleSolver.as
*       Created by: [EMAIL PROTECTED]
*
****************************************************************************
*****/
/***************************************************************************
******
*
*
*       Class: TriangleSolver
*
*       Class that helps solving triangle equations, all the methods are
static
*       so there is no need to create an instance of the class
*
*       Math reference : http://en.wikipedia.org/wiki/Triangle
*
*       Usage Example :
*
*       import ca.daroost.utils.TriangleSolver;
*       // lets say that we have a rectangle triangle of known height and
width and we are looking for the hypotenuse
*       var hyp:Number = TriangleSolver.hypothenuse(100, 50);
*
*
****************************************************************************
*****/
class ca.daroost.utils.TriangleSolver {
        //

/***************************************************************************
******
        *
        *      Properties
        *

****************************************************************************
*****/
        //
        public static var DEGTORAD:Number = Math.PI/180;
        public static var RADTODEG:Number = 180/Math.PI;

        //

/***************************************************************************
******
        *
        *      Constructor : TriangleSolver
        *

****************************************************************************
*****/
        //
        function TriangleSolver() {

        }
        //

/***************************************************************************
******

****************************************************************************
******
        **
        **
Methods
        **

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

****************************************************************************
*****/
        //
        //

/***************************************************************************
******
        *
        *      Method : hypothnuse
        *
        *      The Pythagorean theorem
        *
        *               @param : a - the a side
        *                                b - the b side
        *

****************************************************************************
*****/
        //
        // c = sqrt(a^2 + b^2)
        public static function hypothenuse(a:Number, b:Number):Number {
                var c:Number;
                c = Math.sqrt(Math.pow(a,2)+Math.pow(b,2));
                return c;
        }
        //

/***************************************************************************
******
        *
        *      Method : sineRule
        *
        *      Refers to the sine rule
        *          c/sin(angleC) = a/sin(angleA) = b/sin(angleB)
        *
        *               @param : c - the c side
        *                                angleC - the angle opposed to the c
side
        *                                a - the a side
        *                                angleA - the angle opposed to the a
side
        *

****************************************************************************
*****/
        //
        //
        public static function sineRule(c:Number, angleC:Number, a:Number,
angleA:Number):Number {
                if ( (angleC == undefined) || (angleC == null) ) {
                        angleC = Math.asin(c*Math.sin(a)/angleA);
                        return angle;
                } else if ( (c == undefined) || (c == null) ) {
                        c = a*Math.sin(angleC)/Math.sin(angleA);
                        return c;
                }
        }
        //

/***************************************************************************
******
        *
        *      Method : cosRule
        *
        *          Refers to the cosine rule which is the extended version
of the Pythagorean theorem
        *      c^2 = a^2 + b^2 - 2*a*b*cos(angleC)
        *
        *               @param : c - the c side
        *                                a - the a side
        *                                b - the b side
        *                                angleC - the angle opposed to the c
side
        *

****************************************************************************
*****/
        //
        public static function cosRule(c:Number, a:Number, b:Number,
angleC:Number):Number {
                if ( (angleC == undefined) || (angleC == null) ) {
                        angleC =
Math.acos((Math.pow(a,2)+Math.pow(b,2)-Math.pow(c,2))/2*a*b);
                        return angle;
                } else if ( (c == undefined) || (c == null) ) {
                        c =
Math.sqrt(Math.pow(a,2)+Math.pow(b,2)-2*a*b*Math.cos(angleC));
                        return c;
                }
        }
        //

/***************************************************************************
******
        *
        *      Method : angleRule
        *
        *      Refers to the angle rule
        *      angleC + angleA + angleB = 180
        *
        *               @param : angleA - the angle opposed to the a side
        *                                angleB - the angle opposed to the b
side
        *

****************************************************************************
*****/
        //
        public static function angleRule(angleA:Number,
angleB:Number):Number {
                var angleC:Number;
                angleC = 180 - (angleA + angleB);
                return angleC;
        }

        //

/***************************************************************************
******
        *
        *      Method : area
        *
        *      Calculates the area of a triangle (best for a rectangle
triangle)
        *      A = b*h/2
        *
        *               @param : b - the base of the triangle
        *                                h - the height of the triangle
        *

****************************************************************************
*****/
        //
        public static function area(b:Number, h:Number):Number {
                var area:Number;
                area = b*h/2;
                return area;
        }

        //

/***************************************************************************
******
        *
        *      Method : areaHeron
        *
        *      Calculates the area of a triangle where s is the triangle's
semiperimeter
        *          s = a+b+c/2
        *      A = sqrt(s(s-a)(s-b)(s-c))
        *
        *               @param : a - the a side
        *                                b - the b side
        *                                c - the c side
        *

****************************************************************************
*****/
        //
        public static function areaHeron(a:Number, b:Number,
c:Number):Number {
                var area:Number;
                area = Math.sqrt((a+b+c)*(a+b-c)*(b+c-a)*(c+a-c))/4;
                return area;
        }

}

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Merrill,
Jason
Sent: 14 décembre 2006 14:06
To: Flashcoders mailing list
Subject: RE: [Flashcoders] Area of a triangle using perimiter values only

Thanks - all, yes Jake saw it first and others chimed in with the same
thought, my numbers did not compute because they did not make a triangle.  I
have it working now.

The formula is fine, and this function works for me as long as the values
come from a true triangle:

        public static function areaOfTriangle(a:Number, b:Number,
c:Number):Number{
                return (Math.sqrt((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c)))/4;
        }

Thanks eveyrone!

Jason Merrill
Bank of America
Learning & Organizational Effectiveness





_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.com


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.15.18/586 - Release Date: 2006-12-13


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.15.18/586 - Release Date: 2006-12-13


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



--
Jordan Snyder
Applications Developer
Image Action LLC
http://www.imageaction.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to