# Heron's formula for area of a triangle [closed]

Use the first form of Heron's formula to give a function areah, which gives the area of a triangle. Test your answer on the isosceles triangle {{-1 ,0}, {1, 0}, {0, 1}, {-1, 0}}.

This is what I have:

areah[triangle_] :=
(lenbroke[triangle]/2 Product[lenbroke[triangle]/2 -
len (lineseg (triangle[[i]])), {i, 1, 3}])


This is what I get when I test it:

areah[{{-1, 0}, {1, 0}, {0, 1}, {-1, 0}}]


I don't know what is wrong because when I test it, it doesn't work.

-

## closed as off-topic by m_goldberg, Sjoerd C. de Vries, Artes, Yves Klett, Michael E2Oct 13 '13 at 17:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – m_goldberg, Sjoerd C. de Vries, Artes, Yves Klett, Michael E2
If this question can be reworded to fit the rules in the help center, please edit the question.

Hi, there seems to be a lot missing from your post: lenbroke, len, lineseg. And a triangle has three vertices, not four. Please correct these problems. –  Michael E2 Oct 13 '13 at 0:32
@MichaelE2 Those are three vertices, but the triangle is stammering –  belisarius Oct 13 '13 at 0:58
4 because it has to go back to where it originally was. –  Sam Oct 13 '13 at 1:28
Oops, poor eyesight - sorry. I still don't see the definitions of the other variables/functions. Perhaps you're filling them in now. –  Michael E2 Oct 13 '13 at 1:36
I used a = {-1, 0}; b = {1, 0}; c = {0, 1}; s = 1/2 Abs[Det[{a - b, a - c}]] –  minthao_2011 Oct 13 '13 at 3:04

Maybe this is what you want:

areah[triangle_] :=
Module[{a, b, c, s},
{a, b, c} = Norm /@ Differences[triangle];
s = (a + b + c)/2; Sqrt[s (s - a) (s - b) (s - c)]]

areah[{{-1, 0}, {1, 0}, {0, 1}, {-1, 0}}] // Simplify


1

But I prefer the solution of @minthao_2011 using determinant.

-

I used

a = {-1, 0}; b = {1, 0}; c = {0, 1}; s = 1/2 Abs[Det[{a - b, a - c}]]


1

-