Computer Code

The spherical and plane trigonometric laws pertaining to a triangle:  cosine, haversine, sine (long and short forms), tangent, half-tangent, Napier (one and two), and area are provided as functions, which may be cut and pasted into an application.

The following code is intended for Maple(r) 7

Instructions

  1. with a mouse, select the whole following section.
  2. hit cntrl-C.
  3. in your Maple 7 worksheet, left-click your mouse where you want to insert this code.
  4. Edit --> Paste Maple text.
  5. left-click mouse at top of the pasted text.
  6. hit Enter repeatedly, until past the bottom of this code.

You have all of the functions life, in Maple!


> # COMMON functions

The sides of the triangle are {sa, sb, sc} and the opposite angles are {aA, aB, aC}.

for brevity, a few functions

> ss:=unapply((sa+sb+sc)/2,(sa,sb,sc));

> aS:=unapply((aA+aB+aC)/2,(aA,aB,aC));

> sr:=unapply(sqrt(sin(ss(sa,sb,sc)-sa)*sin(ss(sa,sb,sc)-sb)*sin(ss(sa,sb,sc)-sc)/sin(ss(sa,sb,sc))),(sa,sb,sc));

> aR:=unapply(sqrt(cos(aS(aA,aB,aC)-aA)*cos(aS(aA,aB,aC)-aB)*cos(aS(aA,aB,aC)-aC)/cos(Pi-aS(aA,aB,aC))),(aA,aB,aC));

definition of the haversine function and its inverse

> hav:=unapply((sin(x/2))^2,x);

> archav:=unapply(2*arcsin(sqrt(x)),x);

the archav above is the principal-value. the other value is its negative.

[place holder]

 

> # SPHERICAL laws

This is the spherical section.

spherical law of cosines. Caution: do NOT use these equations for numerical calculation! Instead, use the law of haversines or its dual.

> law_cos_sa:=unapply(arccos(sin(sb)*sin(sc)*cos(aA)+cos(sb)*cos(sc)),(sb,sc,aA));

> law_cos_aA:=unapply(arccos((cos(sa)-cos(sb)*cos(sc))/(sin(sb)*sin(sc))),(sa,sb,sc));

and its dual

> law_cosdual_aA:=unapply(arccos(sin(aB)*sin(aC)*cos(sa)-cos(aB)*cos(aC)),(aB,aC,sa));

> law_cosdual_sa:=unapplly(arccos((cos(aA)+cos(aB)*cos(aC))/(sin(aB)*sin(aC))),(aA,aB,aC));

spherical law of haversines

> law_hav_sa:=unapply(archav(hav(sb-sc)+sin(sb)*sin(sc)*hav(aA)),(sb,sc,aA));

> law_hav_aA:=unapply(archav((hav(sa)-hav(sb-sc))/(sin(sb)*sin(sc))),(sa,sb,sc));

and its dual

> law_havdual_aA:=unapply(Pi-archav(hav(aB-aC)+sin(aB)*sin(aC)*hav(Pi-sa)),(aB,aC,sa));

> law_havdual_sa:=unapply(Pi-archav((hav(Pi-aA)-hav(aB-aC))/(sin(aB)*sin(aC))),(aA,aB,aC));

each of the foregoing six functions is the principal-value. the other value is the negative of the principal-value.

spherical isosceles law of haversines

> law_isosceles_hav_sa:=unapply(2*arcsin(sin(sb)*sin(aA/2)),(sb,aA));

> las_isosceles_hav_aA:=unapply(2*arcsin(sin(sa/2)/sin(sb)),(sa,sb));

and its dual

> law_isosceles_havdual_aA:=unapply(2*arccos(sin(aB)*cos(sa/2)),(aB,sa));

> law_isosceles_havdual_sa:=unapply(2*arccos(cos(aA/2)/sin(aB)),(aA,aB));

spherical law of sines (short and long forms) and their duals. In the calling sequence of the short form only, the side sb and angle aB may be replaced by the side sc and angle aC, respectively

> law_sin_expr:=unapply(sqrt((2* cos(sa)* cos(sb)* cos(sc) + ((sin(sa))^2 + (sin(sb))^2 + (sin(sc))^2)^2 - 2)) / (sin(sa)* sin(sb) *sin(sc)),(sa,sb,sc));

> law_sin_short_aA:=unapply(arcsin(sin(sa)*sin(aB)/sin(sb)),(sa,aB,sb));

> law_sin_long_aA:=unapply(arcsin(sin(sa)*law_sin_expr(sa,sb,sc)),(sa,sb,sc));

> law_sin_short_sa:=unapply(arcsin(sin(aA)*sin(sb)/sin(aB)),(aA,aB,sb));

> law_sin_long_sa:=unapply(arcsin(sin(aA)*law_sin_expr(Pi-aA,Pi-aB,Pi-aC)),(aA,aB, aC));

each of the foregoing four functions is the principal-value. the other value is the supplement of the principal-value.

We may combine the haversine and sine (short form) laws, to obtain a consistent additional angle (or side, in the case of the dual).

> law_hav_and_sin_aB:=unapply(law_hav_aA(sb,sc,sa)*signum(law_sin_short_aA(sb,aA,sa)),(sa,sb,sc,aA));

> law_hav_and_sin_sb:=unapply(law_havdual_sa(aB,aC,aA)*signum(law_sin_short_sa(aB,aA,sa)),(aA,aB,aC,sa));

spherical law of tangents. Use as a check. The function should calculate to zero.

> law_tan:=unapply(tan((sb-sc)/2)/tan((sb+sc)/2)-tan((aB-aC)/2)/tan((aB+aC)/2),(sb,sc,aB,aC));

[place holder]

spherical law of half-tangent and its dual

> law_half_tan_aA:=unapply(2*arctan(sr(sa,sb,sc)/sin(ss(sa,sb,sc)-sa)),(sa,sb,sc));

> law_half_tan_sa:=unapply(2*arccot(aR(aA,aB,aC)/sin(aS(aA,aB,aC)-aA)),(aA,aB,aC));

[place holder]

spherical Napier's analogies and their duals

> napier_one_sc:=unapply(2*arctan(sin((aA+aB)/2)*tan((sa-sb)/2)/sin((aA-aB)/2)),(aA,aB,sa,sb));

> napier_one_aC:=unapply(2*arccot(sin((sa+sb)/2)*tan((aA-aB)/2)/sin((sa-sb)/2)),(sa,sb,aA,aB));

> napier_two_sc:=unapply(2*arctan(cos((aA+aB)/2)*tan((sa+sb)/2)/cos((aA-aB)/2)),(aA,aB,sa,sb));

> napier_two_aC:=unapply(2*arccot(cos((sa+sb)/2)*tan((aA+aB)/2)/cos((sa-sb)/2)),(sa,sb,aA,aB));

[place holder]

spherical area is equal to the spherical-excess E multiplied by the square of the radius of the sphere.

> spherical_excess_aE:=unapply(2*aS(aA,aB,aC)-Pi,(aA,aB,aC));

> spherical_lHuilier_sE:=unapply(4*arctan(sqrt(tan(ss(sa,sb,sc)/2)*tan((ss(sa,sb,sc)-sa)/2)*tan((ss(sa,sb,sc)-sb)/2)*tan((ss(sa,sb,sc)-sc)/2))),(sa,sb,sc));

[place holder]

> # PLANE laws

This is the plane section.

For brevity, the radii of the incricle and circumcircle.

> plane_sr:=unapply((ss(sa,sb,sc)-sa)*(ss(sa,sb,sc)-sb)*(ss(sa,sb,sc)-sc)/ss(sa,sb,sc),(sa,sb,sc));

> plane_aR:=unapply(sqrt((sa^2*sb^2*sc^2)/(4*sb^2*sc^2+sc^2*sa^2+sa^2*sb^2)-(sa^2+sb^2+sc^2)^2),(sa,sb,sc));

plane law of cosines. Caution: do NOT use these equations for numerical calculation! Instead, use the law of haversines or its dual.

> law_cos_plane_sa:=unapply(sqrt(sb^2+sc^2-2*sb*sc*cos(aA)),(sb,sc,aA));

> law_cos_plane_aA:=unapply(arccos((sb^2+sc^2-sa^2)/(2*sb*sc)),(sa,sb,sc));

and its dual

> law_cosdual_plane_aA:=unapply(aB+aC-Pi,(aB,aC));

plane law of haversines

> law_hav_plane_sa:=unapply(sqrt((sb-sc)^2+4*sb*sc*hav(aA)),(sb,sc,aA));

> law_hav_plane_aA:=unapply(archav((sa-(sb-sc))*(sa+(sb-sc))/(4*sb*sc)),(sa,sb,sc));

each of the foregoing four functions is the principal-value. the other value is the negative of the principal-value.

