Reputation: 2268
I have two points PointA and Point B denoted by red points.
i can calculate the Perpendicaular points denoted by green points ( Top Perpendicular point , Bottom Perpendicular point) when the line is horizontal.
When line has a slope how would i calculate the perpendicular points.
Upvotes: 0
Views: 283
Reputation: 80187
Calculate direction vector of AB
dx = b.x-a.x
dy = b.y-a.y
Normalize it (make unit length)
len = sqrt(dx*dx+dy*dy)
udx = dx / len
udy = dy / len
Make perpendicular vector
px = -udy
py = udx
Calculate green points
g1.x = b.x + px*distance
g1.y = b.y + py*distance
g2.x = b.x - px*distance
g2.y = b.y - py*distance
Upvotes: 2