Problem A
Horizontal Ray–Segment Intersection
Languages
da
en
You are given a horizontal ray and a line segment in the 2D plane. The ray starts at point $ q = (q_x, q_y)$ and extends infinitely in the positive $x$-direction (“East”). That is, the ray consists of all points $(x, y)$ such that $x \geq q_x$ and $y = q_y$. The line segment has endpoints $a=(a_x, a_y)$ and $b=(b_x, b_y)$, ordered such that $b_y\geq a_y$. The line segment is closed at $a$ and open at $b$; that is, point $a$ is considered part of the line segment, while point $b$ is not.
The task is to determine whether the ray intersects the line segment.
In the $1$st and $4$th of the examples below, the answer is “yes.”
Input
The input consists of:
-
One line with the coordinates $q_x$ and $q_y$ of $q$.
-
One line with the coordinates $a_x$ and $a_y$ of $a$.
-
One line with the coordinates $b_x$ and $b_y$ of $b$, with $b_y\geq a_y$.
Each coordinate is given as a floating point number $z$ with $0\leq z \leq 90$. The Euclidean distance between the query point and the line segment is at least $10^{-6}$. The Euclidean distance between $a$ and $b$ is at least $10^{-6}$.
Output
Write “yes” if the ray intersects the line segment. Else write “no”.
| Sample Input 1 | Sample Output 1 |
|---|---|
1.0 1.0 0.5 0.0 2.0 2.0 |
yes |
| Sample Input 2 | Sample Output 2 |
|---|---|
1.0 1.0 2.0 0.0 0.0 1.5 |
no |
| Sample Input 3 | Sample Output 3 |
|---|---|
1.0 1.0 2.0 2.0 3.0 2.0 |
no |
| Sample Input 4 | Sample Output 4 |
|---|---|
1.0 1.0 2.0 1.0 2.0 2.0 |
yes |
| Sample Input 5 | Sample Output 5 |
|---|---|
1.0 2.0 2.0 1.0 2.0 2.0 |
no |
