Getting Through The Big Triangle Problem

The triangle problem comes up constantly in data processing, engineering calculations, and geometry-heavy codebases. You get three values, sometimes from messy sensor readings, sometimes from user input that barely makes sense, and you have to determine whether they form a valid triangle, classify it, and often work out angles or area. People overcomplicate it because they start with the wrong assumption. At its core, you are dealing with a set of constraints. Three positive numbers can only form a triangle when the sum of any two sides exceeds the third. This is the triangle inequality theorem. Most people memorize it as a + b > c, but that is incomplete. It actually means a + b > c AND a + c > b AND b + c > a. All three conditions must hold simultaneously. If you only check one, you will silently accept invalid input and produce garbage downstream. I learned this the hard way on a project where we were validating surveyor measurements. We checked only the first condition, and our area calculations ended up returning NaN for entire classes of degenerate triangles. The fix was three explicit checks, nothing fancy. The Big Triangle Problem Answers generally fall into two categories: determining validity and then extracting useful properties once validity is confirmed. Getting the first step right matters more than optimizing the second.

The Practical Approach

Sort your three values first. Put the largest value last. Once sorted so that a b c, you only need to verify that a + b > c. The other two inequalities become automatically true because c is already the biggest side. This cuts your validation logic from three comparisons to one. It seems trivial until you are writing this check inside a loop processing hundreds of thousands of triangles. After validation, classification follows a straightforward path. If all three sides differ, it is scalene. If exactly two match, it is isosceles. If all three match, it is equilateral. For right triangles, apply the Pythagorean theorem: a² + b² should equal c² within some acceptable floating-point tolerance. That tolerance point is where most implementations break. Do not use exact equality checks with floats. Use something like abs(a*a + b*b - c*c)

1e-9 instead. I spent a week debugging what I thought was a classification bug before realizing that 0.70710678² plus 0.70710678² does not equal exactly 1.0 in IEEE 754 arithmetic. It equals 0.9999999999999998. Your triangle is right. The math is just slightly off. For area, use Heron's formula once the triangle is validated. Calculate the semi-perimeter s = (a + b + c) / 2, then area = sqrt(s * (s-a) * (s-b) * (s-c)). The intermediate values stay well-behaved for normal-sized inputs. The formula breaks down near degeneracy though. When a + b approaches c closely, the term (s-c) approaches zero and floating-point cancellation can introduce significant error. In those edge cases, switch to the formula area = 0.5 * a * b * sin(C), where C is the angle between sides a and b, computed via the law of cosines. It is slightly more expensive computationally but far more stable near degenerate boundaries.

Common Pitfalls

Negative or zero side lengths are the most obvious issue. Input validation should reject anything 0 before you do any geometry. But there is a less obvious one: integer overflow. If your sides are large integers and you compute a*a or a+b without casting to a wider type, you will wrap around silently. This happens in languages like C and C++ routinely. Cast to a 64-bit integer or a float before squaring. Another frequent mistake is assuming that an isosceles right triangle will always pass the right-triangle check using squared integers. It usually does, but only if your tolerance handling is correct. A third pitfall that catches people out involves collinear points. Three values where a + b exactly equals c describe a degenerate triangle — a straight line. Strict inequality is required. Some applications accept degenerates, some reject them. Decide early and document it. My team once inherited a library that silently accepted degenerate triangles and returned zero area, which looked fine until someone tried to compute altitudes and got division by zero errors.

Get the Full Details

Solved: 3-6 The Big Triangle Problem Below is a figure that contains several triangles. Record t ...
Solved: 3-6 The Big Triangle Problem Below is a figure that contains several triangles. Record t ...

When The Standard Approach Fails

If you are working in a high-throughput environment where every microsecond counts, Heron's formula is fast but the square root at the end is the bottleneck. There is no way around it for exact area. If you only need to compare areas without computing the actual value, skip the square root entirely and compare the product s*(s-a)*(s-b)*(s-c) directly. It is monotonically increasing with area, so ordering is preserved without the costly operation. For triangle classification alone, you never need to compute any angles or areas. Side-length comparisons are sufficient and take roughly three comparisons plus two equality checks. If you are processing millions of triangles per second, this distinction matters.

A Realistic Edge Case

Last year I ran into a case where a user submitted three sides that were valid under normal rounding but caused problems in downstream code. The values were 0.33333333, 0.33333334, and 0.33333333. Mathematically they form a near-equilateral triangle, and numerically they pass the inequality check. But when fed into a rendering pipeline that computes barycentric coordinates, the near-degenerate angle calculations produced flickering artifacts on the GPU. The workaround was to add a minimum valid angle threshold. If any computed angle fell below a certain value, the triangle was classified as degenerate and rejected. The threshold value depends entirely on your application. For graphics work, around 1e-6 radians works well. For structural analysis, you would need a much tighter bound. Write a single function that returns a structured result containing validity, classification, area, and angles. Do not split this into multiple functions that recompute the same things. Cache intermediate values. Validate first, classify second, compute derived properties only if valid. This ordering prevents wasted computation and keeps error paths clean. Here is a compact reference implementation in Python that covers validation, classification, and area:

import math

def solve_triangle(a, b, c):
    if a <= 0 or b <= 0 or c <= 0:
        return None
    sides = sorted([a, b, c])
    if sides[0] + sides[1] <= sides[2]:
        return None
    s = sum(sides) / 2
    area = math.sqrt(s * (s - sides[0]) * (s - sides[1]) * (s - sides[2]))
    if sides[0] == sides[1] == sides[2]:
        kind = "equilateral"
    elif sides[0] == sides[1] or sides[1] == sides[2] or sides[0] == sides[2]:
        kind = "isosceles"
    else:
        kind = "scalene"
    if abs(sides[0]2 + sides[1]2 - sides[2]2) < 1e-9:
        kind += " right"
    return {"kind": kind, "area": area}
This handles the common cases. It does not handle every edge case in production code, and you should add input sanitization, logging, and the near-degenerate rejection logic I mentioned above. But for a starting point, it is solid. The main thing to remember is that the triangle problem is deceptively simple. The validation is one line. Everything after that is where mistakes accumulate. Pay attention to floating-point behavior, handle degenerates explicitly, and do not trust that your input is well-behaved. It rarely is.

3-6 The Big Triangle Problem
3-6 The Big Triangle Problem