Showing posts with label spherical triangle. Show all posts
Showing posts with label spherical triangle. Show all posts

Saturday, May 25, 2024

Swiss Micros DM32: Spherical Triangle ft. Law of Cosines

Swiss Micros DM32: Spherical Triangle ft. Law of Cosines



Introduction


The state file spheretri.d32 is about solving triangles on the spherical space.





The programs solve spherical triangles in two common problems: SSS (side-side-side, really arc lengths) and SAS (side-angle-side). All the inputs are in decimal degrees.


Also calculated are the surface area and perimeter, both in radians. The radius is assumed to be 1.


Surface Area = ( A° + B° + C° ) * π / 180 – π = A + B + C – π


Perimeter = ( X° + Y° + Z°) * π / 180 = X + Y + Z


The sum of the angles (A, B, C) must be greater than 180° (π radians). Due to this requirement, in solving for angles and sides, the Law of Cosines will be used in each instance. The Law of Sines is only advised to check ratios.



Equation listing


Law of Sines – can be used as a check on triangles:

SIN(A)÷SIN(X)=SIN(B)÷SIN(Y)


Law of Cosines – two equations:

COS(Z)=COS(X)×COS(Y)+SIN(X)×SIN(Y)×COS(C)

COS(C)=-COS(A)×COS(B)+SIN(A)×SIN(B)×COS(Z)


Here the variables are general place holders.



Program Listing


Labels:

Label H: help program

Label I: Initialization routine. Sets the angles mode to degrees and clears the variables.

Label C: Starts the solve spherical triangle routine: given the three arc lengths X, Y, and Z.

Label Z: Starts the solve spherical triangle routine: given the arc lengths X and Y and and the angle between the arcs, angle C

Label F: Routine to solve for angles A and B, perimeter, and area



General Instructions


  1. To start a new problem, execute program I.

  2. To solve a spherical triangle given the sides (arc lengths), execute program C. (SSS)

  3. To solve a spherical triangle given two sides and the internal angle, execute program Z. (SAS)


This program also solves for the surface area, assuming a radius of 1, and perimeter of the triangle.


Program Code



H01 LBL H

H02 SF 10

H03 EQN: A N G L E _ A _ B _ C

H04 EQN: S I D E S _ X _ Y _ Z

H05 EQN: X E Q _ C _ S S S

H06 EQN: X E Q _ Z _ S A S

H07 EQN: E Q N S _ A R E _ S I N E

H08 EQN: A N D _ C O S I N E _ L A W S

H09 CF 10

H10 RTN


I01 LBL I

I02 DEG

I03 CLVARS

I04 CLx

I05 RTN


C01 LBL C

C02 INPUT X

C03 INPUT Y

C04 INPUT Z

C05 RCL Z

C06 COS

C07 RCL X

C08 COS

C09 RCL Y

C10 COS

C11 ×

C12 -

C13 RCL X

C14 SIN

C15 RCL Y

C16 SIN

C17 ×

C18 ÷

C19 ACOS

C20 STO C

C21 VIEW C

C22 XEQ F

C23 RTN


Z01 LBL Z

Z02 INPUT X

Z03 INPUT Y

Z04 INPUT C

Z05 RCL X

Z06 COS

Z07 RCL Y

Z08 COS

Z09 ×

Z10 RCL X

Z11 SIN

Z12 RCL Y

Z13 SIN

Z14 ×

Z15 RCL C

Z16 COS

Z17 ×

Z18 +

Z19 ACOS

Z20 STO Z

Z21 VIEW Z

Z22 XEQ F

Z23 RTN


F01 LBL F

F02 RCL X

F03 COS

F04 RCL Z

F05 COS

F06 RCL Y

F07 COS

F08 ×

F09 -

F10 RCL Z

F11 SIN

F12 RCL Y

F13 SIN

F14 ×

F15 ÷

F16 ACOS

F17 STO A

F18 RCL Y

F19 COS

