Advertisement
pcwizz

Triangle areas

Apr 29th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 3 methods of getting the area of a triangle
  2. areaOfTriangleHeron a b c = sqrt (s*(s-a)*(s-b)*(s-c)) -- calculate area of a triangle from the length of it's three sides using heron's fomula
  3.     where
  4.     s = (a+b+c) / 2
  5.  
  6. areaOfTriangleTrigUnopt a b c = c * height / 2 -- calculate the area of a triangle with modern trigonometry
  7.     where
  8.     cosa = (b^2 + c^2 - a^2) / (2*b*c)
  9.     sina = sqrt (1 - cosa^2)
  10.     height = b*sina
  11.  
  12.  
  13. areaOfTriangleTrig a b c = 0.5 * a * b * sin c -- optimized triangles with trigonometry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement