Quiz: Geometric intersection in Python

In this quiz, you want to write intersection functions. Assume that lines consist of only two vertices to make things simpler (hopefully).

Total points are 120, so there are 20 bonus points that are not tied to any specific problems. Please create only one script file called FirstLastname_quiz2.py and include all your functions only there. For derivation, please take a picture of your work and submit it in FirstLastname_work.jpeg. Please submit only these two files. There will be penalties for violating these submission requirements. I will deduct $-2$ for each violation including function and argument names after prorating your score.

To earn 100% of your score, please submit it in 2 hours. After that, your final score will be linearly reduced by 5% in hourly increments. For example, if you submit it 2 hours and 10 minutes late, your full potential will be $120\times(1-0.05\times 3)=102$. In other words, if you do not submit it in 20 hours after the regular 2 hours of the proctored quiz, you will get a zero!

Only the math module is allowed. If you use any other modules, you will get 50% of your final prorated score.


1   Point intersection

20 points

Write a function intersect_point(line, pnt) that returns True if pnt is on line or False otherwise. line is $((x_0, y_0), (x_1, y_1))$ and pnt is $(s, t)$.

2   Perpendicularity

30 points

Derive an equation for the line that is perpendicular to $y=ax+b$ and passes through $(s, t)$. Submit your full work in JPEG.

3   Snapping

30 points

Write a function snap_point(line, pnt) that snaps pnt to line. If pnt cannot be projected onto line perpendicularly, return the closest node of line.

4   Line intersection

40 points

Write a function intersect_line(line1, line2) that returns the intersection point of two lines if any or None otherwise. If line1 overlaps with line2 linearly (i.e., they share a line segment, not a point), return the start and end nodes of the shared line segment in $((x_s, y_s), (x_e, y_e))$.