I have P1=(x1,y1) and P2=(x2,y2) points and they are specified. Also I have h distance from P1 point that is also known. And I want to find P3 and P4 that located on perpendicular line and h is distance to them. How can i found those
P4=?
P3=?
Basically, you first find the vector from P1 to P2. Then to get a perpendicular vector you take the negative inverse of the vector (switching the axes around and making one negative, which one you make negative determines the direction). After that, you find the normal of the perpendicular vector by dividing the vector by it’s magnitude (length). Finally, you multiply by h and -h to get the vectors of the right length in each direction.
var first = points[0];
var second = points[1];
var newVec = first-second;
var newVector = Vector3.Cross (newVec, Vector3.forward);
newVector.Normalize();
var newPoint = width*newVector+first;
var newPoint2 = -width*newVector+first;
Debug.DrawLine (newPoint,newPoint2);
I may have a redundant normalization but it is working great, and the idea is first get the vector from 1 to 2. Then make a new vector (y, -x) on this angle, switch to (-y, x) for P3.