Advertisement

Help with Triangles

Started by February 28, 2002 08:43 PM
1 comment, last by paraphobe80d 22 years, 11 months ago
I''m trying to write a program for my college computer science class. I''m pretty stumped. I need to figure out how to get the area of a triangle, of any type, just knowhing the length of the three sides... thanks.
Get out your nearest trig book or Google search for "area of triangle" and I bet you''ll finish this before anyone else can reply.
Advertisement
You need Hero''s Formula, which is pretty easy to implement:

n = (perimeter of triangle) / 2;

Area = sqrt( n*(n - side1)*(n - side2)*(n - side3) );


A quick example (3-4-5 right triangle):

n = (3 + 4 + 5)/2 = 12/2 = 6
sqrt( 6(3)(2)(1) ) = sqrt(36) = 6

And, lo and behold, (3*4)/2 = 6 as well

I hope that helps!
h20, member of WFG 0 A.D.

This topic is closed to new replies.

Advertisement