plane isosceles law of haversines

> law_isosceles_hav_plane_sa:=unapply(2*sb*sin(aA/2),(sb,aA));

> las_isosceles_hav_plane_aA:=unapply(2*arcsin(sa/(2*sb)),(sa,sb));

plane law of sines (short and long forms) and the dual of the short form, only. In the calling sequence of the short form only, the side sb and angle aB may be replaced by the side sc and angle aC, respectively.

> law_sin_short_plane_aA:=unapply(arcsin(sa*sin(aB)/sb),(sa,aB,sb));

> law_sin_long_plane_aA:=unapply(arcsin(sa/(2*plane_aR(sa,sb,sc))),(sa,sb,sc));

> law_sin_short_plane_sa:=unapply(arcsin(sin(aA)*sb/sin(aB)),(aA,aB,sb));

each of the foregoing four functions is the principal-value. the other value is the supplement of the principal-value.

plane law of tangents. Use as a check. The function should calculate to zero.

> law_plane_tan:=unapply((sb-sc)/(sb+sc)-tan((aB-aC)/2)/tan((aB+aC)/2),(sb,sc,aB,aC));

[place holder]

plane law of half-tangent and its dual

> law_half_tan_plane_aA:=unapply(2*arctan(plane_sr(sa,sb,sc)/(ss(sa,sb,sc)-sa)),(sa,sb,sc));

> law_half_tan_plane_sa:=unapply(2*sin(aS(aA,aB,aC)-aA)/plane_aR(aA,aB,aC),(aA,aB,aC));

each of the foregoing two functions is the principal-value. the other value is the negative of the principal-value.

[place holder]

plane Napier's analogies and their duals

> napier_one_plane_sc:=unapply(sin((aA+aB)/2)*(sa-sb)/sin((aA-aB)/2),(aA,aB,sa,sb));

> napier_one_plane_aC:=unapply(2*arccot((sa+sb)*tan((aA-aB)/2)/(sa-sb)),(sa,sb,aA,aB));

> napier_two_plane_sc:=unapply(cos((aA+aB)/2)*(sa+sb)/cos((aA-aB)/2),(aA,aB,sa,sb));

> napier_two_plane_aC:=unapply(Pi-(aA+aB),(aA,aB));

[place holder]

plane area may be computed by either of the following functions.

> plane_Heron_area:=unapply(sqrt(ss(sa,sb,sc)*(ss(sa,sb,sc)-sa)*(ss(sa,sb,sc)-sb)*(ss(sa,sb,sc)-sc)),(sa,sb,sc));

> plane_circum_area:=unapply((sa*sb*sc)/(4*aR(sa,sb,sc)),(sa,sb,sc));

> plane_in_area:=unapply(sr(sa,sb,sc)*ss(sa,sb,sc),(sa,sb,sc));

> plane_area:=unapply((sa*sb/2)*sin(aC),(sa,sb,aC));

[place holder]


Cyclical permutations of each of the foregoing functions, as well.

 

Strategy

This strategy is specifically for the solution of spherical triangles (but, may be employed for plane triangles, as well), employing the foregoing functions.  We adapt the reasonable, but purely arbitrary, convention that we will view a sphere from the outside and that we will traverse the boundary of a region on the sphere so that the region is on our left-side.  There are two difficulties:

With the foregoing convention, we distinguish the triangles ABC and ACB.

The ultimate goal is the solution of the triangle. That is, to find the three sides {sa,sb,sc} and the opposite three angles {aA,aB,aC}. We partition this problem according as the emphasis is on the sides or the angles, with the latter being the dual of the former.

sides.

We take as a sub-goal that of obtaining the three sides and only the one angle.

[place holder]

angles.

The angles are the dual of the sides, above.

We take as a sub-goal that of obtaining the three angles and only the one side.

[place holder]

plane angles.

This is easier than the foregoing "angles", which is applicable to either the spherical or plane cases.

[place holder]

alternatives.

Instead of the Napier analogy one, one may employ the corresponding Napier analogy two. Instead of the law of haversines, one may employ the corresponding law of half-tangents. Except for the resulting large errors, the corresponding law of cosines could be employed, as well.

 

 

 

Any comments or suggestions?  If you discover any errors; please, report them to the Webmaster, below.

 

Copyright (c) 2003 by R.I. 'Scibor-Marchocki  last modified Saturday 16-th August 2003.  mailto:Webmaster@rism.com