I’m trying to convert a line into a very thin polygon but don’t know how to take the slope / angle of the line into account.
Say I have the line segment of x1,y1 and x2,y2. If those values were 0,0 and 100,0 (completely flat, straight line) I could create a very thin polygon by simply adding 0.00001 to both y points to create 2 new points.
How can I take the slope of the line into account to achieve the same thing with a line going in any direction?
Thanks.
Find a perpendicular line and then get the two points in this direction and you’ll always have the same thickness.
The two perpendiculars of vector (x, y) are (-y, x) and (y, -x) so:
since your vector is (x2 – x1, y2 – y1) a vector perpendicular to this could be either:
(y1 – y2, x2 – x1) or (y2 – y1, x1 – x2)
Simply chose one and then add it to each point to get their corresponding points. Assuming you chose the first one, your two extra points will be:
Where d is your line thickness.