To find the area of the triangle
/* Syntax: result = AREA3 (float x1, float y1, float x2, float y2, float x3, float y3);
Parameters:
x1~3: Triangle 3 vertices x coordinate
y1~3: Triangle 3 vertex y-coordinate
return value: Triangle area///
*
method: Helen-Qin Jiu formula known triangle A,b,c, then S area =√[p (P- A) (P-b) (P-C)] (Helen Formula) (
of which p= (A+B+C)/2)/
float area3 (float x1, float y1, float x2, float y2, float x3, flo At y3) {
float A, B, C, p, s;
To find the three-side length
a = sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-y2));
b = sqrt ((x1-x3) * (X1-X3) + (y1-y3) * (Y1-y3));
c = sqrt ((x2-x3) * (X2-X3) + (y2-y3) * (Y2-y3));
p = (A + B + c)/2;
Find the area
s = sqrt (p* (p-a) * (p-b) * (p-c));
return s;
}
Test function
int main () {
float x1, y1, x2, y2, X3, y3;
while (cin>>x1>>y1>>x2>>y2>>x3>>y3) {
cout << area3 (x1, y1, x2, y2, x3, y3);
}
return 0;
}