You are the captain of a battleship. The engineering department's been cutting corners with designs this year, so the ship you're on takes the shape of a simple triangle.
You walk out onto the deck and enjoy the sea breeze... though not for long. An enemy has fired at you! — but will the shot hit?
You may write either a function or a full program for this challenge.
Your program will take in 11 integers, ten of which are paired:
The first three pairs of integers (x1, y1), (x2, y2), (x3, y3) will specify the vertices of your ship. The triangle formed will have nonzero area.
The next pair of integers (ex, ey) specifies the location of the enemy's cannon. The enemy cannon will never lie on, or within the boundary of your ship.*
The pair (ax, ay) after that specifies where the enemy aimed at. This will be distinct from (ex, ey).
The final positive integer R specifies the range of the enemy's shot
*You'd be a terrible captain if you didn't even notice that happening!
You must print/return a truthy value (e.g. true, 1) if the battleship will be hit, otherwise a falsy value (e.g. false, 0).
What is a hit?
The enemy shot is a straight line segment of length R from (ex, ey) in the direction of (ax, ay). If this line segment overlaps any part of the interior of your triangular battleship, then this counts as a hit. Otherwise it is not a hit.
Shots which graze along or only reach up to the boundary of the triangle do not count as a hit.
0 0 0 1 1 0 1 1 0 0 2
Hit: The enemy has shot right through the centre of your ship!
2 0 0 2 4 4 0 0 1 1 1
No hit: The enemy's range is too short, so you are safe.
0 0 1 2 3 0 -4 0 0 0 8
No hit: The enemy has grazed the side of your ship, so this does not count as a hit. Lucky!
0 0 -1 3 4 -1 -3 -4 3 4 5
No hit: The enemy shot just stops short of the ship, so you are safe. If the enemy's cannon had even slightly better range, then you would have been hit! Phew!
-2 -3 -3 6 7 -2 -6 2 1 -4 7
Hit: Even though the shot didn't penetrate to the other side, this is still a hit.
-3 2 2 -4 7 -3 -3 -4 -3 0 10
No hit: For the record, this is another close miss.
Additional test cases
0 0 6 0 6 8 -6 -8 6 8 20
No hit: This is another graze, but at an angle.
0 0 -2 -5 5 3 -3 4 0 0 6
Hit: The shot entered via a vertex of the ship.