Tuesday, April 14, 2015

HP Prime and HP 50g: Spherical Triangles

HP Prime and HP 50g:  Spherical Triangles


These set of programs address four common scenarios of solving spherical triangles.

Spherical Triangle with angles A, B, C and sides a, b, c.
Referring to the diagram above:  a, b, and c (lowercase) represents the sides, while A, B, and C represent (upper case) represent the angles. 

The programs are named symbolizing your starting point.  S is used for side and A is used for angle.  (If you have better program names, feel free to suggest.)  All examples are given in degrees.

SSSSPHTRI:  Given Three Sides (a, b, c)

The equations used are: 

A = ACOS((COS(a)-COS(b)*COS(c))/(SIN(b)*SIN(c)))
B = ASIN(SIN(A)*SIN(b)/SIN(a))
C = ASIN(SIN(A)*SIN(c)/SIN(a))

HP Prime: 
EXPORT SSSSPHTRI(a,b,c)
BEGIN
LOCAL A,B,C;
// spherical triangles
// given external angels
// EWS 2015-04-13
A:=ACOS((COS(a)-COS(b)*COS(c))/
(SIN(b)*SIN(c)));
B:=ASIN(SIN(A)*SIN(b)/SIN(a));
C:=ASIN(SIN(A)*SIN(c)/SIN(a));
RETURN {A,B,C};

END;

HP 50g:
<< → a b c
<< a COS b COS c COS * - b SIN c SIN * / ACOS
DUPDUP SIN b SIN * a SIN / ASIN
SWAP SIN c SIN * a SIN / ASIN >> >>

Output:  A, B, C

Example:
Input:  a = 10,  b = 12,  c = 14
Output:  A = 44.7594887937, B = 57.4655995208, C = 78.8067166022

SSASPHRTRI:  Given Side, Side, Angle (b, c, B)

The equations used are:

C = ASIN(SIN(c)*SIN(B)/SIN(b))
A = ACOS((SIN(B)*SIN(C)*COS(b)*COS(c)-COS(B)*COS(C))/(1-SIN(B)*SIN(C)*
SIN(b)*SIN(c)))
a = ASIN(SIN(A)*SIN(b)/SIN(B))


HP Prime:
EXPORT SSASPHTRI(b,c,B)
BEGIN
// spherical triangle
// given b,c,B; return C,A,a
// EWS 2015-04-13
LOCAL C,A,a;
C:=ASIN(SIN(c)*SIN(B)/SIN(b));
A:=ACOS((SIN(B)*SIN(C)*COS(b)*COS(c)
-COS(B)*COS(C))/(1-SIN(B)*SIN(C)*
SIN(b)*SIN(c)));
a:=ASIN(SIN(A)*SIN(b)/SIN(B));
RETURN {C,A,a};

HP 50g:
<< → b c B
<< c SIN B SIN * b SIN / ASIN

DUPDUP DUP COS B COS * NEG SWAP SIN B SIN * b COS * c COS * +
SWAP SIN B SIN * b COS * c COS * + SWAP SIN B SIN * b SIN * c SIN *
NEG 1 + / ACOS

DUP SIN b SIN * B SIN / ASIN >> >>

Output: C, A, a

Example:
Input:  b = 12, c = 11, B = 49
Output:  C = 43.8384683062, A = 88.3203610398, a = 15.983905611

SASSPHITRI:  Given Side, Angle, Side (b, A, c)

Equations Used:
a = ACOS(COS(b)*COS(c)+SIN(b)*SIN(c)*COS(A))
B = ASIN(SIN(b)*SIN(A)/SIN(a))
C = ASIN(SIN(c)*SIN(A)/SIN(a))

HP Prime:
EXPORT SASSPHTRI(b,A,c)
BEGIN
// spherical triangle
// given b,A,c; return a,B,C
// EWS 2015-04-13
LOCAL a,B,C;
a:=ACOS(COS(b)*COS(c)+SIN(b)*SIN(c)
*COS(A));
B:=ASIN(SIN(b)*SIN(A)/SIN(a));
C:=ASIN(SIN(c)*SIN(A)/SIN(a));
RETURN {a,B,C};
END;

HP 50g:
<< → b A c
<< b COS c COS * b SIN c SIN * A COS * + ACOS
DUPDUP SIN INV b SIN * A SIN * ASIN
SWAP SIN INV c SIN * A SIN * ASIN >> >>

Output:  a, B, C

Example:
Input:  b = 10, A = 46.5, c = 12
Output:  a = 8.833284800833, B = 55.1114117424, C = 79.1481099363

AASSPHITRI:  Given Angle, Angle, Side (A, B, a)

Equations Used:
b = ASIN(SIN(B)*SIN(a)/SIN(A))
c = ACOS((COS(a)*COS(b)-SIN(a)*SIN(b)*COS(A)*COS(B))/(1-SIN(a)*SIN(b)*SIN(A)*SIN(B)))
C = ACOS(−COS(A)*COS(B)+SIN(A)*SIN(B)*COS(c))

HP Prime:
EXPORT AASSPHTRI(A,B,a)
BEGIN
// spherical triangle
// EWS 2015-04-13
// given A,B,a; return b,c,C
LOCAL b,c,C;
b:=ASIN(SIN(B)*SIN(a)/SIN(A));
c:=ACOS((COS(a)*COS(b)-SIN(a)*SIN(b)*
COS(A)*COS(B))/(1-SIN(a)*SIN(b)*SIN(A)
*SIN(B)));
C:=ACOS(−COS(A)*COS(B)+SIN(A)*SIN(B)
*COS(c));
RETURN {b,c,C};
END;

HP 50g:
<<  → A B a
<< B SIN a SIN * A SIN / ASIN

4 NDUPN DROP
COS a COS * SWAP SIN a SIN * A COS * B COS * NEG +
SWAP SIN a SIN * A SIN * B SIN * NEG 1 + / ACOS

DUP COS B SIN * A SIN * A COS B COS * - ACOS >> >>

Output:  b, c, C

Example:
Input:  A = 41, B = 33, a = 12
Output:  b ≈ 9.939, c ≈ 17.641, C ≈ 107.004

HP 50g Programming Notes:

DUPDUP:  Left Shift, EVAL (PRG), F1 (STACK), NXT, NXT, F5 (DUPDUP)

NDUPN:  (object, number of times to be duplicated -> duplicated objects, number)
Left Shift, EVAL (PRG), F1 (STACK), Left Shift, NXT (PREV), F1 (NDUPN)

NEG: +/-

INV:  1/X


Source:
Weisstein, Eric W. "Spherical Trigonometry." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/SphericalTrigonometry.html  Retrieved April 11, 2015


This blog is property of Edward Shore.  2015

Fun with the HP 30b

Fun with the HP 30 b Introduction The following programs are for the HP 30b Business Professional. Did you know that the 30b...