I have a linesegment ‘v’ and I want to find a point that is at an ‘r’ distance to v and perpendicular to v(from the starting point of the line segment).Its in 2d so there will be two points on either side of the line.This can be one by solving 2 equations,one by testing dot product and other equation through distanace.Is there an efficient implementation for it???Thanks in advance.

You can do this using vector operations. Let vector A be the starting point of linesegment ‘v’, and vector B be the endpoint. Let vector V = B - A. Normalize V to get U (a unit vector parallel to V). Suppose U has components xu and yu, i.e. U = {xu, yu}. Let Q = {yu, -xu) and R = {-yu, xu}. Q and R are unit vectors perpendicular to V. Let’s say the distance you want those two points to be from the line segment is s. Scaling Q and R by s yields Q’ = {syu, -sxu}, and R’ = {-syu, sxu}. The two points you are looking for are P1 = A + Q’ and P2 = A + R’. This is very straightforward if you already have vector subroutines defined. You would need 2D vector addition, subtraction, normalization routines (very easy to write).