Results 1 to 7 of 7

Thread: Problems with grid square distance?

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    4

    Problems with grid square distance?

    locator.rar

    Hello,
    I have problem with calculations of latitude and longitude in my programm. Programm work, but at the finnish, distance in km is wrong, for short distance it's +- 1-2 km wrong, and for long distance is +- 4-7 km wrong.
    Programm calculate distance between grid squares (Maidenhead grid squares).

    This is formula from IARU Region 1 VHF Committee:
    Distance = 111,2 * arccos(sin Latitude1 * sin Latitude2 + cos Latitude1 * cos Latitude2 * cos(Longitude1-Longitude2))

    where the conversion factor is 111,2 km/deg.

    Points rounding methods:
    Distance Commenced km Math Truncation
    0 km 1 0 0
    43,2 km 44 43 43
    56,7 km 57 57 56

    Please, can anyone look at my code and help me to found error in code?

    Thank you very much in advance.

  2. #2
    PowerPoster
    Join Date
    Jul 06
    Location
    Maldon, Essex. UK
    Posts
    5,157

    Re: Problems with grid square distance?

    I think there's a problem converting the Locator to Latitude and Longitude
    For my location (JO01ir) Your program is returning 51.729, -0.7083 whereas my 'real' location is 51.7252, 0.6686. (I don't understand why you're deliberately negating the Longitude.) The variation in Latitude amounts to about 14 seconds and I guess is 'acceptable' but the Longitude is significantly out.

    It looks as if you're adjusting the calculation to find the centre of the final sub-square but you're subtracting 0.5 degrees (30 minutes) from both Latitude and Longitude. This square is 5 minutes by 2.5 minutes

    It's a bit difficult trawling through your code as there are no comments and little structure - I assume you've converted something like this http://ilgonis.orgfree.com/software.htm#MHD to VB6

    BTW What are you comparing your results with ?
    (G3XJL)

    EDIT: Just been playing around, it looks as if the calculation returns the Latitude and Longitude of the bottom left corner of the Sub-Square, so to adjust to the centre of the square you'll have to add 1.25 minutes to the Longitude and 2.5 minutes to the Latitude.
    Last edited by Doogle; Sep 9th, 2012 at 05:12 AM.

  3. #3
    New Member
    Join Date
    Sep 12
    Posts
    4

    Re: Problems with grid square distance?

    Thank you very much Doogle for fast answer.
    I comparing my results with this calculator: http://hrvhf.net/contest.php (on the top in Menu you have QRB TEST)

    Where I must exactly in code to add 1.25 minutes to the Longitude and 2.5 minutes to the Latitude and how?

    My code is converted from WB5KIA site, from his calculator.

    Best regards!

  4. #4
    PowerPoster
    Join Date
    Jul 06
    Location
    Maldon, Essex. UK
    Posts
    5,157

    Re: Problems with grid square distance?

    Actually the adjustment is a bit of a Red Herring, since it's the distance you're calculating. I suspect the problem may be associated with the ArcCos and / or PI.

    I've attached the Project I was 'playing' with - it appears to be consistant with the 9A-VHF-UHF-SHf Portal you quoted earlier
    Attached Files Attached Files

  5. #5
    New Member
    Join Date
    Sep 12
    Posts
    4

    Re: Problems with grid square distance?

    Thank you again. Your code work better then my.

    Strange thing also by your code:
    When calculate: JO01IR-KN04XX then is all ok: 1732 km
    But, when calculate: JO01IR-KN04WW the is result: 1729 km, (must be 1730 km)
    And when calculate: JO01IR-KN04VV then is all ok: 1727 km

    All others locators work perfect. Only for this calculation I found error, all others try give me ok results.
    Thank you very much for your time.

  6. #6
    PowerPoster
    Join Date
    Jul 06
    Location
    Maldon, Essex. UK
    Posts
    5,157

    Re: Problems with grid square distance?

    I think it may be something to do with the adjustment of Latitude and Longitude to locate the centre of the sub-square. I thought that the basic calculation gives the bottom left had corner of the sub-square; if that's incorrect then there's room for errors. I'll see if I can find out exactly how to adjust. If I remove the adjustments, then the distances seem to increase by 1Km.

    EDIT: I think I've found the problem, I got the adjustments the wrong way round. They should be:
    Code:
    '
    ' Adjust to the centre of the Sub-Square
    '
    dblLong = dblLong + CDbl(2.5 / 60)
    dblLat = dblLat + CDbl(1.25 / 60)
    Last edited by Doogle; Sep 10th, 2012 at 12:43 AM.

  7. #7
    New Member
    Join Date
    Sep 12
    Posts
    4

    Re: Problems with grid square distance?

    Now code work perfect.
    But, again one problem: all calculations under 100 km distance is wrong, calculations adds +1 km.
    All calculations (no matter what the field is in use) now over 100 km distance work perfect.

    Maybe for this problem under 100 km I can simply add in code that: if is distance under 100 km value of calculations simply add +1 km, and problem is solved?
    I will play today with code and will see if code calculate value +1 km for every grid square under 100 km.

Posting Permissions

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