Area of a triangle from coordinates

Prerequisites

Area Of A Parallelogram Show

Area of a trapezium Show

Area of a triangle Show

Area of a triangle from coordinates

Introduction

  • Finding the area of a triangle using it's base and height is easy.
  • But sometimes the base isn't perpendicular to it's height.
  • In these cases we can use a different method that relies only on the coordinates of the corners (vertices) of the triangle.
  • If the 3 vertices are given as: (x1, y1), (x2, y2), (x3, y3)
  • Then the equation of it's area is: (1/2) |x1(y2 − y3) + x2(y3 − y1) + x3(y1 − y2)|
    LaTeX formula:\left| \frac{ x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2) }{2} \right|

Proof

  • Given a triangle: picture of a triangle with vertices: (1, 1), (9, 2), and (5, 5)
  • With vertices:
    • a: 1, 1
    • b: 9, 2
    • c: 5, 5
  • First we extend each vertex down to the x-axis: triangle with lines drawn to the x-axis
  • This creates 3 trapaziums: the first two trapeziums the 3rd trapezium
  • The area of the triangle can then be expressed in terms of these trapeziums: area = D + E - F
  • The area of a trapezium is: (base1 + base2) * height / 2
  • The area of each of our trapeziums is: D_{area} = \frac{(a_y + c_y) \times (c_x - a_x)}{2} E_{area} = \frac{(c_y + b_y) \times (b_x - c_x)}{2} F_{area} = \frac{(a_y + b_y) \times (b_x - a_x)}{2}
  • Plugging these into our area equation, we get: area = \frac{(a_y + c_y) \times (c_x - a_x) + (c_y + b_y) \times (b_x - c_x) - (a_y + b_y) \times (b_x - a_x)}{2}
  • This simplifies to: area = \frac{c_xa_y - a_xa_y + c_xc_y - a_xc_y + b_xc_y - c_xc_y + b_xb_y - c_xb_y - b_xa_y + a_xa_y - b_xb_y + a_xb_y}{2} area = \frac{c_xa_y - a_xc_y + b_xc_y - c_xb_y - b_xa_y + a_xb_y}{2} area = \frac{a_x(b_y - c_y) + b_x(c_y - a_y) + c_x(a_y - b_y)}{2}
  • Finally, the area must be positive, so we take the absolute value: area = \left|\frac{ a_x(b_y - c_y) + b_x(c_y - a_y) + c_x(a_y - b_y)}{2} \right|

Code (Python)

triangle = [[1, 1], [8, 0], [6, 6]]

area = triangle[0][0] * (triangle[1][1] - triangle[2][1]) \
     + triangle[1][0] * (triangle[2][1] - triangle[0][1]) \
     + triangle[2][0] * (triangle[0][1] - triangle[1][1])

area /= 2
area = abs(area)

print(area) # prints 20.0