Negative result of ((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c)) is not possible if a,b,
and c are lengths of a triangle's sides. The first term will always be
obviously positive, and so will the other three terms -- they are simply
the sum of the lengths of two sides less the third side, and you can't have
a triangle where that isn't true. It's most likely that your input numbers
to the formula are incorrect. Trace that to find your problem.
On 12/14/06, Merrill, Jason <[EMAIL PROTECTED]> wrote:
I'm trying to figure the area of a triangle in Actionscript using the
perimeter values only, not the traditional simple formula:
area = (height/2)*base
because figuring the height is tricky given the triangle will be drawn
in odd ways (i.e. a not horizontally alinged base), so I am exploring
other triangle area forumulas that only take in the perimiter values
(a,b,c), like Heron's formula or this one, which I like:
given a,b,c are the length of the sides of the triangle, then the
formula is:
squareRoot of: (a+b+c)(b+c-a)(c+a-b)(a+b-c)
___
4
So in trying to translate that to actionscript, I wrote:
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;
}
But the problem is (a+b+c)*(b+c-a)*(c+a-b)*(a+b-c) results in a negative
number, and this the square root cannot be taken. Or perhaps I am
interpreting the forumula incorrectly:
http://mathworld.wolfram.com/TriangleArea.html
What am I doing wrong here? Thanks.
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
___
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