F20 RCL X

F21 COS

F22 RCL Z

F23 COS

F24 ×

F25 -

F26 RCL X

F27 SIN

F28 RCL Z

F29 SIN

F30 ×

F31 ÷

F32 ACOS

F33 STO B

F34 RCL A

F35 RCL+ B

F36 RCL+ C

F37 →RAD

F38 π

F39 -

F40 STO R

F41 RCL X

F42 RCL+ Y

F43 RCL+ Z

F44 →RAD

F45 STO P

F46 VIEW A

F47 VIEW B

F48 VIEW R

F49 VIEW P

F50 RTN


You can download the DM32 state file here:


https://drive.google.com/file/d/1qX-y2G5sCOmm4ktmZbnGoPI3uzrx6IfF/view?usp=sharing



Examples  (FIX 5)


SSS Problem (LBL C)


X = 18.66°

Y = 20.49°

Z = 19.95°


Results:

C = 62.04726°

A = 55.92702°

B = 64.98954°

R = 0.05173 radians (surface area)

P = 1.03149 radians (perimeter)


SAS Problem (LBL Z)


X = 17.00 °

Y = 23.32°

C = 64.55°


Results:

Z = 21.88733°

A = 45.08768°

B = 73.51096 °

R = 0.05495 radians (surface area)

P = 1.08572 radians (perimeter)



Sources


Wikipedia. “Spherical Triangle” Updated April 9, 2024. Retrieved April 11, 2024.

https://en.wikipedia.org/wiki/Spherical_trigonometry#:~:text=Spherical%20trigonometry%20is%20the%20branch,sphere%2C%20geodesics%20are%20great%20circles.


Gray, Glen. “Spherical Trigonometry – An Introduction and Basic Theorems” Video. February 12, 2023. Retrieved April 11, 2024. https://www.youtube.com/watch?v=McWv9bcvMYg



Note: The blog will be posted on Saturdays only on June and July 2024.


Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

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

Friday, July 5, 2013

Spherical Triangle Solver - TI-84+

Spherical Triangle Solver: Programmed on a TI-84+ C Silver Edition

This could easily be ported to other programming calculators given how basic the TI-84+ programming is.

Variables:
"Sides" (Subtending Angles): X, Y, Z
Corresponding Angles: A, B, C

I try to capture all possible traps. No guarantees by I try. This program is rather large, about 1,500 bytes. Ending quotes and parenthesis can be left out on the TI-84+ but I present them in the text for completeness.

PROGRAM: SPHTRI
: Lbl 0
: ClrHome
: Output(1,1,"ANGLE (θ),SIDE")
: Output(2,1,"A, X")
: Output(3,1,"B, Y")
: Output(4,1,"C, Z")
: Output(6,1,"PRESS ENTER TO GO ON")
: Pause
: ClrHome
: Menu("KNOWN:","3 SIDES",1,
"2 S,INT θ (X,Y,C)",2,
"2 S,EXT θ (Y,Z,B)",3,
"1 S,2 ADJ θ (Z,A,B)",4,
"2 θS, ADJ SIDE (X,A,B)",5,
"3 ANGLES", 6
"EXIT",7)

