TRI_SOLVE
This function solves a triangle when exactly three independent values are known across the three sides and three opposite angles. It returns all sides and all angles in a structured 2D output.
The solver applies standard trigonometric triangle relationships, primarily the Law of Sines and Law of Cosines:
\frac{a}{\sin(A)} = \frac{b}{\sin(B)} = \frac{c}{\sin(C)}
c^2 = a^2 + b^2 - 2ab\cos(C)
In side-side-angle (SSA) cases, two geometric solutions can exist. The ssa_flag option controls how ambiguous SSA cases are handled.
Excel Usage
=TRI_SOLVE(a, b, c, A, B, C, ssa_flag)
a(float, optional, default: null): Side length opposite angle A (length units).b(float, optional, default: null): Side length opposite angle B (length units).c(float, optional, default: null): Side length opposite angle C (length units).A(float, optional, default: null): Angle opposite side a (radians).B(float, optional, default: null): Angle opposite side b (radians).C(float, optional, default: null): Angle opposite side c (radians).ssa_flag(str, optional, default: “forbid”): SSA ambiguity handling mode.
Returns (list[list]): A 2D array where the first row is [a, b, c] and the second row is [A, B, C].
Example 1: Solve all values from three known sides
Inputs:
| a | b | c |
|---|---|---|
| 3 | 4 | 5 |
Excel formula:
=TRI_SOLVE(3, 4, 5)
Expected output:
| Result | ||
|---|---|---|
| 3 | 4 | 5 |
| 0.643501 | 0.927295 | 1.5708 |
Example 2: Solve from two sides and included angle
Inputs:
| a | b | C |
|---|---|---|
| 5 | 6 | 0.9 |
Excel formula:
=TRI_SOLVE(5, 6, 0.9)
Expected output:
| Result | ||
|---|---|---|
| 5 | 6 | 4.86861 |
| 0.934776 | 1.30682 | 0.9 |
Example 3: Solve from two angles and one side
Inputs:
| A | B | c |
|---|---|---|
| 1 | 0.8 | 7 |
Excel formula:
=TRI_SOLVE(1, 0.8, 7)
Expected output:
| Result | ||
|---|---|---|
| 6.04848 | 5.15634 | 7 |
| 1 | 0.8 | 1.34159 |
Example 4: Solve ambiguous SSA by selecting acute branch
Inputs:
| a | b | A | ssa_flag |
|---|---|---|---|
| 8 | 10 | 0.6 | acute |
Excel formula:
=TRI_SOLVE(8, 10, 0.6, "acute")
Expected output:
| Result | ||
|---|---|---|
| 8 | 10 | 13.9206 |
| 0.6 | 0.783556 | 1.75804 |
Python Code
from trianglesolver import solve as trianglesolver_solve
def tri_solve(a=None, b=None, c=None, A=None, B=None, C=None, ssa_flag='forbid'):
"""
Solve a triangle from any valid combination of three known side/angle values.
See: https://pypi.org/project/trianglesolver/
This example function is provided as-is without any representation of accuracy.
Args:
a (float, optional): Side length opposite angle A (length units). Default is None.
b (float, optional): Side length opposite angle B (length units). Default is None.
c (float, optional): Side length opposite angle C (length units). Default is None.
A (float, optional): Angle opposite side a (radians). Default is None.
B (float, optional): Angle opposite side b (radians). Default is None.
C (float, optional): Angle opposite side c (radians). Default is None.
ssa_flag (str, optional): SSA ambiguity handling mode. Valid options: Forbid, Acute, Obtuse. Default is 'forbid'.
Returns:
list[list]: A 2D array where the first row is [a, b, c] and the second row is [A, B, C].
"""
try:
result = trianglesolver_solve(a=a, b=b, c=c, A=A, B=B, C=C, ssa_flag=ssa_flag)
return [[result[0], result[1], result[2]], [result[3], result[4], result[5]]]
except Exception as e:
return f"Error: {str(e)}"