How to get point A, B , C, and D?
if AB and CD are perpendicular to p0p1.
Assume p0A, p0B, p1C, and p1D have normalized length
How to get point A, B , C, and D?
if AB and CD are perpendicular to p0p1.
Assume p0A, p0B, p1C, and p1D have normalized length
The direction of the line is given by d = normalize(p1 - p0)
. To calculate a perpendicular vector we can use the cross product with (0, 0, 1)
. Which results in:
d_left = (-d.y, d.x)
d_right = (d.y, -d.x)
You haven't said how your coordinate system is aligned, so d_left
might become d_right
and vice versa.
You then get the desired points with:
A = p0 + d_left
B = p0 + d_right
C = p1 + d_left
D = p1 + d_right
Suppose rotate(p,d)
is a operator to rotate p
vector d
angle.
Then if the inclination of p0p1
with positive x-axis
is x
. Then,
A = p0 + rotate(p1-p0,pi/2)/|p1-p0|
B = p0 + rotate(p1-p0,-pi/2)/|p1-p0|
C = p1 + rotate(p1-p0,pi/2)/|p1-p0|
D = p1 + rotate(p1-p0,-pi/2)/|p1-p0|