Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
22 lines (17 loc) · 765 Bytes

File metadata and controls

22 lines (17 loc) · 765 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/python
from segment_intersect import segments_intersect
def right_horizontal_ray_intersect(p0, p1, p2):
"""An algorithm to determine whether a given right horizontal ray from p0 intersects a line segment p1p2"""
max_x = max(p1[0], p2[0])
if max_x < p0[0]:
return False
# When max(x1, x2) = x0, if intersecting, the intersection point must be po, then po must be on the line segment p1p2
elif max_x == p0[1]:
if p1[0] == p2[0] and min(p1[1], p2[1]) <= p0[1] and max(p1[1], p2[1]) >= p0[1]:
return True
else:
return equal(p0, p1) or equal(p0, p2)
else:
return segments_intersect(p1, p2, p0, (max_x, p0[1]))
def equal(p1, p2):
return p1[0] == p2[0] and p1[1] == p2[1]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.