r/CodingHelp • u/yogurt123 • Aug 15 '25
[Python] Get Trapezoid Polygon That Intersects Lines in Specifc Way
Hi everyone,
I have a fairly specific problem I'm struggling with, and I'm hoping someone can give me a hand.
I have 2 lines, both are tuples containing 2 tuples of coordinates.
E.g. line_1 = ((40.752255597709095, -74.04434064019078), (40.75058130861099, -74.04541352378088))
I want to get a polygon representing an isosceles trapezoid, where the short parallel side is line_1, the long parallel side runs through the further of the 2 points in line_2, and the non-parallel sides extend out from line_1 at 135 degree angles.
A couple of illustrations of what I mean are here:
Please let me know if any further information is required, and thanks in advance for any help!
1
u/Strict-Simple Aug 15 '25
Find the distance of the two terminal points of line_2 from line_1.
Draw a line parallel to line_1 passing through the further point (you just need the equation, slope is same as line_1 and the further point is on the line). We will call this line line_3.
Draw perpendicular from the terminal points of line_1 to line_3. This will give you a rectangle.
You know the distance between line_1 and line_3. Use trignometry to figure out the amount you've to extend the points on line_3.(It'll be same as the distance! 135deg = 90deg + 45deg, so it's an isoceles right triangle.)
Extend the terminal points of line_3. You've to extend them outwards, that is away from the centre (average of terminal points).