-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes
More file actions
147 lines (127 loc) · 4.01 KB
/
notes
File metadata and controls
147 lines (127 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
0 <= t <= 1
d(t) = p(A,t) - p(B,t) < radius
p(s,t) = (s.px + (t * s.vx), s.py + (t * s.vy))
sqrt(
((s1.px + (t * s1.vx)) - (s2.px + (t * s2.vx)))^2 +
((s1.py + (t * s1.vy)) - (s2.py + (t * s2.vy)))^2
) < radius
d(t) = sqrt(((s1.px + (t * s1.vx)) - (s2.px + (t * s2.vx)))^2 + ((s1.py + (t * s1.vy)) - (s2.py + (t * s2.vy)))^2)
A = s1.px
B = s1.vx
C = s2.px
D = s2.vx
E = s1.py
F = s1.vy
G = s2.py
H = s2.vy
d(t) = sqrt(((A + (t * B )) - (C + (t * D )))^2 + ((E + (t * F )) - (G + (t * H )))^2)
d(t) = sqrt(
((A + (t * B )) - (C + (t * D )))^2 +
((E + (t * F )) - (G + (t * H )))^2
)
d(t) = sqrt(
((A + tB) - (C + tD))^2 +
((E + tF) - (G + tH))^2
)
d(t) = sqrt(
((A + tB) - (C + tD))^2 +
((E + tF) - (G + tH))^2
)
d(t) = sqrt(
(A + tB - C - tD)^2 +
(E + tF - G - tH)^2
)
d(t) = sqrt(
(A + t(B - D) - C)^2 +
(E + t(F - H) - G)^2
)
d(t) = sqrt(
(t(B - D) + (A - C))^2 +
(t(F - H) + (E - G))^2
)
P = B - D
Q = A - C
R = F - H
S - E - G
d(t) = sqrt(
(tP + Q)^2 +
(tR + S)^2
)
d(t) = sqrt(
(tP + Q)^2 +
(tR + S)^2
)
d(t) = sqrt(
t^2 * P^2 + 2QtP + Q^2 +
t^2 * R^2 + 2StR + S^2
)
d(t) = sqrt(
t^2 * (P^2 + R^2) + t(2QP + 2SR) + Q^2 + S^2
)
d(t)^2 = t^2 * (P^2 + R^2) + t(2QP + 2SR) + Q^2 + S^2
a = P^2 + R^2
b = 2QP + 2SR
c = Q^2 + S^2
t_closest = -b/(2a)
t_closest = -(2QP + 2SR)/(2(P^2 + R^2))
P = B - D
Q = A - C
R = F - H
S = E - G
P = B - D
Q = A - C
R = F - H
S = E - G
P = s1.vx - s2.vx
Q = s1.px - s2.px
R = s1.vy - s2.vy
S = s1.py - s2.py
P = s1.vx - s2.vx
Q = s1.px - s2.px
R = s1.vy - s2.vy
S = s1.py - s2.py
t_closest = -(2(A - C)(B - D) + 2(E - G)(F - H))/(2((B - D)^2 + (F - H)^2))
t_closest = -(2(A - C)(B - D) + 2(E - G)(F - H))/(2((B - D)^2 + (F - H)^2))
A = s1.px
B = s1.vx
C = s2.px
D = s2.vx
E = s1.py
F = s1.vy
G = s2.py
H = s2.vy
t_closest = -(2(s1.px - s2.px)(s1.vx - s2.vx) + 2(s1.py - s2.py)(s1.vy - s2.vy))/(2((s1.vx - s2.vx)^2 + (s1.vy - s2.vy)^2))
di = distance of interest, collision distance, sum of 2 ships' radii
0 = t^2 * (P^2 + R^2) + t(2QP + 2SR) + Q^2 + S^2 - di^2
a = (P^2 + R^2)
b = (2QP + 2SR)
c = (Q^2 + S^2 - di^2)
a = ((s1.vx - s2.vx)^2 + (s1.vy - s2.vy)^2)
b = (2(s1.px - s2.px)(s1.vx - s2.vx) + 2(s1.py - s2.py)(s1.vy - s2.vy))
c = ((s1.px - s2.px)^2 + (s1.py - s2.py)^2 - di^2)
discriminant = b^2 - 4ac
discriminant = (2(s1.px - s2.px)(s1.vx - s2.vx) + 2(s1.py - s2.py)(s1.vy - s2.vy))^2 - 4((s1.vx - s2.vx)^2 + (s1.vy - s2.vy)^2)((s1.px - s2.px)^2 + (s1.py - s2.py)^2 - di^2)
/* Ships: A, B
* P(x, t) = position of x at time t
* D(x, y) = distance from x to y
* mag(v) = magnitude of vector v
* P(ship, t) = P(ship, 0) + t * ship.velocity
* P(ship, 0) = <ship.x, ship.y>
* D(x, y) = mag( P(x, t) - P(y, t) )
* constraint: D(A, B) > (a.radius + b.radius) for all t
* tcollision = D(A, B) < (a.radius + b.radius)
*
*
* t = mag((<A.x, A.y> + t * A.velocity) - (<B.x, B.y> + t * B.velocity)) < (A.radius + B.radius)
* t = mag(<A.x + t * A.vx, A.y + t * A.vy> - <B.x + t * B.vx, B.y + t * B.vy>) < (A.radius + B.radius)
* t = mag(<A.x + t * A.vx - B.x - t * B.vx, A.y + t * A.vy - B.y - t * B.vy>) < (A.radius + B.radius)
* t = mag(<A.x - B.x + t * (A.vx - B.vx), A.y - B.y + t * (A.vy - B.vy)>) < (A.radius + B.radius)
* t = sqrt((A.x - B.x + t * (A.vx - B.vx))^2 + (A.y - B.y + t * (A.vy - B.vy))^2) < (A.radius + B.radius)
*
* https://www.wolframalpha.com/input/?i=sqrt((A+-+B+%2B+t+*+(N+-+M))%5E2+%2B+(C+-+D+%2B+t+*+(O+-+P))%5E2)+solve+for+t
* t = (-sqrt(-(A O - A P - B O + B P + C M - C N - D M + D N)^2) + A M - A N - B M + B N - C O + C P + D O - D P)/(M^2 - 2 M N + N^2 + O^2 - 2 O P + P^2) and M^2 - 2 M N + N^2 + O^2 - 2 O P + P^2!=0
*
* t = (-sqrt(-(A.x A.vy - A.x B.vy - B.x A.vy + B.x B.vy + A.y A.vx - A.y B.vx - B.y A.vx + B.y B.vx)^2) + A.x A.vx - A.x B.vx - B.x A.vx + B.x B.vx - A.y A.vy + A.y B.vy + B.y A.vy - B.y B.vy)/(A.vx^2 - 2 A.vx B.vx + B.vx^2 + A.vy^2 - 2 A.vy B.vy + B.vy^2) and A.vx^2 - 2 A.vx B.vx + B.vx^2 + A.vy^2 - 2 A.vy B.vy + B.vy^2!=0
*
* t = [0..1]
*/