This link might be helpful to you, as it details the use of the Haversine formula to calculate the distance.

Excerpt:

This script [in Javascript] calculates great-circle distances between the two points –
that is, the shortest distance over the earth’s surface – using the
‘Haversine’ formula.

```
function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
return d;
}
function deg2rad(deg) {
return deg * (Math.PI/180)
}
```

**(StartA <= EndB) and (EndA >= StartB)**

*Proof:*

Let ConditionA Mean that DateRange A Completely After DateRange B

```
_ |---- DateRange A ------|
|---Date Range B -----| _
```

(True if `StartA > EndB`

)

Let ConditionB Mean that DateRange A is Completely Before DateRange B

```
|---- DateRange A -----| _
_ |---Date Range B ----|
```

(True if `EndA < StartB`

)

Then Overlap exists if Neither A Nor B is true -

(If one range is neither completely after the other,

nor completely before the other,
then they must overlap.)

Now one of De Morgan's laws says that:

`Not (A Or B)`

<=> `Not A And Not B`

Which translates to: `(StartA <= EndB) and (EndA >= StartB)`

NOTE: This includes conditions where the edges overlap exactly. If you wish to exclude that,

change the `>=`

operators to `>`

, and `<=`

to `<`

NOTE2. Thanks to @Baodad, see this blog, the actual overlap is least of:

{ `endA-startA`

, `endA - startB`

, `endB-startA`

, `endB - startB`

}

`(StartA <= EndB) and (EndA >= StartB)`

`(StartA <= EndB) and (StartB <= EndA)`

NOTE3. Thanks to @tomosius, a shorter version reads:

`DateRangesOverlap = max(start1, start2) < min(end1, end2)`

This is actually a syntactical shortcut for what is a longer implementation, which includes extra checks to verify that the start dates are on or before the endDates. Deriving this from above:

If start and end dates can be out of order, i.e., if it is possible that `startA > endA`

or `startB > endB`

, then you also have to check that they are in order, so that means you have to add two additional validity rules:

`(StartA <= EndB) and (StartB <= EndA) and (StartA <= EndA) and (StartB <= EndB)`

or:

`(StartA <= EndB) and (StartA <= EndA) and (StartB <= EndA) and (StartB <= EndB)`

or,

`(StartA <= Min(EndA, EndB) and (StartB <= Min(EndA, EndB))`

or:

`(Max(StartA, StartB) <= Min(EndA, EndB)`

But to implement `Min()`

and `Max()`

, you have to code, (using C ternary for terseness),:

`(StartA > StartB? Start A: StartB) <= (EndA < EndB? EndA: EndB)`

## Best Solution

For the sake of clarity, I'm going to call coordinates in your base (

x,_{n}y), and coordinates in your target (_{n}u,_{n}v)._{n}Now, if we assume:

In this case you only need one set of points {(

x,_{1}y), (_{1}u,_{1}v)} to determine the location of (_{1}u,_{n}v):_{n}u=_{n}u/_{1}x*_{1}x_{n}v=_{n}v/_{1}y*_{1}y_{n}Note: we must have

x≠ 0,_{1}y≠ 0_{1}On the other hand, if the two coordinate systems have different origins (but they are still not rotated with respect to one another), we will need two sets of points {(

x,_{1}y), (_{1}u,_{1}v)} and {(_{1}x,_{2}y), (_{2}u,_{2}v)}:_{2}u= (_{n}u-_{2}u)/(_{1}x-_{2}x) * (_{1}x-_{n}x) +_{1}u_{1}v= (_{n}v-_{2}v)/(_{1}y-_{2}y) * (_{1}y-_{n}y) +_{1}v_{1}Note: we must have

x≠_{1}x,_{2}y≠_{1}y_{2}Now, if the two coordinate systems are rotated with respect to one another, you need (I believe) one more set of matching coordinates. But it doesn't sound like you need that (unless one of your maps has north pointing in a direction other than straight up), so I'm not going to work out the math now. :)