
Red-Flag Day Geometry
Linear Algebra and Heron's Formula
We’re relaxing at the beach in Corolla, NC this week. It’s after Labor Day so prices are down and the crowds have left. The first couple of days were red-flagged meaning you can’t get in the water, but yesterday was fine and I got a boogie board and jumped in. But an offshore storm is developing and today is red-flag again. Even the birds don’t want to take off.

The dunes in Corolla, NC.
Luckily for me, I found this geometry problem to mess around with:

A geometry problem.
There are many ways to solve this, but I thought it might be interesting to try something a little different. Here’s the same problem in Geogebra:

Geogebra line intersections.
The intersection of line and line is and the intersection of with is . Geogebra does a great job of calculating the intersections, but there’s a nice trick for finding the intersection of two lines using linear algebra.
A linear algebra trick
Since two points define a line, we can start by looking at how pairs of points on two lines are related to the point of intersection.

The point of intersection of two lines.
The equations of the lines and can be written in terms of their starting points and , direction vectors, and coefficients and ,
The point of intersection is then
If the intersection is between the points defining the lines then . But, how do we solve for and ? Let’s rewrite the equations in vector form, letting the initial points be and . Now,
where the vector directions are and . For line the vector shows the direction you would need to go to get from the starting point to the ending point .
The point of intersection (assuming the lines intersect) occurs when . Now here’s a neat trick - take the cross product of both sides with
since the cross product of any vector with itself is . Subtract from both sides to get
and then solve for
You can solve for the same way,
but you only need one of the two solutions. The point of intersection is
The cross product gives the angle between two vectors and is related to the lengths of each,
where the notation is the length of the vector and is the angle between vectors and . The direction of the cross product is which is perpendicular to both and .

The cross product.
Testing the formula
We can test the formula by finding the intersection of the lines and . The line has initial point and direction . The second line, has initial point and direction . This gives
as shown in the Geogebra plot. Call the function line_intersect
in Julia as
p = [0;0];
q = [4;4];
r = [2;4];
s = [2;-4];
F = line_intersect(p,q,r,s)
2-element Vector{Float64}:
2.6666666666666665
2.6666666666666665
For the second intersection, change to to get
The inputs are all 2-element vectors, but the cross product requires 3-element vectors. This is corrected in the code by adding a to the end of each input vector, e.g. push!(p,0)
. When the solution is calculated, the 3rd element is still there, so we use pop!(p_int)
to remove the in the direction.
Heron’s formula
You may know the formula for the area of a triangle as one-half the base times the height.

A triangle with altitude splitting base into .
The base is , but you have to calculate the height to get the area. Heron’s formula is more direct,
where is the semi-perimeter, or half the perimeter of the triangle,
Heron of Alexandria (also known as Hero) was a mathematician and engineer

Ἥρων, Heron of Alexandria.
Ἥρων, Heron of Alexandria
known for many inventions such as this steam engine called an aeolipile which uses the principle of action/reaction of steam venting through the pipes to spin the ball.

An aeolipile. Vented steam causes the ball to spin.
He is credited with the triangle area formula, but it was likely known much earlier.
There are many proofs of Heron’s formula such as this one which uses the Pythagorean formula for right angle triangles. In the figure above, we can get two representations of the altitude ,
Subtracting the first from the second and solving for gives
Substitute this value of back into the first Pythagorean formula and solve for to get
The first step above is to use the identity , and then the third line is derived from .
Now that we have the height of the triangle we can get the area,
The Julia code for Heron’s formula is included in redflag.jl
as herons
.
The Red Flag Solution
With these two functions, we can now solve the problem. In Julia define the points
A = [0,0];
B = [4,4];
C = [3,4];
D = [2,4];
E = [4,0];
The points of intersection are
F = line_intersect(A,B,D,E-D)
2-element Vector{Float64}:
2.6666666666666665
2.6666666666666665
G = line_intersect(A,C,D,E-D)
2-element Vector{Float64}:
2.4000000000000004
3.2
and the area of the small triangle is
T = herons(A,F,G)
1.0666666666666644
The problem asked for the ratio of the triangle area to the square area as a percentage:
T/16 * 100
6.666666666666653
Sometimes you might like having a lazy day at the beach and not doing much more than solve a crossword puzzle. Solving this geometry puzzle is a bit like doing a crossword puzzle. There might not be a practical application for it, but you will find many opportunities to solve for the intersections of two lines, and knowing Heron’s formula can also be handy.
This solution using linear algebra and Heron’s formula isn’t the only way to find the answer, and it’s always a good idea to check your answer by solving the problem with several unique methods.
I’m not sure why anyone would spend time making sand castles when you could be solving a geometry problem.

Hero of the beach.
A Day at the Beach
This geometry puzzle allowed us to look at a method to calculate the intersection of two lines using techniques from linear algebra, and to calculate the area of a triangle with Heron’s method. There are many practical applications where you’ll need to find the intersection of two lines such as:
- Computer Graphics: Determining where lines or edges meet in rendering
- Game Development: Collision detection between objects
- Geographic Information Systems (GIS): Finding where roads or boundaries intersect
- Computer Vision: Detecting intersections in image processing
- CAD/CAM Software: Calculating tool paths and design intersections
Heron’s also might find practical applications in
- Land Surveying: Calculating plot areas from measured sides
- Architecture: Computing irregular floor areas
- Engineering: Structural analysis and design
- Navigation: Distance and area calculations
- Game Development: Terrain and collision calculations
While our beach puzzle was purely recreational, the techniques we used are fundamental tools in many fields of science and engineering. Whether you’re designing video games, analyzing satellite data, or planning construction projects, understanding geometric intersections and area calculations is invaluable.
And here’s a picture of a Brazilian jasmine I found at the beach.

Brazilian jasmine.
Code for this article
The two Julia functions, line_intersect
and herons
are in the file redflag.jl.
Software
- Geogebra - GeoGebra is dynamic mathematics software for all levels of education that brings together geometry, algebra, spreadsheets, graphing, statistics and calculus in one easy-to-use package.
- Julia - The Julia Project as a whole is about bringing usable, scalable technical computing to a greater audience: allowing scientists and researchers to use computation more rapidly and effectively; letting businesses do harder and more interesting analyses more easily and cheaply.
References and further reading
- Line–line intersection: Wikipedia
- Intersection of two straight lines: Math Open Reference
- Cross product: Wikipedia
- Heron’s Formula: CueMath
- Heron’s Formula Calculator: OMNI Calculator
- Heron of Alexandria: Wikipedia
- Aeolipile: Wikipedia
Image credits
- Triangle with altitude h cutting base c into d + (c − d): By Jamgoodman - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=74872701.
- Hero of Alexandria: By Unknown author - http://www.xtec.es/~jcanadil/imatges/personatges/actius/Heron.jpg, Public Domain, https://commons.wikimedia.org/w/index.php?curid=24180886.
- Aeolipile: The entry under Aeolipile in volume one of this work states “The cut is copied from Hero’s “Spiritalia”, edited by Woodcroft, of London.” - Knight’s American Mechanical Dictionary, 1876. source, Public Domain, https://commons.wikimedia.org/w/index.php?curid=42014.