# area function using xy

Printable View

• 03-26-2002
rake
area function using xy
I dont even have a clue, any tips how to begin?????

I need to find an area of a triangle.

User inputs x and y for Side A, B, C.

I know how to do with just sides AB and C but how do I do it with xy for each point ABC.

Lost
• 03-26-2002
rippascal
create a function that uses the distance formula
distance = sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-f1)))

I think this is correct.
• 03-26-2002
philip
a = b * h / 2

/|\
/ | \
B / | \ C
/ |h \
/ | \
‾‾‾‾‾‾‾‾‾‾
A(b)
• 03-26-2002
philip
ah, crap

a = b * h / 2

********** /|\
********* /* | \
*******B /**| *\ C
********/** |h* \
*******/*** |*** \
*******‾‾‾‾‾‾‾‾‾‾
**********A(b)

(sorry, its messy, i know)
• 03-26-2002
Govtcheez
The height will be the difference of the 2 most extreme y coordinates, and the base will be the difference of the 2 most extreme x coordinates.
• 03-26-2002
biosx
area = (base/2) * height
• 03-26-2002
rake
almost have it
ok, i worked out the code. Had to go with govtcheese's formula.

But everything works now except answer comes as something like a hexadecimal number.

Area = 1.04635e+34, it should say 7. Any clues.????? it is a float.
• 03-26-2002
Govtcheez
That's not a hex number - that's a huge number.

Show your code - you must have done something wrong.
• 03-26-2002
rake
here is code
here is function code

float area(Point& A, Point& B, Point& C)
{
int x2 = B.GetX() - A.GetX();
int x3 = C.GetX() - A.GetX();
int y3 = C.GetX() - A.GetX();
int y2 = B.GetX() - A.GetX();

return sqrt((x2*3) - (y3*y2)/2.0);

}

Does this help??
• 03-26-2002
Govtcheez
> Does this help??

Not at all....

What's "Point"?

Where the hell did that formula come from?

Why are you only saying GetX?
• 03-26-2002
rake
I just worked it out
point comes from the class........sorry for wasting your time, but I worked it out. How embarrassing I forgot to include <cmath> for sqrt.

anyway thanks for the area help.