How to construct a perpendicular line at an endpoint of a line segment?