area (Polygon [(0,0), (s1,0), (s1,s2), (0,s2)])
= triArea (0,0) (s1,0) (s1,s2) + polyArea [(s1,s2), (0,s2)]
= triArea (0,0) (s1,0) (s1,s2) + triArea (0,0) (s1,s2) (0,s2) + polyArea [(0,s2)]
= triArea (0,0) (s1,0) (s1,s2) + triArea (0,0) (s1,s2) (0,s2) + 0
triArea (0,0) (s1,0) (s1,s2)
= let a = distBetween (0,0) (s1,0)
b = distBetween (s1,0) (s1,s2)
c = distBetween (s1,s2) (0,0)
s = 0.5 * (a+b+c)
in sqrt (s * (s-a) * (s-b) * (s-c))
= let c = sqrt (s1 ^ 2 + s2 ^ 2)
s = 0.5 * (s1+s2+c)
in sqrt (s * (s-s1) * (s-s2) * (s-c))
s * (s-c)
= (0.5 * (s1+s2+c)) * (0.5 * (s1+s2-c))
= 0.25 * ((s1+s2)^2 - c^2)
= 0.25 * ((s1+s2)^2 - (s1^2+s2^2))
= 0.25 * (2*s1*s2)
= 0.5 * s1 * s2
(s-s1) * (s-s2)
= (0.5 * (-s1 + s2 + c)) * (0.5 * (s1 - s2 + c))
= 0.25 * (c-(s1-s2)) * (c+(s1-s2))
= 0.25 * (c^2 - (s1-s2)^2)
= 0.25 * ((s1^2+s2^2)-(s1^2-2*s1*s2+s2^2))
= 0.5 * s1 * s2
so, triArea (0,0) (s1,0) (s1,s2) = 0.5 * s1 * s2
same reasoning for triArea (0,0) (s1,s2) (0,s2):
triArea (0,0) (s1,s2) (0,s2) = 0.5 * s1 * s2
so,
area (Polygon [(0,0), (s1,0), (s1,s2), (0,s2)])
= s1 * s2
= area (Rectangle s1 s2)
This entry was posted
on Monday, May 14th, 2007 at 6:29 pm and is filed under Haskell - SOE.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.