# Approximate Point of Intersection of two planes

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 = y2-y1
B = x1-x2
C = A*x1+B*y1

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

A1x + B1y = C1
A2x + B2y = C2

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

`determinate = A1*B2 - A2*B1`

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 = (B2*C1 - B1*C2)/determinatey = (A1*C2 - A2*C1)/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;}```