| home | contents | send comment | send link | add bookmark |

Plane Triangle Solver

by Stephen R. Schmitt

fixsideunits of length fixangledegrees
a:
A:
b:
B:
c:
C:
  units of area   messages
  area:
  info:

Contents

  1. About
  2. The source code
  3. Discussion

About

The Plane Triangle Calculator is a Java Script calculator that, given 3 of the 6 elements (sides and interior angles) of a triangle, computes the other 3 elements.

To operate the calculator, first select three known elements of the triangle to "fix" their values by using the check boxes. Next, enter the values of the elements in the upper text boxes corresponding to each element. Last, press the calculate button. Pressing the clear button clears all entries. Possible messages:

On invalid entries, the element windows will display:
NaN -- Not a Number

Return to Contents


The source code

The Java Script source code for this program can be viewed by using the View|Source command of your web browser.

You may use or modify this source code in any way you find useful, provided that you agree that the author has no warranty, obligations or liability. You must determine the suitability of this source code for your use.

Return to Contents


Discussion

A plane triangle is defined by 3 interior angles and 3 line segments. These parameters are not independent.

Given at least one side and any two of the other parameters, the remaining parameters can be computed. There may be two, one, or no solutions for some combinations of three given parameters. The triangle is solved using the laws of sines and cosines, shown below.

Law of sines

sin A   sin B   sin C
----- = ----- = -----
  a       b       c

Law of cosines

a2 = b2 + c2 - 2·b·c·cos A   
b2 = a2 + c2 - 2·a·c·cos B
c2 = a2 + b2 - 2·a·b·cos C

Example

Given, a = 4, c = 7, A = 25°; the remaining parameters are computed using:

C = sin-1 [(c/a)·sin A]            law of sines

B = 180.0 - (A + C)                sum of interior angles = 180
     ______________________
b = √ a2 + c2 - 2·a·c·cos B        law of cosines
Using the equations above, we get:
C = sin-1 [(7/4)·sin 25°] = 47.7°
 
B = 180.0 - (25° + 47.7°) = 107.3°
     ________________________
b = √ 16 + 49 - 56·cos 107.3° = 9.04
There are two possible values of C since the range of sin-1 is 0°...180°. The other possible value is 132.3° which gives us a second feasible solution:
C = 132.3°

B = 180.0 - (25° + 132.3°) = 22.7°
     _______________________
b = √ 16 + 49 - 56·cos 22.7° = 3.65

Area using Hero's formula

In this calculator, the areas of the triangles are computed from the lengths of the three sides, a, b, c using the formula below which was first stated and proved by Hero of Alexandria in the first century AD.

s = (a + b + c)/2                  semi perimeter
        __________________________
Area = √ s·(s - a)·(s - b)·(s - c)

Hero (or Heron) of Alexandria (~10 AD to ~70 AD) was a Greek engineer. He is most famous for the invention of the first steam engine, the aeolipile. In this device, steam is generated in a boiler and fed into a sphere through a pair of hollow spindles. The sphere would spin from the reaction force created by ejecting the steam under pressure through two angled nozzles.

References/u>

Return to Contents


AbCd Classics - free on-line books


Copyright © 2004, Stephen R. Schmitt