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:You haven't said how your coordinate system is aligned, so
d_left
might becomed_right
and vice versa.You then get the desired points with:
Suppose
rotate(p,d)
is a operator to rotatep
vectord
angle.Then if the inclination of
p0p1
with positivex-axis
isx
. 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|