?
Solved

Northing Easting Calculations..

Posted on 2003-03-09
8
Medium Priority
?
9,760 Views
Last Modified: 2011-09-20
Im using a Postcode component giving me an OS grid Easting and Northing positions. I have 2 coordinates, I need to measure the distance between the 2 points and also get the direction of travel. I have sussed out the direction problem (I think) but im struggling with the direction travelled. I need the direction to be in degrees so I can then calculate if they are travelling North, South or North-East etc?

Here is the code for distance:

Public Function Distance(x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double

Dim lowX As Double
Dim lowY As Double
Dim highX As Double
Dim highY As Double

'Get highest first x
If x1 > x2 Then
    highX = x1
    lowX = x2
Else
    highX = x2
    lowX = x1
End If

'Get highest first y
If y1 > y2 Then
    highY = y1
    lowY = y2
Else
    highY = y2
    lowY = y1
End If

dDistance = Format(Sqr(((highX - lowX) ^ 2 + (highY - lowY) ^ 2)) / 1609.3, "0.00")

End Function

I would be gratefully of any help on this one please?
0
Comment
Question by:Reddz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Expert Comment

by:Bros
ID: 8099480
If you dont nees the highX and highY i can tell you that thay dont make any diffrence

becouse for example
x1 = 625
x2 = 45

(x1 - x2) ^ 2 =>
(625 - 45) ^ 2 = 336400

vice versa

(x2 - x1) ^ 2 =>
(45 - 625) ^ 2 = 336400

---
so if you make an calculation x^2 you will allways get the resualt x>=0 but x can be both x and -x
---

anyway im not so god at trigonometri " yet :) "

but i think you can use this code:

'-------------------Functions----------------------------
Public Function aTan(Cosine)
'Inverse tangent in degrees
aTan = Atn(Cosine) / (3.14159265358979 / 180)
End Function

Public Function TanD(Degrees)
'Tangent in degrees
Tane = Tan(Degrees * (3.14159265358979 / 180))
End Function
'---------------------------------------------------

angle = aTan((Line1.x2 - Line1.x1) / (Line1.y2 - Line1.y1))

i hope it will be usefull anyway...
0
 

Expert Comment

by:Bros
ID: 8099498
sorry, my mistake

change this:
angle = aTan((Line1.x2 - Line1.x1) / (Line1.y2 - Line1.y1))

to:
angle = aTan((x2 - x1) / (y2 - y1))
0
 
LVL 2

Expert Comment

by:navneet77
ID: 8099520
you can find the slope by (y2-y1)/(x2-x1) which will be tangent. To find the degree from that use atn() and than convert them to degree

pi = 3.14159265358979
t = (Y2 - Y1) / (X2 - X1)
degree = Atn(t) * (180 / pi)

now if degree is greater than 45 degree he is traveling northward.

Hope that helps
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:redfordb
ID: 8101638
             B (s:t)
              .
             /|
            /b|
           /  |
          /   |
         /    |
        /a   c|  
       .------.
       A      C
      (m;n)  (s;n)
 
Given position A (m;n) and B(s;t), it follows that position C has co-ordinates (s;n).

The length of AC is therefore s-m
The length of BC is therefore t-n

The length of AB can be determines using pythagoras ie.
AB = Sqr(AC^2 + BC^2)
 
Add the following function to your project...

Function ASin(value As Double) As Double
    If Abs(value) <> 1 Then
        ASin = Atn(value / Sqr(1 - value * value))
    Else
        ASin = 1.5707963267949 * Sgn(value)
    End If
End Function

Define a variable to hold the angle na done for the bearing ie.

Dim Angle   As Double
Dim Bearing As Double

To determine angle a, call this function like this :
Angle = ASin(BC / AB)

Note that the value in "Angle" is in radians to convert it to degrees, multiply it by 57.29578 ie.
Angle = Angle * 57.29578

Now you have angle a. But thats the angle inside the triangle, you need to get the complentary angle to determine the bearing ie.

If Ax < Bx Then
    If Ay < By Then
       Bearing = 90 - Angle
    Else
       Bearing = 180 - Angle
    End If
Else
    If Ay < By Then
       Bearing = 360 - Angle
    Else
       Bearing = 270 - Angle
    End If
End If

And now you have the distance between the points, as well as the angle/bearing.








0
 

Author Comment

by:Reddz
ID: 8113600
Thank Guy I have sussed it out with a little more looking around the net, here's what ive come up with...


Dim Pi As Double
Dim Bearing As Double

'calculate Pi
    Pi = Atn(1) * 4

'Calculate the Distance Travelled
    dDistance = Sqr(((x2 - x1) ^ 2 + (y2 - y1) ^ 2))

'Convert Distance from metres to miles
    dDistance = dDistance / 1609.3

'Round Distance to nearest Mile .1
    dDistance = Round(dDistance, 1)


'Calculate Direction Travelled in degrees

    dx = x2 - x1
    dy = y2 - y1

'Check which quadrant we are in and find the degrees
    If dx > 0 Then
        Bearing = 90 - (180 / Pi) * Atn(dy / dx)
    End If
   
    If dx < 0 Then
        Bearing = 270 - (180 / Pi) * Atn(dy / dx)
    End If
   
    If dx = 0 Then
        If dy > 0 Then Bearing = 0
            If dy < 0 Then Bearing = 180
                If dy = 0 Then
                    dDirection = "None"
                    Exit Function
                End If
    End If
   
‘From the degrees work out if we are travelling North, South etc

    If Bearing > 0 And Bearing < 22.5 Then
        dDirection = "North"
    End If
   
    If Bearing > 22.5 And Bearing < 67.5 Then
        dDirection = "North East"
    End If
   
    If Bearing > 67.5 And Bearing < 112.5 Then
        dDirection = "East"
    End If
   
    If Bearing > 112.5 And Bearing < 157.5 Then
        dDirection = "South East"
    End If

    If Bearing > 157.5 And Bearing < 202.5 Then
        dDirection = "South"
    End If
   
    If Bearing > 202.5 And Bearing < 247.5 Then
        dDirection = "South West"
    End If
   
    If Bearing > 247.5 And Bearing < 292.5 Then
        dDirection = "West"
    End If
   
    If Bearing > 292.5 And Bearing < 337.5 Then
        dDirection = "North West"
    End If
   
    If Bearing > 337.5 And Bearing < 360 Then
        dDirection = "North"
    End If
0
 

Accepted Solution

by:
Reddz earned 0 total points
ID: 8113630
Thank Guy I have sussed it out with a little more looking around the net, here's what ive come up with...


Dim Pi As Double
Dim Bearing As Double

'calculate Pi
    Pi = Atn(1) * 4

'Calculate the Distance Travelled
    dDistance = Sqr(((x2 - x1) ^ 2 + (y2 - y1) ^ 2))

'Convert Distance from metres to miles
    dDistance = dDistance / 1609.3

'Round Distance to nearest Mile .1
    dDistance = Round(dDistance, 1)


'Calculate Direction Travelled in degrees

    dx = x2 - x1
    dy = y2 - y1

'Check which quadrant we are in and find the degrees
    If dx > 0 Then
        Bearing = 90 - (180 / Pi) * Atn(dy / dx)
    End If
   
    If dx < 0 Then
        Bearing = 270 - (180 / Pi) * Atn(dy / dx)
    End If
   
    If dx = 0 Then
        If dy > 0 Then Bearing = 0
            If dy < 0 Then Bearing = 180
                If dy = 0 Then
                    dDirection = "None"
                    Exit Function
                End If
    End If
   
‘From the degrees work out if we are travelling North, South etc

    If Bearing > 0 And Bearing < 22.5 Then
        dDirection = "North"
    End If
   
    If Bearing > 22.5 And Bearing < 67.5 Then
        dDirection = "North East"
    End If
   
    If Bearing > 67.5 And Bearing < 112.5 Then
        dDirection = "East"
    End If
   
    If Bearing > 112.5 And Bearing < 157.5 Then
        dDirection = "South East"
    End If

    If Bearing > 157.5 And Bearing < 202.5 Then
        dDirection = "South"
    End If
   
    If Bearing > 202.5 And Bearing < 247.5 Then
        dDirection = "South West"
    End If
   
    If Bearing > 247.5 And Bearing < 292.5 Then
        dDirection = "West"
    End If
   
    If Bearing > 292.5 And Bearing < 337.5 Then
        dDirection = "North West"
    End If
   
    If Bearing > 337.5 And Bearing < 360 Then
        dDirection = "North"
    End If
0
 

Expert Comment

by:CleanupPing
ID: 8900433
Reddz:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9074547
Reddz, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question