Jem said:
Those 4 points you have define a slope for the line L1
m1 = (y2 - y1) / (x2 - x1);
That's not a good idea. The slope may become infinite.
given
P1 ( x1, y1 )
P2 ( x2, y2 )
D
wanted
P3
P4
such that the distance from P3 to P1 equals D and
the distance from P4 to P2 equals D and
the line connecting P3 and P1 is perpendicular to the line P2 - P1 and
the line connection P4 and P2 is perpendiculat to the line P2 - P1 and
P3 and P4 or on the same side of the line P2 - P1
(make a drawing, all of the above are obvious from the drawing, but its
hard to describe and understand it in text form only)
Calulate:
P2 - P1, that is
dx = x2 - x1;
dy = y2 - y1;
a vector perpendicular to P2-P1 has the parameters
perp_x = dy
perp_y = -dx;
thus you just need to normalize this
len = sqrt( perp_x * perp_x + perp_y * perp_y );
perp_x /= len;
perp_y /= len;
and multiply with the desired distance
perp_x *= D;
perp_y *= D;
The points P3 and P4 are then:
P3 = P1 + perp
that is: x3 = x1 + perp_x
y3 = y1 + perp_y
P4 = P4 + perp
that is x4 = x2 + perp_x
y4 = y2 + perp_y
the line P4-P3 is parallel to P2-P1 with the given distance D