GPS waypoint distance in Km


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003
    Posts
    985

    Default GPS waypoint distance in Km

    Code:
    '****************** Use Pythagoras' Theorem To Calculate Distance From Waypoint ********************************
    '
    'assumes you have lat & longitudinal difference in degrees and minutes loaded into arrays
    '
    'Example Lat & Longitude arrays
    'L0,L1 degrees L2,L3 decimal point L4,L5,L6,L7
    'L8,L9,LA degrees LB,LC decimal point LD,LE,LF,LG
    '
    '
    Way_Distance:						'
    IF L7 > 4 THEN L6 = L6 + 1				'round off last two decimal places
    IF L6 > 4 THEN L5 = L5 + 1				'of latitude difference
    '
    degB = L2 * 1000					'
    degB = degB + (L3 * 100)				'
    degB = degB + (L4 * 10)					'
    degB = degB + L5					'
    '
    L0 = L0 * 10						'
    L0 = L0 + L1						'
    '
    IF LG > 4 THEN LF = LF + 1				'round off last two decimal places
    IF LF > 4 THEN LE = LE + 1				'of longitude difference
    '
    degC = LB * 1000					'
    degC = degC + (LC * 100)				'
    degC = degC + (LD * 10)					'
    degC = degC + LE					'
    '
    degree = L8 * 100					'
    degree = degree + (L9 * 10)				'
    degree = degree + LA					'
    '
    gosub degB_mod						'
    degA = L0 * 110						'1 degree = 110 Km @ 27 degrees latitude
    degA = degA + (degB / 100)				'add 100%
    degA = degA + remainder					'
    degB = degB / 100					'calculate 83%
    degB = degB * 83					'
    gosub degB_mod						'
    degA = degA + (degB / 100)				'add to make 183%
    degA = degA + remainder					'
    '
    gosub degC_mod						'
    degree = degree * 98					'1 degree = 98 Km @ 152 degrees longitude
    degree = degree + (degC	/ 100)				'add 100%
    degree = degree + remainder				'
    degC = degC / 100					'calculate 63%
    degC = degC * 63					'
    gosub degC_mod						'
    degree = degree + (degC / 100)				'add to make 163%
    degree = degree + remainder				'
    '
    degree = degree * degree				'Pythagoras' theorem: C² = A² + B²    /|
    degA = degA * degA					'                                    / |
    degree = degree + degA					'                                  C/  |
    degree = SQR degree					'                                  /_A_|B
    '
    L0 = degree Dig 4					'prepare coordinate variables as display buffer
    L1 = degree dig 3					'
    L2 = degree dig 2					'
    L3 = degree dig 1					'
    L4 = degree dig 0					'
    L0 = L0 + 48						'convert back to ASCII for LCD display
    L1 = L1 + 48						'
    L2 = L2 + 48						'
    L3 = L3 + 48						'
    L4 = L4 + 48						'
    goto printKM						'
    '
    degB_mod:						'
    remainder = degB // 100					'calculate remainder of the next divide
    goto Calc_mod						'
    degC_mod:						'
    remainder = degC // 100					'calculate remainder of the next divide
    Calc_mod:						'
    IF remainder > 49 THEN					'round off remainder to the nearest unit
    remainder = 1						'
    goto done_modulus					'
    ENDIF							'
    remainder = 0						'
    done_modulus:						'
    return							'
    This is a rough routine to calc distance on Km from a waypoint given that
    the latitude & longitudinal difference in degrees has already been aquired by
    subtracting waypoint coordinates from present location or vice versa.
    It relies on the fiction that the distance in Km of 1 degree is constant
    so it will become less accurate as the device moves further away from my
    own geographic coordinates because one degree longitudes becomes
    serverely shorter as you move toward one of the poles.

    printKm: would be a routine that writes L0 - L4 values on an LCD display
    and then the word Kilometers.
    Where to go with it next??

  2. #2
    Join Date
    Jul 2005
    Posts
    11


    Did you find this post helpful? Yes | No

    Default Calculating Km's from waypoint

    Thanks for that Art, will give it a go .

    Cheers

    Nigel VK4FNA (Lake Moogerah, Queensland )

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. Replies: 1
    Last Post: - 26th June 2009, 23:33
  3. GPS clock timing !
    By bethr in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 3rd July 2008, 20:11
  4. Replies: 2
    Last Post: - 28th April 2006, 12:10
  5. GPS Receiver
    By lester in forum Adverts
    Replies: 2
    Last Post: - 22nd February 2006, 12:47

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts