Triangular battleships (A computational geometry problem) 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?

Input

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!

Output

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.

Examples

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.

Scoring

This is code-golf, so the shortest code in bytes wins. Standard loopholes apply.
Python 3, 252 bytes

This is certainly the most variables I've ever used in code golf. :^P

from math import*;A=atan2
def h(a,b,c,d,e,f,g,h,i,j,R):
 r=R;_=0
 while r&gt;0:Q=A(j-h,i-g);k,l=g+r*cos(Q),h+r*sin(Q);D=A(d-b,c-a);E=A(f-b,e-a);F=A(l-b,k-a);G=A(b-d,a-c);H=A(f-d,e-c);I=A(l-d,k-c);_=_ or(D&lt;F&lt;E or E&lt;F&lt;D)and(G&lt;I&lt;H or H&lt;I&lt;G);r-=.001
 return _


Slightly ungolfed, with comments:

from math import*
# Parameters:
#  (a,b) (c,d) (e,f) - vertices of the triangle
#  (g,h) - location of cannon
#  (i,j) - aim of cannon
#  R - range of cannon
# Variables within function:
#  _ - was this shot a hit?
#  r - distance 0 &lt; r &lt;= R that we're testing
#  Q - angle between cannon source and destination
#  (k,l) - point that we're testing
#  D,E,F - angles between point 1 and 2,3,test
#  G,H,I - angles between point 2 and 1,3,test
def h(a,b,c,d,e,f,g,h,i,j,R):
    r=R;_=0
    while r&gt;0:
        Q=atan2(j-h,i-g)
        k,l=g+r*cos(Q),h+r*sin(Q)
        D=atan2(d-b,c-a)
        E=atan2(f-b,e-a)
        F=atan2(l-b,k-a)
        G=atan2(b-d,a-c)
        H=atan2(f-d,e-c)
        I=atan2(l-d,k-c)
        _=_ or(D&lt;F&lt;E or E&lt;F&lt;D)and(G&lt;I&lt;H or H&lt;I&lt;G)
        r-=.001
    return _


How it works:


Calculate the endpoint of the shot.
Test lots of points along the line from the endpoint to the cannon's location:

Calculate angles from vertex 1 to other two vertices and to test point;
Calculate angles from vertex 2 to other two vertices and to test point;
If the test point angle is between the other two angles, in both cases, then the test point is within the triangle and the ship has been hit.



Sample runs:

&gt;&gt;&gt; h(0,0,0,1,1,0,1,1,0,0,2)
True
&gt;&gt;&gt; h(0,0,1,2,3,0,-4,0,0,0,8)
False
&gt;&gt;&gt; h(0,0,-1,3,4,-1,-3,-4,3,4,5)
False
&gt;&gt;&gt; h(-2,-3,-3,6,7,-2,-6,2,1,-4,7)
True