area function using xy

This is a discussion on area function using xy within the C++ Programming forums, part of the General Programming Boards category; I dont even have a clue, any tips how to begin????? I need to find an area of a triangle. ...

1. 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

2. create a function that uses the distance formula
distance = sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-f1)))

I think this is correct.

3. a = b * h / 2

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

4. ah, crap

a = b * h / 2

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

(sorry, its messy, i know)

5. 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.

6. area = (base/2) * height

7. 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.

8. That's not a hex number - that's a huge number.

Show your code - you must have done something wrong.

9. 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??

10. > Does this help??

Not at all....

What's "Point"?

Where the hell did that formula come from?

Why are you only saying GetX?

11. 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.

Popular pages Recent additions