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: 
If you want to use Java I can recommend to use [JTS](https://github.com/locationtech/jts). Create a [LineSegment](https://locationtech.github.io/jts/javadoc/org/locationtech/jts/geom/LineSegment.html) and use the pointAlongOffset method. Given Points p1 and p2 the code would look like that:

```
// create LineSegment
LineSegment ls = new LineSegment(p1.getX(), p1.getY(), p2.getX(), p2.getY());
// perpendicular distance to line
double offsetDistance = 10;
// calculate Point right to start point
Coordinate startRight = ls.pointAlongOffset(0, offsetDistance);
// calculate Point left to start point
Coordinate startLeft = ls.pointAlongOffset(0, -offsetDistance);
// calculate Point right to end point
Coordinate endRight = ls.pointAlongOffset(1, offsetDistance);
// calculate Point left to end point
Coordinate endLeft = ls.pointAlongOffset(1, -offsetDistance);

```
You can store your points in `vec2d`, then use some mathematical equations to get the perpendicular point.

```
vec2d getPerpendicularPoint(vec2d A, vec2d B, float distance)
{
   vec2d M = (A + B) / 2;
   vec2d p = A - B;
   vec2d n = (-p.y, p.x);
   int norm_length = sqrt((n.x * n.x) + (n.y * n.y));
   n.x /= norm_length;
   n.y /= norm_length;
   return (M + (distance * n));
}

```