How to calculate the area of a quadrilateral with determinant

Revision en1, by simiao, 2016-05-01 17:52:15

Hello guys!

I was solving a contest on gym here at codeforces and I faced this problem where basically you have to calculate the area of a quadrilateral given by four points in a 2D plane.

In contest time I solved the problem identifying the point that makes the polygon not convex (if there is one), since there's no guarantee of it being convex, and from it I form 2 triangles, so the area is the sum of this 2 triangles areas. The code is messy but you can see it here.

After the contest I went to look for other people solutions and most of them seem to have solved using determinant, but not for calculate the area of the 2 triangles like me, it's like given the four points of the quadrilateral a, b, c and d, the area is 1/2 * (det(a,b) + det(b,c) + det(c,d) + det(d,a)), but I have no idea why this is true.

If someone can explain this relation, or point me to some place that explains it I would be very thankfull! :D

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English simiao 2016-05-01 17:52:15 1111 Initial revision (published)