nyoj-67-triangle area (S=(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2))

topic link

1  /* 
2      Name:nyoj-67-Area of ​​a triangle
 3      Copyright:
 4      Author:
 5      Date: 2018/4/26 16:44:47
 6      Description:
 7      The formula for finding the area of ​​the three vertices of a triangle is: 
 8          S =(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2)
 9  */ 
10 #include <iostream>
 11 #include <cstdio>
 12  using  namespace std;
 13  int main()
 14  {
 15      int x1 ,x2,x3,y1,y2,y3;
 16      while (cin>>x1>>y1>>x2>>y2>>x3>>y3, x1+x2+x3+y1+y2+ y3) {
17         double ans = x1*y2 + x2*y3 + x3*y1 -x1*y3 - x2*y1 - x3*y2;
18         printf("%.1f\n", ans/2>0?ans/2:-ans/2);
19     }
20     return 0;
21 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324902341&siteId=291194637