Question: I have two points store in two variable, which forms a line. I want to find a point which is perpendicular to that line from one end point in that line.

Suppose I have two points P1(x1,y1) and P2(x2,y2) then i want to find a third point P3 such that line(P1-P2) is perpendicular to line(P2,P3) and intersect at P2.

Answer: 
First, the angle:

```
public static double angle (double x1, double y1, double x2, double y2) {
    double xdiff = x1 - x2;
    double ydiff = y1 - y2;
    //double tan = xdiff / ydiff;
    double atan = Math.atan2(ydiff, xdiff);
    return atan;
}

```

To get the perpendicular, you must add PI/2 to the angle of the line defined by your two points.

Once you have that angle, the formula is:

```
x = interceptPt.x + sin(perp_angle) * distance;
y = interceptPt.y + cos(perp_angle) * distance;

```
I got the answer at <http://jsfiddle.net/eLxcB/2/> 

```
// Start and end point
var startX = 120
var startY = 150
var endX = 180
var endY = 130
R.circle(startX,startY,2);

// Calculate how far above or below the control point should be
var centrePointX = startX
var centrePointY = startY;

// Calculate slopes and Y intersects
var lineSlope = (endY - startY) / (endX - startX);
var perpendicularSlope = -1 / lineSlope;
var yIntersect = centrePointY - (centrePointX * perpendicularSlope);

// Draw a line between the two original points
R.path('M '+startX+' '+startY+', L '+endX+' '+endY);

// Plot some test points to show the perpendicular line has been found
R.circle(100, (perpendicularSlope * 100) + yIntersect, 2);

```