Showing posts with label azimuth. Show all posts
Showing posts with label azimuth. Show all posts

Thursday, May 16, 2019

Casio fx-CG50 and HP Prime: Azimuth/Bearing Conversions

Casio fx-CG50 and HP Prime: Azimuth/Bearing Conversions

Introduction




The programs A2B (Azimuth to Bearing) and B2A (Bearing to Azimuth) convert angles between two measuring systems that are commonly used by civil engineers and navigators.

The program uses an unusual approach: the use of the arcsine, sine, and cosine functions.   These functions are used on because on scientific calculators, the trigonometric functions return answers in specific ranges.

Let x be a real number.  then:

asin(x) returns answers in the range -90° to 90°  (-π/2 to π/2 radians)

acos(x) returns answers in the range 0° to 180°  (0 to π radians)

atan(x) returns answers in the range -90° to 90°  (-π/2 to π/2 radians)

This was used in the HP 33E program from the calculator book "HP 33E: Surveying Applications".  See Source below.

Formulas:

A = azimuth
B = bearing
Q = quadrant  (1,2,3,4)

Azimuth to Bearing:

B = abs( asin( sin A ) )
Q = int(A/90 + 1)

(Yes, the asin/sin is there for a purpose: to get an angle in the range of -90° to 90°)

Bearing to Azimuth:

A = 180° * int(Q/2) - B * cos(Q * 180°)

In the programs A2B and B2A, both input and output will be degrees-minutes-seconds format.

To enter degrees-minutes-seconds:

Casio fx-CG50:  [ OPTN ] [ F6 ] (more) [ F5 ] (ANGLE)  [ F4 ] (° ' ")

HP Prime:  [ Shift ] [ a b/c ] or [ Shift ] [ 9 ] (select °, ', or '' from the menu)

Azimuth to Bearing Program A2B

Casio fx-CG50 Program A2B (Azimuth to Bearing)

ClrText
Locate 1,4,"AZIMUTH TO BEARING"
Deg
"AZ: "? → A
Abs( sin^-1 ( sin A ) ) → B
"BEARING ="
B ▶ DMS ◢
Intg( A ÷ 90 + 1 ) → Q
"QUADRANT = "
Q = 1 ⇒ "NE"
Q = 2 ⇒ "SE"
Q = 3 ⇒ "SW"
Q = 4 ⇒ "NW"

HP Prime Program A2B (Azimuth to Bearing)

EXPORT A2B(A)
BEGIN
// Azimuth to Bearing
HAngle:=1;  // Degrees
LOCAL B, Q, L0:={"NE","SE","SW","NW"};
B:=ABS(ASIN(SIN(A)));
Q:=IP(A/90+1);
RETURN { →HMS(B), L0(Q) }
END;

Example 1:  220° 15' 36"
Result:  40°15'36". SW

Example 2:  184°00'14"
Result: 4°00'14"  SW

Bearing to Azimuth Program B2A

Casio fx-CG50 Program B2A  (Bearing to Azimuth) 

ClrText
Locate 1,4,"BEARING TO AZIMUTH"
Deg
"BEARING: "? → B
Menu "QUADRANT", "NE", 1, "SE", 2, "SW", 3, "NW", 4
Lbl 1: 1 → Q: Goto 5
Lbl 2: 2 → Q: Goto 5
Lbl 3: 3 → Q: Goto 5
Lbl 4: 4 → Q: Goto 5
Lbl 5
180 * Intg( Q ÷ 2 ) - B * cos( Q * 180 ) → A
"AZ ="
A ▶ DMS

HP Prime Program B2A (Bearing to Azimuth)

Arguments:  Bearing, Quadrant.  You can enter Quadrant by a string or numerical quadrant.  "NE" = 1,  "SE" = 2,  "SW" = 3, "NW" = 4

EXPORT B2A(B,q)
BEGIN
// Bearing to Azimuth
// q "NE", "SE", "SW", "NW"
// or 1,2,3,4
LOCAL A, L0:={"NE","SE","SW","NW"};
HAngle:=1;  // Degrees
// deal with strings
IF TYPE(q)==2 THEN
q:=POS(L0,q);
END;
A:= 180 * IP(q/2) - B * cos(q * 180);
RETURN →HMS(A);
END;

Example 3:  43°21'55"  SW (q = 3)
Result:  223°21'55"

Example 4:  13°14'56"  SE (q = 2)
Result:  166°45'04"

Source:

Hewlett Packard.  "HP33E:  Surveying Applications"  Hewlett Packard Company.  March 1978

Eddie

All original content copyright, © 2011-2019.  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.

Sunday, October 21, 2018

HP 11C (and Emulators): Sun's Approximate Declination, Altitude, and Azimuth

HP 11C (and Emulators):  Sun's Approximate Declination, Altitude, and Azimuth

Introduction

The following program calculates three positions for our Sun in our Solar System:

1.  Declination of the Sun (δ = 0° at the Equinoxes)
2.  Altitude of the Sun (height of the sun)
3.  Azimuth of the Sun (degree from latitude ground-wise north)
 
Formulas Used:

Inputs:
D = days after the vernal equinox (usually March 20 or March 21)
L = latitude given in D.MMSS format (avoid ±90°)
T = time before solar noon (12 PM).  Example: 9 AM, T= 3.  3 PM, T = -3.

Declination:
δ = 23.45 * sin(D * 0.9856)

Altitude:
H = asin(cos L * cos D * cos(15 * T)) + sin L * sin D)

Azimuth:
A = acos((sin H * sin L - sin D) / (cos L * cos H))

Before running the program, store D in R1, L in R2, and T in R3.

HP 11C Program: Sun Declination, Altitude, Azimuth

001 42, 21, 13 LBL C
002 43, 7 DEG
003 45, 1 RCL 1
004 48 .
005 9 9
006 8 8
007 5 5
008 6 6
009 20 ×
010 23 SIN
011 2 2
012 3 3
013 48 .
014 4 4
015 5 5
016 20 ×
017 44, 4 STO 4
018 31 R/S
019 24 COS
020 45, 2 RCL 2
021 43, 2 →H
022 24 COS
023 20 ×
024 45, 3 RCL 3
025 1 1
026 5 5
027 20 ×
028 24 COS
029 20 ×
030 45, 2 RCL 2
031 43, 2 →H
032 23 SIN
033 45, 4 RCL 4
034 23 SIN
035 20 ×
036 40 +
037 43, 23 ASIN
038 44, 5 STO 5
039 31 R/S
040 23 SIN
041 45, 2 RCL 2
042 43, 2 →H
043 23 SIN
044 20 ×
045 45, 4 RCL 4
046 23 SIN
047 30 -
048 45, 2 RCL 2
049 43, 2 →H
050 24 COS
051 45, 5 RCL 5
052 24 COS
053 20 ×
054 10 ÷
055 43, 24 ACOS
056 44, 6 STO 6
057 43,32 RTN


Example 1:
Stored Data: 
R0 = 184 (approximately September 21),
R1 = -14° 50' 12" (entered as -14.5012)
R2 = 0 (noon)

Output:
δ ≈ 13.1576°
H ≈ 62.0058°
A = 180.0000°

Example 2:
Stored Data: 
R0 = 68 
R1 = 46°
R2 = 4 (8 AM)

Output:
δ ≈ 21.5892°
H ≈ 35.9899°
A ≈ 84.4083°

Sources:

Hewlett Packard.  "Sun Altitude, Azimuth, Solar Pond Absorption", HP 67/97 Energy Conservation December 1978.
Shore, Edward.  "HP 35S: Sun Altitude, Azimuth, Solar Pond Absorption"  Eddie's Math and Calculator Blog:  http://edspi31415.blogspot.com/2013/06/hp-35s-sun-altitude-azimuth-solar-pond.html  June 7, 2013

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Sunday, July 19, 2015

HP Prime & TI-84: Bearing and Azimuth Conversions

HP Prime & TI-84:  Bearing and Azimuth Conversions

Azimuth vs Bearing


AZ2BE (Azimuth to Bearing)
Note:  Bearings start clockwise from due north.  Bearings will be reduced to angles between 0° to 360°.

Three outputs will be returned:  bearing, direction string, and quadrant reference number (for reference).  The HP Prime version will return a list.  

HP Prime AZ2BE:
EXPORT AZ2BE(θ)
BEGIN
// Azimuth to Bearing
// EWS 2015-07-19
LOCAL q,b,s;
θ≔θ MOD 360;
q≔IP(θ/90)+1;
// Determining the Bearing Angle
IF q==1 THEN
b≔θ; s:=”NE”;
END;
IF q==2 THEN
b≔ABS(θ-180); s≔”SE”;
END;
IF q==3 THEN
b≔θ-180; s≔”SW”;
END;
IF q==4 THEN
b≔ABS(θ-360); s≔”NW”
END;
RETURN {b,s,q};
END;

TI-84+ AZ2BE:
Input "ANGLE:",θ
360*fPart(θ/360)+360*(θ<0)→θ
iPart(θ/90)+1→Q
If Q=1:Then
θ→B
"NE"→Str1:End
If Q=2:Then
abs(θ-180)→B
"SE"→Str1
End
If Q=3:Then
θ-180→B
"SW"→Str1
End
If Q=4:Then
abs(θ-360)→B
"NW"→Str1
End
Disp "BEARING",B
Disp Str1,Q

BE2AZ  (Bearing to Azimuth)
Note:  Bearings outside of range of 0° to 90° or quadrant numbers outside of 1 to 4 will result in an “UNEXPECTED RESULT” message. 

Quadrants:
Quadrant 1:  Northeast
Quadrant 2:  Southeast
Quadrant 3:  Southwest
Quadrant 4:  Northwest

HP Prime BE2AZ:
EXPORT BE2AZ(b,q)
BEGIN
// Bearing to Azimuth
// bearing, quadrant
// 1 = NE, 2 = SE, 3 = SW, 4 = NW
// 2015-07-19 EWS

LOCAL θ;

// Are b and q in the proper range?
IF b<0 OR b>90 OR q<1 OR q>4 THEN
RETURN “Unexpected Value”;
KILL;
END;

// Calculation
q≔IP(q);
IF q==1 THEN
θ≔b;
END;
IF q==2 THEN
θ≔180-b;
END;
IF q==3 THEN
θ≔b+180;
END;
IF q==4 THEN
θ≔360-b;
END;
RETURN θ;
END;

TI-84+ BE2AZ:
Input "BEARING:",B
Disp "1=NE"
Disp "2=SE"
Disp "3=SW"
Disp "4=NW"
Input "Q:",Q
If B<0 or B>90 or Q<1 or Q>4
Then
Disp "UNEXPECTED VALUE"
Stop
End
iPart(Q)→Q
If Q=1:Then
B→θ:End
If Q=2:Then
180-B→θ:End
If Q=3:Then
B+180→θ:End
If Q=4:Then
360-B→θ:End
Disp "AZIMUTH:",θ

Examples:

Azimuth:  68°, Bearing: 68° bearing NE (q=1)
Azimuth: 164°, Bearing:  16° bearing SE (q=2)
Azimuth: 224°, Bearing:  44° bearing SW (q=3)
Azimuth: 321°, Bearing:  39° bearing NW (q=4)


This blog is property of Edward Shore.  2015

Tuesday, March 3, 2015

HP Prime: Solar Position (Right Ascension, Declination, Altitude, Azimuth)

HP Prime: Solar Position (Right Ascension, Declination, Altitude, Azimuth)

Input:
* Month
* Date
* Year
* Local Time (your local standard time – do not adjust for daylight savings time)
* Longitude
* Latitude


Local Time:  Use a 24 Hour clock. When entering time, you can enter a decimal or hours°minutes’seconds’’.

Longitude:  This is your location, going east from the Greenwich Prime Meridian.  East is positive, West is negative. Range: -180° to 180°

Latitude: This is your location, going north from the Equator.  North is positive, South is negative.  Range:  -90° to 90°

Entering HMS:

HP Prime:  Use Shift+9 and select the appropriate symbol (°, ‘, or ‘’)

Output:
r:  Distance from the Earth to the Sun in astronomical units (AU)
α:  Right ascension in decimal hours
δ:  Declination in decimal degrees
eot:  Equation of Time in minutes
alt:  Altitude/Elevation
azi:  Azimuth, from due North going clockwise

Please keep in mind that these are approximate answers.

Also, a 2-column matrix is returned to the home screen for reference.  The first column is the input column, the second is the output column.

[[ month,  distance ]
[ day,  right ascension ]
[ year, declination ]
[ local time, declination ]
[ longitude, altitude ]
[ latitude, azimuth ]]

HP Prime:  solar

EXPORT solar()
BEGIN
// aa.usno.navy.mil
// Updated 2015-03-01 EWS

// month, day, year, local standard
// time, longitude, latitude
LOCAL m,D,Y,lstd,long,lat;

INPUT({m,D,Y,lstd,long,lat},
"Data: Use Shift+9 for H°M′S″",
{"Month:","Date :","Year :",
"Local Time (24):", "Long (+E):",
"Lat (+N)"});

// Initialization
LOCAL d,g,q,L,r,ec,gmt;
LOCAL eot,alt,lha,azi,zen,loc;
LOCAL α,δ,g1,g2;
LOCAL w1,w2;
HAngle:=1;

// Greenwich Mean Time
gmt:=lstd-long/15;

// Julian Date
d:=367*Y-IP(7*(Y+IP((m+9)/12))/4)
+IP((275*m)/9)+D+1721013.5+gmt/24
-0.5*SIGN(100*Y+m-190002.5)+0.5;
d:=d-2451545;

// Intermediate Calculations
g:=(357.529+.98560028*d)  MOD 360;
q:=(280.459+.98564736*d) MOD 360;
L:=(q+1.915*SIN(g)+.02*SIN(2*g)) MOD 360;
r:=1.00014-.01671*COS(g)-.00014*COS(2*g);
ec:=23.439291-.00000036*d;

α:=ARG(COS(L)+SIN(L)*COS(ec)*i) MOD 360;

// Convert to hours
α:=α/15;

// Declination
δ:=ASIN(SIN(ec)*SIN(L));

// Equation of Time
eot:=q/15-α;
eot:=eot*60;

// Greenwich Mean Time (in hours)
g1:=-0.000319*SIN(−125.04-0.052954*d)
-2.4ᴇ−5*SIN(560.94+1.9713*d);
gmt:=(18.697374558+24.06570982441908*d
+g1*COS(ec)) MOD 24;

// Hour Angle (in degrees)
lha:=(gmt-α)*15+long;

// Altitude (approximate)
alt:=ASIN(SIN(lat)*SIN(δ)+
COS(lat)*COS(δ)*COS(lha));

// Azimuth
// Clockwise from South
azi:=ARG(SIN(lha)*i+COS(lha)*SIN(lat)
-TAN(δ)*COS(lat));
// Convert to clockwise from North
azi:=azi+180;

PRINT();
PRINT("Sun "+m+"/"+D+"/"+Y+" ; "+lstd);
PRINT("Distance: "+r);
PRINT("α (hours): "+α);
PRINT("δ (degrees): "+δ);
PRINT("eot (minutes): "+eot);
PRINT("Approximate");
PRINT("alt (elevation): "+alt);
PRINT("azi (North-clockwise): "+azi);

PRINT("DEGREES MODE SET");
RETURN [[m,r],[D,α],[Y,δ],[lstd,eot],
[long,alt],[lat,azi]];
END;


Example:

Input:
June 1, 2015; 12:00 PM , Longitude: -118°13’59”, Latitude: 34°3’

Output:
r = 1.01406353128 AU
α = 4.6292012064 hr
δ = 22.0919016903°
eot = 2.157339456 min
alt = 78.032250726°
azi = 182.442424012°


Resources:

The United States Naval Observatory (USNO)  Washington, D.C.:
“Approximate Solar Coordinates” (URL:  http://aa.usno.navy.mil/faq/docs/SunApprox.php )
“Approximate Sidereal Time” (URL: http://aa.usno.navy.mil/faq/docs/GAST.php )
“Computing Altitude and Azimuth from Greenwich Apparent Sidereal Time” (URL: http://aa.usno.navy.mil/faq/docs/Alt_Az.php )
“Converting Between Julian Dates and Gregorian Calendar Dates” (URL: http://aa.usno.navy.mil/faq/docs/JD_Formula.php )
Retrieved February 23, 2015 to March 1, 2015

This blog is property of Edward Shore - 2015


Friday, June 7, 2013

HP 35S: Sun Altitude, Azimuth, Solar Pond Absorption

HP 35S: Sun Altitude, Azimuth, Solar Pond Absorption

Source: Sun Altitude, Azimuth, Solar Pond Absorption, HP 67/97 Energy Conservation December 1978, Author: HP

Input:

This program asks for:

D = days after March 21 (later will be sun's declination : 23.45 sin (D * .9856°) )
L = latitude given in D.MMSS (degrees minutes seconds) format (avoid ±90°)
T = time before solar noon (12:00 PM), if the time is after noon, enter hours as a negative (example: 3:00 PM → -3)
N = index of refraction of surface/fluid (see below)


Index of Refraction for Common Objects:

Water: 1.33
Ice: 1.309
Glass: 1.52
Diamond: 2.42



Formulas: (Degrees Mode)

Sun Declination
D = 23.45 * sin( days after March 21 * .9856°)

Altitude of the Sun (H):
H = asin (cos L * cos D * cos (15 * T) + sin L * sin D)

Azimuth of the Sun (A): (degree from latitude ground wise north)
A = acos ( (sin H * sin L - sin D) ÷ (cos L * cos H) )

Fraction of the surface penetrated by the sun that hour (T):
T = 2 * n * (x^2 + y^2) * sin H * cos R
Where
R = asin (cos H ÷ n)
x = (cos R + n * sin H)^-1
y = (sin H + n * cos R)^-1

Example 1:

Input:
D = 68 (May 28), L = 46°, T = 4 (8:00 AM), N = 1.33 (water)

Output:
H (altitude) = 35.98991°
A (azimuth) = 84.40835°
F (fraction of coverage) = 0.95943

Example 2:

Input:
D = 90 (June 19), L = 23°, T = -3 (3:00 PM), N = 2.42 (diamond)

Output:
H = 48.81756°
A = 99.85903°
F = 0.82156



Program:

U001 LBL U
U002 INPUT D \\ declination
U003 DEG
U004 0.9856
U005 *
U006 SIN
U007 23.45
U008 *
U009 STO D \\ altitude
U010 COS
U011 INPUT L
U012 HMS→ \\ or → H
U013 STO L
U014 COS
U015 *
U016 INPUT T
U017 15
U018 *
U019 COS
U020 *
U021 RCL L
U022 SIN
U023 RCL D
U024 SIN
U025 *
U026 +
U027 ASIN
U028 STO H
U029 VIEW H \\ azimuth
U030 SIN
U031 RCL L
U032 SIN
U033 *
U034 RCL D
U035 SIN
U036 -
U037 RCL L
U038 COS
U039 RCL H
U040 COS
U041 *
U042 ÷
U043 ACOS
U044 STO A
U045 VIEW A

U046 RCL H \\ fraction
U047 COS
U048 INPUT N
U049 ÷
U050 ASIN
U051 STO R
U052 COS
U053 RCL H
U054 SIN
U055 RCL* N
U056 +
U057 1/x
U058 x^2
U059 RCL H
U060 SIN
U061 RCL R
U062 COS
U063 RCL* N
U064 +
U065 1/x
U066 x^2
U067 +
U068 RCL* N
U069 2
U070 *
U071 RCL H
U072 SIN
U073 *
U074 RCL R
U075 COS
U076 *
U077 STO F
U078 VIEW F
U079 RTN




This blog is property of Edward Shore. 2013

Python in Numworks: Duplicating and Grayscale

Python in Numworks: Duplicating and Grayscale All three scripts presented today use the math, random, and the Numworks specific ...