[Question]
  [
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](http://meta.codegolf.stackexchange.com/a/2194) 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
```
![test1](https://i.stack.imgur.com/4bR5Rm.jpg)
**Hit:** The enemy has shot right through the centre of your ship!
---
```
2 0 0 2 4 4
0 0
1 1
1
```
![test2](https://i.stack.imgur.com/yti7zm.jpg)
**No hit:** The enemy's range is too short, so you are safe.
---
```
0 0 1 2 3 0
-4 0
0 0
8
```
![test3](https://i.stack.imgur.com/CE3Kwm.jpg)
**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
```
![test4](https://i.stack.imgur.com/3DNYcm.jpg)
**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
```
![test5](https://i.stack.imgur.com/7Qu7bm.jpg)
**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
```
![test6](https://i.stack.imgur.com/TN8ofm.jpg)
**No hit:** For the record, this is another close miss.
---
## Additional test cases
```
0 0 6 0 6 8
-6 -8
6 8
20
```
![test7](https://i.stack.imgur.com/plqPbm.jpg)
**No hit:** This is another graze, but at an angle.
---
```
0 0 -2 -5 5 3
-3 4
0 0
6
```
![test8](https://i.stack.imgur.com/94V6Hm.jpg)
**Hit:** The shot entered via a vertex of the ship.
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins. [Standard loopholes](http://meta.codegolf.stackexchange.com/questions/1061/standard-loopholes-which-are-no-longer-funny) apply.
  
[Answer]
# 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>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<F<E or E<F<D)and(G<I<H or H<I<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 < r <= 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>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<F<E or E<F<D)and(G<I<H or H<I<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:**
```
>>> h(0,0,0,1,1,0,1,1,0,0,2)
True
>>> h(0,0,1,2,3,0,-4,0,0,0,8)
False
>>> h(0,0,-1,3,4,-1,-3,-4,3,4,5)
False
>>> h(-2,-3,-3,6,7,-2,-6,2,1,-4,7)
True
```
[Answer]
# Python 2.7, 235 bytes
```
from numpy import*
X=cross
h=lambda q,w,a,s,y,x,c,v,d,f,r:max([(X([a-q,s-w],[c+k*(d-c)-q,v+k*(f-v)-w])>0)==(X([y-a,x-s],[c+k*(d-c)-a,v+k*(f-v)-s])>0)==(X([q-y,w-x],[c+k*(d-c)-y,v+k*(f-v)-x])>0)for k in arange(0,r/hypot(d-c,f-v),1e-4)])
```
Computes the cross product `AB x AP` between the corners A,B and the point P. If all three have the same sign, then the point is inside the triangle. 
Ungolfed:
```
from numpy import *
def i(q,w,a,s,y,x,e,r): # helper-function, checks whether ER is inside the triangle QW-AS-YX
  t=cross([a-q,s-w],[e-q,r-w])>0
  g=cross([y-a,x-s],[e-a,r-s])>0
  b=cross([q-y,w-x],[e-y,r-x])>0
  return t==g==b
def h(q,w,a,s,y,x,c,v,d,f,r):
  R=arange(0,r/hypot(d-c,f-v),1e-3)
  return max([i(q,w,a,s,y,x,c+k*(d-c),v+k*(f-v)) for k in R])
```
Tests:
```
In : h(0,0,0,1,1,0,1,1,0,0,2)
Out: True
In : h(-3,2,2,-4,7,-3,-3,-4,-3,0,10)
Out: False
In : h(0,0,1,2,3,0,-4,0,0,0,8)
Out: True
     Grazes may count as hits...
In : h(1,2,0,0,3,0,-4,0,0,0,8)
Out: False
     ...or not, depending on the order of edges
```
[Answer]
# C, 247 bytes
Definitely not quite golfed yet.
```
#include<math.h>
int z(float*k){float s=1e-3,t=s,p=k[8]-k[6],q=k[9]-k[7],r=k[10]/hypot(p,q);int w=0;for(;t<1;t+=s){float x=k[6]-k[0]+p*r*t,y=k[7]-k[1]+q*r*t,b=k[2]*k[5]-k[3]*k[4],d=(x*k[5]-y*k[4])/b,e=(x*k[3]-y*k[2])/b;w|=d>0&e<0&d-e<1;}return w;}
```
Currently this uses an approach similar to DLosc's solution, i.e. iterates through all possible coordinates on the line segment to determine if it intersects with the triangle. (So it will fail if the range is over 1000) However, it uses the formula from <http://mathworld.wolfram.com/TriangleInterior.html> to determine if a point is inside the triangle. This avoids a bunch of trigonometric functions.
---
Example check, should print `1 0 0 0 1 0`.
```
#include <stdio.h>
int main() {
    {
        float arr[] = {0,0,0,1,1,0,1,1,0,0,2};
        printf("%d\n", z(arr));
    }
    {
        float arr[] = {2,0,0,2,4,4,0,0,1,1,1};
        printf("%d\n", z(arr));
    }
    {
        float arr[] = {0,0,1,2,3,0,-4,0,0,0,8};
        printf("%d\n", z(arr));
    }
    {
        float arr[] = {0,0,-1,3,4,-1,-3,-4,3,4,5};
        printf("%d\n", z(arr));
    }
    {
        float arr[] = {-2,-3,-3,6,7,-2,-6,2,1,-4,7};
        printf("%d\n", z(arr));
    }
    {
        float arr[] = {-3,2,2,-4,7,-3,-3,-4,-3,0,10};
        printf("%d\n", z(arr));
    }
}
```
[Answer]
# JavaScript (ES6) 320 ~~448 522 627~~
(Could still be golfed more?)
Steps:
1. Find the actual hit target (point at distance r on the line from enemy to aim)
2. Hit: if the segment from enemy to target intersect any of the sides of the ship, but not at the endpoints
3. Hit too: if the target is inside the ship - even if the shot entered at a vertex - test case 8
Ref:  
[Segment intersection](https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect)  
[Point inside triangle](https://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-triangle)  
[Point in a segment given a distance](https://math.stackexchange.com/questions/134112/find-a-point-on-a-line-segment-located-at-a-distance-d-from-one-endpoint) 
*Test in Firefox*
```
C=(i,j,k,l,m,n,g,h,a,b,r,
  d=a-g,e=b-h,f=r/Math.sqrt(d*d+e*e),
  p=g+f*d,q=h+f*e,
  z=j*(m-k)+i*(l-n)+k*n-l*m,
  s=(j*m-i*n+(n-j)*p+(i-m)*q)/z,
  t=(i*l-j*k+(j-l)*p+(k-i)*q)/z,
  S=(i,j,k,l,
     a=k-i,b=l-j,c=p-g,d=q-h,e=i-g,f=j-h,
     s=a*f-b*e,t=c*f-d*e,m=a*d-c*b)=>
     m&&((s/=m)>0&s<1&(t/=m)>0&t<1)
)=>s>0&t>0&s+t<1|S(i,j,k,l)|S(i,j,m,n)|S(m,n,k,l)
// Test
MyOutput.innerHTML = ['Test1', C(0,0, 0,1, 1,0, 1,1, 0,0, 2),
'<br>Test2', C(2,0, 0,2, 4,4, 0,0, 1,1, 1),
'<br>Test3', C(0,0, 1,2, 3,0, -4,0, 0,0, 8),
'<br>Test4', C(0,0, -1,3, 4,-1, -3,-4, 3,4, 5),
'<br>Test5', C(-2,-3, -3,6, 7,-2, -6,2, 1,-4, 7),
'<br>Test6', C(-3,2, 2,-4, 7,-3, -3,-4, -3,0 ,10),
'<br>Test7', C(0,0, 6,0, 6,8, -6,-8, 6,8, 20),
'<br>Test8', C(0,0,-2,-5, 5,3, -3,4, 0,0, 6)];
```
```
<div id="MyOutput"></div>
```
**Ungolfed**
```
function check(p0x, p0y, p1x, p1y, p2x, p2y, ex, ey, ax, xy, r)
{
  var sec = function(p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y)
  {
      var s10x = p1x - p0x, s10y = p1y - p0y, 
          s32x = p3x - p2x, s32y = p3y - p2y,
          s02x = p0x - p2x, s02y = p0y - p2y,
          s = s10x * s02y - s10y * s02x, t = s32x * s02y - s32y * s02x,
          d = s10x * s32y - s32x * s10y;
      return d && (s/=d) > 0 && s<1 && (t/=d) > 0 && t < 1 && [p0x + (t * s10x), p0y + (t * s10y)];
  }
  var pr = function(p0x, p0y, p1x, p1y, r)
  {
      var dx = (p1x-p0x), dy = (p1y-p0y), f = r/Math.sqrt(dx*dx+dy*dy);
      return [p0x + f*dx, p0y+f*dy];
  }
  var inside = function(p0x, p0y, p1x, p1y, p2x, p2y, px, py)
  {
      var area2 = (-p1y*p2x + p0y*(-p1x + p2x) + p0x*(p1y - p2y) + p1x*p2y),
          s = (p0y*p2x - p0x*p2y + (p2y - p0y)*px + (p0x - p2x)*py)/area2,
          t = (p0x*p1y - p0y*p1x + (p0y - p1y)*px + (p1x - p0x)*py)/area2;
      return s > 0 && t > 0 && s+t < 1;
  }
  var tx, xy;
  [tx, ty] = pr(ex, ey, ax, ay, r);
  return inside(p0x, p0y, p1x, p1y, p2x, p2y, tx,ty)
  || sec(p0x, p0y, p1x, p1y, ex, ey, tx, ty)
  || sec(p0x, p0y, p2x, p2y, ex, ey, tx, ty)
  || sec(p2x, p2y, p1x, p1y, ex, ey, tx, ty);
}  
```
[Answer]
# [Scala](http://www.scala-lang.org/), ~~349~~ 328 bytes
Saved 21 bytes thanks to the comment of @ceilingcat
---
Golfed version. [Try it online!](https://tio.run/##hZDdasJAEIXvfYq5kqTNqlGrJXEFIf5dlBJLb1JK2SRrEhsT2awtEvPsdpIYaEEozGGGb/ccdifzWMwuqbvjnoQnFiWQX6L9IRUSsvKos2cy7ORMsqRPpzPtozDl6cDBplZ6dGNu@nwLocIMW3NRHspHcdQWFaBCVITaoTaGrdL8iwkQdGOW3aH6VDe/wyjmipj2VDyMMX2m7EioRSRQzRJ80uBe3Hlpptg1iGmIIIuSBlho8YmreYTVYI5gi4A3YIEgRvDZgCUCl/gaI14NVpXFR8sVrCuLjxYEDnXOZ2uyaC8m8/O86la7vZys2@vJ6ryq@tIUhOqcDArTKS4tgHI9e1yrwkSQGTATgp3eXqSIkuBdNeA1iSRQyPEmwAGpjBMlVHoa1KVX9XvA6qsqdLvwfJSHozRAiiO/6UdDX4NBNZNh48Z6/BuwZXF2O4HolX9YT2RQ59Tk4f8Q0r@aUCMNxjiVZFS9S6/Dxjc/U7SK1uUH)
```
import scala.math.{atan2=>A,_};type Q=Double;def h(a:Q,b:Q,c:Q,d:Q,e:Q,f:Q,g:Q,h:Q,i:Q,j:Q,R:Q)={var r=R;var Z=1>1;while(r>0){val Q=A(j-h,i-g);val k=g+r*cos(Q);val l=h+r*sin(Q);val D=A(d-b,c-a);val E=A(f-b,e-a);val F=A(l-b,k-a);val G=A(b-d,a-c);val H=A(f-d,e-c);val I=A(l-d,k-c);Z=Z||D<F&F<E|E<F&F<D&&G<I&I<H|H<I&I<G;r-=1e-3};Z}
```
Ungolfed version. [Try it online!](https://tio.run/##hVLBTuMwFLznK@aEHDYpaWEBVRSpUrttD2hVVlxAaOUkbpKSppXj7gpBv7378hxCWiGt5IznzfiNncRlJHO532erzVoblFXVWUmTdt6kkUUPg1sMPfzeOetwqSKDO5kVeHMA87pRmGOA0Xob5oqUWC2QCtnH3EPIGDHGjIpxwZgwpowZ45LxntClyCof@CM1NFX3TfVI1ULmpWLlb5rlCkLjFoFb91Trcj7WUCzhI6UNaErclvtCboJvlH2KaF2KedvMyUxrs8yKQ3PEuTEFhvRyNMm2O2Z3YV117P5gN7fuy7E7YTckOfYgaYra7rRJjm3ygTtrkmOb3Lj0vWpW8fd3CDHCDR3l5ITgBmOXxXFbG7luRYWYUDGr6IzI1K6ctrWJ@7GPhj9A0AmCLgs7xkenYvW9WNG1EVInZR9DreXr0y@jsyJ5dvt4KDLT/PMNqSYvRCoCD3Z0ebQJjR6d8uwMP7dmszV9GL1VX/ZTQ8/DOXP/4qObxvVhwOetOk7wu9x/YZl/bnOs8v3/IX6vbqLn0sMVsUq55HN1bdjVly@zc3bO3tn/Aw)
```
import scala.math.{atan2 => A, _}
object Main {
  type Q = Double
  def h(a: Q, b: Q, c: Q, d: Q, e: Q, f: Q, g: Q, h: Q, i: Q, j: Q, R: Q) = {
    var r = R
    var Z = false
    while (r > 0) {
      val Q = A(j - h, i - g)
      val k = g + r * cos(Q)
      val l = h + r * sin(Q)
      val D = A(d - b, c - a)
      val E = A(f - b, e - a)
      val F = A(l - b, k - a)
      val G = A(b - d, a - c)
      val H = A(f - d, e - c)
      val I = A(l - d, k - c)
      Z =
        Z || ((D < F && F < E) || (E < F && F < D)) && ((G < I && I < H) || (H < I && I < G))
      r -= 0.001
    }
    Z
  }
  def main(args: Array[String]): Unit = {
    println(h(0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 2)) // Output: true
    println(h(0, 0, 1, 2, 3, 0, -4, 0, 0, 0, 8)) // Output: false
    println(h(0, 0, -1, 3, 4, -1, -3, -4, 3, 4, 5)) // Output: false
    println(h(-2, -3, -3, 6, 7, -2, -6, 2, 1, -4, 7)) // Output: true
  }
}
```
]