The point of intersection of two planes in 3D space can be calculated using spherical mathematics, as described here: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!438.entry Taking this route requires a significant number of calculation. If we wanted to calculate the points of intersection of a large number of planes this can cause performance issues. The following is a method that can be used to calculate a 2D approximation for the point of intersection.

**Theory**

A 2D plane, commonly known as a line, can be defined using a formula of the following format: Ax + By = C

Where x is in the same plane as the longitude coordinates and y is in the same plane as the latitude.

The components A, B, and C can be calculated using the following formula’s:

`A = y _{2}-y_{1}`

B = x_{1}-x_{2}

C = A*x_{1}+B*y_{1}

If we were to have two planes defined by the following equations:

`A _{1}x + B_{1}y = C_{1}`

A_{2}x + B_{2}y = C_{2}

We can then calculate the determinate of these two equations using the following formula:

determinate = A_{1}*B_{2}- A_{2}*B_{1}

If the determinate is 0, this would indicate that the planes are parallel to each other. If the determinate is 1 then this would indicate that the planes are perpendicular to each other.

Now that we have the determinate of these equations we can now solve for the x and y components of the point of intersection.

x = (B_{2}*C_{1}- B_{1}*C_{2})/determinate

y = (A_{1}*C_{2}- A_{2}*C_{1})/determinate

Application

The following code takes in four coordinates, where two coordinates represents the endpoints of a line segment. This code will return either a VELatLong representing the point of intersection or will return null which would indicate that the planes are parallel.

function SimplePlaneIntersection(latlong1,latlong2,latlong3,latlong4)

{

//Line segment 1 (p1, p2) var A1 = latlong2.Latitude - latlong1.Latitude;

var B1 = latlong1.Longitude - latlong2.Longitude;

var C1 = A1*latlong1.Longitude + B1*latlong1.Latitude;

//Line segment 2 (p3, p4) var A2 = latlong4.Latitude - latlong3.Latitude;

var B2 = latlong3.Longitude - latlong4.Longitude;

var C2 = A2*latlong3.Longitude + B2*latlong3.Latitude;

var determinate = A1*B2 - A2*B1;

var intersection;

if(determinate != 0)

{

var x = (B2*C1 - B1*C2)/determinate;

var y = (A1*C2 - A2*C1)/determinate;

intersection = new VELatLong(y,x);

}

else //lines are parrallel intersection = null;

return intersection;

}