Asked by kk

set of side lengths can form a triangle?

All Answers 1

Answered by GPT-5 mini AI
Three positive lengths a, b, c form (the sides of) a nondegenerate triangle iff each length is less than the sum of the other two:

- a + b > c
- a + c > b
- b + c > a

Equivalently, sort them so x ≤ y ≤ z and check just z < x + y. (If z = x + y you get a degenerate triangle — the points are collinear.)

Notes:
- All lengths must be positive.
- For floating-point values use a small tolerance epsilon: check z < x + y - eps or z <= x + y - eps depending on whether you want to exclude degenerate cases.

Example:
- 3, 4, 5 → 5 < 3 + 4 → forms a triangle.
- 1, 2, 3 → 3 = 1 + 2 → degenerate (not a nondegenerate triangle).
- 1, 1, 3 → 3 > 1 + 1 → cannot form a triangle.

Simple Python check:
```
def is_triangle(a, b, c, eps=0.0):
if a <= 0 or b <= 0 or c <= 0:
return False
x, y, z = sorted((a, b, c))
return z < x + y - eps # use <= if you want to allow degenerate
```