: Lbl 1
: Input "SIDE X:", X
: Input "SIDE Y:", Y
: Input "SIDE Z:", Z
: If X+Y+Z>360°
: Then
: Disp "NO SOLN"
: Pause
: Goto 0
: End
: cos^-1 (( cos(X) - cos(Y) cos(Z) )/( sin(Y) sin(Z) )→ A
: cos^-1 (( cos(Y) - cos(X) cos(Z) )/( sin(X) sin(Z) )→ B
: cos^-1 (( cos(Z) - cos(X) cos(Y) )/( sin(X) sin (Y) )→ C
: Disp "A,B,C:",A,B,C
: Pause
: Goto 0

: Lbl 2
: Input "SIDE X:", X
: Input "SIDE Y:", Y
: Input "θ BETWEEN C:", C
: cos^-1 ( cos(X) cos(Y) + sin(X) sin(Y) cos(C) ) → Z
: sin^-1 ( sin(C) sin(X) / sin(Z) ) → A
: sin^-1 ( sin(C) sin(Y) / sin(Z) ) → B
: Disp "Z,A,B:",Z,A,B
: Pause
: Goto 0

: Lbl 3
: Input "SIDE Y:", Y
: Input "CORR. θ B:", B
: Input "ADJ. SIDE Z:", Z
: If Y < sin^-1 (sin(Z) sin(B) )
: Then
: Disp "NO SOLN."
: Pause
: Goto 0
: End
: sin^-1 ( sin(Z) sin(B) / sin(Y) ) → C
: 2 tan^-1 ( tan(.5Y - .5Z) sin(.5B + .5C) / sin(.5B - .5C) ) → X
: 2 tan^-1 ( sin(.5Y - .5Z) / tan(.5B - .5C) / sin(.5Y + .5Z) ) → A
: Disp "C,X,A:",C,X,A
: Pause
: If Y: Then
: 180° - C → S
: 2 tan^-1 (tan(.5Y - .5Z) sin(.5B + .5C) / sin(.5B - .5C) ) → T
: 2 tan^-1 (sin(.5Y - .5Z) / tan(.5B - .5S) / sin(.5Y + .5Z) ) → U
: Disp "ALT C,X,A:",S,T,U
: Pause
: End
: Goto 0

: Lbl 4
: Input "θ A:", A
: Input "θ B:", B
: Input "SIDE BETWEEN Z:", Z
: cos^-1 ( sin(A) sin(B) cos(Z) - cos(A) cos(B) ) → C
: cos^-1 ( (cos(A) + cos(B) cos(C)) / (sin(B) sin(C)) → X
: cos^-1 ( (cos(B) + cos(A) cos(C)) / (sin(A) sin(C)) → Y
: Disp "C,X,Y:",C,X,Y
: Pause
: Goto 0

: Lbl 5
: Input "θ A:", A
: Input "CORR. SIDE X:", X
: Input "ADJ θ B:", B
: sin^-1 (sin(X) sin(B) / sin(A) ) → Y
: 2 tan^-1 (tan(.5X-.5Y) sin(.5A+.5B) / sin(.5A-.5B)) → Z
: 2 tan^-1 (sin(.5X-.5Y) / tan(.5A-.5B) / sin(.5X+.5Y)) → C
: Disp "Y,C,Z:", Y,C,Z
: Pause
: Goto 0

: Lbl 6
: Input "θ A:", A
: Input "θ B:", B
: Input "θ C:", C
: If A+B+C<180° or A+B+C>540°
: Then
: Disp "NO SOLN."
: Goto 0
: Pause
: End
: Prompt A,B,C
: cos^-1 ((cos(A) + cos(B) cos(C))/(sin(B) sin(C)) → X
: cos^-1 ((cos(B) + cos(A) cos(C))/(sin(A) sin(C))→ Y
: cos^-1 ((cos(C) + cos(A) cos(B))/(sin(A) sin(B)) → Z
: Disp "X,Y,Z:",X,Y,Z
: Pause
: Goto 0

: Lbl 7

Sources:

Wikipedia: Solutions of Triangles
http://en.wikipedia.org/wiki/Solution_of_triangles#Solving_spherical_triangles

Had To Know: Spherical Trigonometry Calculator
http://www.had2know.com/academics/spherical-trigonometry-calculator.html

Examples - in Degrees Mode:

1. Given 3 Sides:
X: 34.49°
Y: 28.11°
Z: 29.00°
Solutions:
A: 76.64274255°
B: 54.05239674°
C: 56.40782913°

2. Given 2 Side with Interior Angle
X: 5.58°
Y: 7.24°
C: 164°
Solutions:
Z: 12.69684035°
A: 7.004143971°
B: 9.093527785°

3. Given 2 Sides with Exterior (Adjacent) Angle:
Y: 14.41°
B: 77.97°
Z: 18.00°
No Solution

Y: 7.09°
B: 44.8°
Z: 6.36°
Solutions:
C: 39.22735167°
X: 10.02551866°
A: 96.36477875°

4. Given 1 side and 2 adjacent angles
A: 75°
B: 88°
Z: 4.53°
Solutions:
C: 17.58132838°
X: 14.62939892°
Y: 15.14817154°


5. Given 2 Angles and 1 adjacent side
A: 103°
X: 2.66°
B: 71°
Solutions:
Y: 2.581182188°
C: 6.006268443°
Z: .2855550692°

6. Given 3 interior angles
A: 89°
B: 66°
C: 70°
Solutions:
X: 79.49157643°
Y: 63.94337829°
Z: 67.52897419°



This blog is property of Edward Shore. 2013

Sunday, June 2, 2013

HP 35S: Spherical Triangle

(First draft?)

Formulas:
sin A / sin a = sin B / sin b = sin C / sin c
cos A = - cos B cos C + sin B sin C cos a
cos a = cos b cos c + sin b sin c cos A

A, B, C are angles formed by the great circles (the "lines" of the Spherical triangle). Note that A + B + C > 180°. a, b, and c measure the arc length of great circles as angles measured from the center of the sphere.

Source: http://www.krysstal.com/sphertrig.html

Program: Label S
Calculator: HP 35S

I am not sure if I covered all possible scenarios.

Memory registers B and C are used for temporary purposes.

Given: B, A, b; Goal: a; Label S001
S001 LBL S
S002 SIN
S003 x<>y
S004 SIN
S005 ÷
S006 x<>y
S007 SIN
S008 ×
S009 ASIN
S010 RTN

Given: b, a, B; Goal: A; Label S011
S011 SIN
S012 x<>y
S013 SIN
S014 ×
S015 x<>y
S016 SIN
S017 ÷
S018 ASIN
S019 RTN

Given: a, b, c; Goal: A; Label S020
S020 STO C
S021 COS
S022 x<>y
S023 STO B
S024 COS
S025 ×
S026 x<>y
S027 COS
S028 x<>y
S029 -
S030 RCL B
S031 SIN
S032 RCL C
S033 SIN
S034 ×
S035 ÷
S036 ACOS
S037 RTN

Given: b, A, c; Goal: a; Label S038
S038 STO C
S039 SIN
S040 x<>y
S041 COS
S042 ×
S043 x<>y
S044 STO B
S045 SIN
S046 ×
S047 RCL C
S048 COS
S049 RCL B
S050 COS
S051 ×
S052 +
S053 ACOS
S054 RTN

Given: A, B, C; Find: a; Label S055
S055 STO C
S056 COS
S057 x<>y
S058 STO B
S059 COS
S060 ×
S061 x<>y
S062 COS
S063 +
S064 RCL B
S065 SIN
S066 RCL C
S067 SIN
S068 ×
S069 ÷
S070 ACOS
S071 RTN


Examples:


Given: B = 3.2145°, A = 2.2718°, b = 40°; XEQ S001; Result: a ≈ 65.4058°

Given: b = 60°, a = 40°, B = 4.95°; XEQ S011; Result A ≈ 3.6720°

Given: a = 4.11°, b = 5°, c = 6.03°; XEQ S020; Result A ≈ 42.5439°

Given: b = 3.996°, A = 49°, c = 6.314°; XEQ S038; Result a ≈ 4.7636°

Given: A = 124°, B = 45°, C = 76°; XEQ S055; Result a ≈ 124.4509°

Enjoy - hope this helps and have a great day!

Eddie

This blog is property of Edward Shore. 2013




Casio fx-991CW: Editing Variables

Casio fx-991CW: Editing Variables Introduction The newer set of Casio scientific calculators, better known as the Classwiz series, rev...