Article 66FTA Area of a triangle in the complex plane

Area of a triangle in the complex plane

by
John
from John D. Cook on (#66FTA)

I recently ran across an elegant equation for the area of a triangle in the complex plane with vertices at z1, z2, and z3. [1].

area_complex_triangle.svg

This formula gives the signed area: the area is positive if the points are given in countclockwise order and negative otherwise.

I'll illustrate the formula with a little Python code. Let's generate a random triangle.

 import numpy as np np.random.seed(20221204) r = 100*np.random.random(6) z1 = r[0] + 1j*r[1] z2 = r[2] + 1j*r[3] z3 = r[4] + 1j*r[5]

Here's what our triangle looks like plotted.

complex_triangle.svg

Now let's calculate the area using the formula above and using Heron's formula.

 def area_det(z1, z2, z3): det = 0 det += z2*z3.conjugate() - z3*z2.conjugate() det -= z1*z3.conjugate() - z3*z1.conjugate() det += z1*z2.conjugate() - z2*z1.conjugate() return 0.25j*det def area_heron(z1, z2, z3): a = abs(z1-z2) b = abs(z2-z3) c = abs(z3-z1) s = 0.5*(a + b + c) return np.sqrt(s*(s-a)*(s-b)*(s-c)) print(area_heron(z1, z2, z3)) print(area_det(z1, z2, z3))

This prints -209.728 and 209.728. The determinate gives a negative area because it was given the points in clockwise order.

[1] Philip J. Davis. Triangle Formulas in the Complex Plane. Mathematics of Computation. January 1964.

The post Area of a triangle in the complex plane first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments