HP Forums
(35S) Azimuth to Bearing/Quadrant and vice-versa - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (35S) Azimuth to Bearing/Quadrant and vice-versa (/thread-9448.html)



(35S) Azimuth to Bearing/Quadrant and vice-versa - JeremyBeck - 11-06-2017 10:57 PM

The following program will convert Azimuths to a Bearing/Quadrant format and vice versa. The quadrants are numbered from 1 to 4 starting in the north east and working clockwise.

Code:

B001    LBL B
B002    SF 10
B003    π
B004    π
B005    BEARING
B006    X=Y?
B007    GTO B029
B008    HMS→
B009    STO B
B010    QUADRANT
B011    STO Q
B012    RCL Q
B013    2
B014    ÷
B015    IP
B016    180
B017    x
B018    RCL Q
B019    180
B020    x
B021    COS
B022    RCL B
B023    x
B024    -
B025    STO A
B026    →HMS
B027    STOP
B028    GTO B003
B029    π
B030    π
B031    AZIMUTH
B032    X=Y?
B033    GTO B003
B034    HMS→
B035    STO A
B036    IP
B037    90
B038    INT÷
B039    1
B040    +
B041    STO Q
B042    RCL A
B043    SIN
B044    ASIN
B045    ABS
B046    STO B
B047    →HMS
B048    RCL Q
B049    STOP
B050    GTO B029
B051    RTN

After executing the program BEARING will be displayed. At this point enter the bearing to be converted in H.P. notation(dd.mmsss) followed by R/S. If a bearing was entered then QUADRANT will be displayed, enter the quadrant followed by R/S. The display will now show the azimuth in H.P. notation on the X register. Pressing R/S at this point will display BEARING. If no bearing is entered or, a bearing of 3.14159265359 is entered the program will display AZIMUTH. Enter the azimuth to be converted in H.P. notation and press R/S. The display will now show the bearing in H.P. notation on the Y register and the quadrant on the X register. At this point if R/S is pressed the display will show AZIMUTH. If no azimuth was entered, or an azimuth of 3.14159265359 was entered the program will display BEARING. Pressing R/S and not entering anything in will switch between BEARING and AZIMUTH.

The variables used by this program are:
A, stores the azimuth in decimal degrees.
B, stores the bearing in decimal degrees.
Q, stores the quadrant number 1-4 where 1 is north east, 2 is south east, 3 is south west, and 4 is north west.

To take a bearing and quadrant and convert it to an azimuth:

For the north-east quadrant, the bearing is the azimuth.
For the south-east quadrant, the bearing needs to be subtracted from 180 to obtain the azimuth.
For the south west quadrant, the bearing must be added to 180 to obtain the azimuth.
For the north-west quadrant, the bearing must be subtracted from 360 to obtain the azimuth.

First the quadrant is divided by 2 and the integer portion multiplied by 180. This will produce either a 0, 180, 180, or 360 depending on the quadrant.
Then the cosine of the quadrant multiplied by 180 is taken which will produce either +1 or -1. This is multiplied by the baring which makes it negative for the north-west and south-east quadrants or positive for the north-east and south-west quadrants.
The result is then added to the first step to produce the azimuth.

To convert an azimuth to a bearing and quadrant is a little easier.
First the integer portion of the azimuth is divided by 90 and the integer portion taken.
The result is added to 1 to obtain the quadrant.
Then the arcsine of the sine of the azimuth is taken of which the absolute value is the bearing.


RE: (35S) Azimuth to Bearing/Quadrant and vice-versa - PedroLeiva - 11-07-2017 12:58 AM

(11-06-2017 10:57 PM)JeremyBeck Wrote:  The following program will convert Azimuths to a Bearing/Quadrant format and vice versa. The quadrants are numbered from 1 to 4 starting in the north east and working clockwise.

Jeremy, very interestig. Could you please include some examples to test how the program solves? TYVM, Pedro


RE: (35S) Azimuth to Bearing/Quadrant and vice-versa - JeremyBeck - 11-07-2017 04:54 PM

(11-07-2017 12:58 AM)PedroLeiva Wrote:  
(11-06-2017 10:57 PM)JeremyBeck Wrote:  The following program will convert Azimuths to a Bearing/Quadrant format and vice versa. The quadrants are numbered from 1 to 4 starting in the north east and working clockwise.

Jeremy, very interestig. Could you please include some examples to test how the program solves? TYVM, Pedro

I've attached a PDF of some test examples (one for each quadrant)


RE: (35S) Azimuth to Bearing/Quadrant and vice-versa - PedroLeiva - 11-08-2017 12:50 PM

(11-07-2017 04:54 PM)JeremyBeck Wrote:  
(11-07-2017 12:58 AM)PedroLeiva Wrote:  Jeremy, very interestig. Could you please include some examples to test how the program solves? TYVM, Pedro

I've attached a PDF of some test examples (one for each quadrant)

I like very much the way you have presented the examples, thank you.
I would suggest to combine this procedure for the calculation of angles in a poligonal, by azimuts differences (maybe with a routine for another program). Is that posible?
Pedro


RE: (35S) Azimuth to Bearing/Quadrant and vice-versa - Dieter - 11-08-2017 06:56 PM

(11-06-2017 10:57 PM)JeremyBeck Wrote:  The following program will convert Azimuths to a Bearing/Quadrant format and vice versa. The quadrants are numbered from 1 to 4 starting in the north east and working clockwise.

I admit I don't know anything about azimuths and bearings, but I noticed that your program uses a quite creative way of checking whether something has been entered or not. This is done by storing pi in X and Y, and after the prompt the program checks whether X and Y are equal.

I would like to suggest another method. The user enters either bearing and quadrant or an azimuth. Since all values are positive (or at least not negative) the sign of the user input may be used to distinguish whether the one or the other has been entered. Also bearing and quadrant may be entered simultaneously, e.g. with bearing [ENTER] quadrant. A negative quadrant then can be used as a marker. See below for some examples.

Here is a program that implements this idea, using the same formulas as yours (but without any variables). I was not sure what the IP in your line B036 is for, so it was simply omitted. #-)

Code:
B001  LBL B
B002  DEG
B003  SF 10
B004  BRG^-Q OR AZIM
B005  CF 10
B006  x≥0?
B007  GTO B027
B008  +/-
B009  ENTER
B010  ENTER
B011  2
B012  INT÷
B013  180
B014  x
B015  x<>y
B016  LASTx
B017  x
B018  COS
B019  R↑
B020  HMS→
B021  x
B022  -
B023  →HMS
B024  ENTER
B025  STOP
B026  GTO B006
B027  HMS→
B028  ENTER
B029  SIN
B030  ASIN
B031  ABS
B032  →HMS
B033  x<>y
B034  90
B035  INT÷
B036  1
B037  +
B038  +/-
B039  STOP
B040  GTO B006

The user enters either bearing and a negative (!) quadrant, or an azimuth.

Example: convert an azimuth of 103°22'35" to bearing and quadrant, and vice versa. Then convert a bearing of 60° in quadrant 2 to the equivalent azimuth.

Code:
[XEQ] B [ENTER]      =>  BRG^-Q OR AZIM

  103,2235    [R/S]  =>  76,3735
                         -2

              [R/S]  =>  103,2235
                         103,2235

60 [ENTER] -2 [R/S]  =>  120
                         120

So you don't have to answer several prompts and the result also has a marker that identifies the quadrant number with a minus sign.

BTW, the idea with the negative sign may also be applied to your program. Instead of 2x pi the program may simply have -1 in X before the prompt. Since the user will not enter any negative data, a following x<0? test will determine whether something has been entered or not.

Dieter


RE: (35S) Azimuth to Bearing/Quadrant and vice-versa - JeremyBeck - 11-09-2017 03:42 PM

(11-08-2017 06:56 PM)Dieter Wrote:  I admit I don't know anything about azimuths and bearings, but I noticed that your program uses a quite creative way of checking whether something has been entered or not. This is done by storing pi in X and Y, and after the prompt the program checks whether X and Y are equal.

I was originally using X=0? to test if a user entered anything in or not but I ran across multiple instances where I needed to enter a 0. that is when I thought of using π. Even if I needed to type in π I would not be carrying it out as may places as does the calculator.

(11-08-2017 06:56 PM)Dieter Wrote:  I would like to suggest another method. The user enters either bearing and quadrant or an azimuth. Since all values are positive (or at least not negative) the sign of the user input may be used to distinguish whether the one or the other has been entered. Also bearing and quadrant may be entered simultaneously, e.g. with bearing [ENTER] quadrant. A negative quadrant then can be used as a marker. See below for some examples.

I do like your idea of using a negative quadrant. I never thought of that. I may be changing the program I have now. Being able to enter the number then executing the program and not having any prompts will save on memory and time for sure.