-
Notifications
You must be signed in to change notification settings - Fork 0
/
math-notes.txt
117 lines (102 loc) · 4.16 KB
/
math-notes.txt
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
2013-08-18 20:03:46
now, given our position and leader's position and movement,
determine how long it will take for him to move to the edge of the circle
surrounding us with radius FOLLOW_DIST.
set a timer for that time.
dist(x,y) = (x² + y²) ^ 0.5
pos(x,y,dx,dy,t) = (x + dx*t), (y + dy*t)
dist(t) = ((x+dx*t)² + (y+dy*t)²)^0.5
solve dist(t) for dist = FOLLOW_DIST, assuming our position is origo:
FOLLOW_DIST² = (x+dx*t)² + (y+dy*t)²
FOLLOW_DIST² = x²+2*x*dx*t+dx²*t² + y²+2*y*dy*t+dy²*t²
FOLLOW_DIST² - (x²+y²) = 2*x*dx*t+dx²*t² + 2*y*dy*t+dy²*t²
FOLLOW_DIST² - (x²+y²))/t = 2*x*dx+dx²*t + 2*y*dy+dy²*t
FOLLOW_DIST² - (x²+y²))/t - (2*x*dx + 2*y*dy) = dx²*t + dy²*t
FOLLOW_DIST² - (x²+y²))/t - (2*x*dx + 2*y*dy) = t*(dx² + dy²)
blargh. this isn't working.
general 2nd grade equation: ax² + bx + c = 0
general solution: x = (-b +- (b² - 4ac)^0.5) / 2a
general form of dist(t): (dx²+dy²)*t² + (2*(x*dx+y*dy))*t + (x²+y²-FOLLOW_DIST²) = 0
11:50 2013-08-24
we have two linearly moving points.
find the point where we cross a radius about them, or if that radius is never crossed,
find the nearest point.
set the timer to the time t we arrive at that point, if current time is 0.
myPos.x(t) = myPos.x + math.cos(o) * t * RUN_SPEED;
myPos.y(t) = myPos.y + math.sin(o) * t * RUN_SPEED;
mo.x(t) = mo.x + mo.dx * t;
mo.y(t) = mo.y + mo.dy * t;
dist(t) = distance2(myPos(t), mo(t));
Find minimum of dist(t).
To do this, solve dist'(t) = 0
dist(t) = ((myX(t) - moX(t))² + (myY(t) - moY(t))²)^0.5
dist(t) = ((myX + myDX*t - moX - moDX*t)² ...
dist(t) = ((myX - moX + t*(myDX - moDX))² ...
diX = myX - moX
diDX = myDX - moDX
dist(t) = (diX² + 2*t*diDX + diDX²*t² + diY² + 2*t*diDY + diDY²*t²)^0.5
Chain rule: if f(x) = h(g(x)), then f'(x) = h'(g(x)) * g'(x)
dist(t) = h(diX²...), where h(g) = g^0.5
g(t) = diX² + diY² + 2*(diDX+diDY)*t + (diDX+diDY)*t²
g'(t) = 0 + 2*(diDX+diDY) + 2*(diDX+diDY)*t
h'(g) = 0.5*(g^-0.5)
(g^-0.5) = 1 / (g^0.5)
h'(g) = 0.5 / (g^0.5)
Solving for 0:
0 = 0.5 / (g^0.5)
0 = 0.5? That can't be right...
Quite. h'(g) != f'(x). Therefore:
dist'(t) = 0.5 / (g(t)^0.5) * g'(t)
Solving again for 0:
0 = 0.5*g'(t) = diDX+diDY + (diDX+diDY)*t? Not right again, since diX and diY are lost...
dist(t) = ((diX + t*diDX)² ...
(a+b)² = a² + 2ab + b²
dist(t) = (diX² + 2*t*diX*diDX + diDX²*t² + diY² + 2*t*diY*diDY + diDY²*t²) ^ 0.5
g(t) = diX² + diY² + 2*t*(diX*diDX+diY*diDY) + (diDX²+diDY²)*t²
g'(t) = 2*(diX*diDX+diY*diDY) + 2*(diDX²+diDY²)*t
Third try's the charm:
0 = diX*diDX+diY*diDY + (diDX²+diDY²)*t Seems reasonable.
t = -(diX*diDX+diY*diDY) / (diDX²+diDY²)
14:33 2013-08-24
OK, mathematically correct, but still not useful; since we're already so close to the closest point we can get,
we will hit it very soon, thus causing a quick loop of corrections, which is not so nice.
Better would be to find out when we'll have deviated x yards from the target's course.
so, a point's minimum distance from a straight line:
line: ax+by+c=0
abs(am+bn+c)/sqrt(a²+b²)
we wanna solve for t, m(t) & n(t), dist = 5
5 = abs(a*m(t)+b*n(t)+c)/sqrt(a²+b²)
5*sqrt(a²+b²) = abs(a*m(t)+b*n(t)+c)
m(t) = x+dx*t
n(t) = y+dy*t
5*sqrt(a²+b²) = abs(a*x+a*dx*t+b*y+b*dy*t+c)
5*sqrt(a²+b²) = abs(a*x+b*y+c + t*(a*dx+b*dy))
5*sqrt(a²+b²) = +/- (a*x+b*y+c + t*(a*dx+b*dy))
1:
5*sqrt(a²+b²) = a*x+b*y+c + t*(a*dx+b*dy)
5*sqrt(a²+b²) - a*x+b*y+c = t*(a*dx+b*dy)
(5*sqrt(a²+b²) - a*x+b*y+c) / (a*dx+b*dy) = t
2:
5*sqrt(a²+b²) = -a*x+b*y+c - t*(a*dx+b*dy)
5*sqrt(a²+b²) + a*x+b*y+c = -t*(a*dx+b*dy)
(5*sqrt(a²+b²) + a*x+b*y+c) / -(a*dx+b*dy) = t
One t is positive, the other is negative. Only the positive one is valid.
As for the line equation:
y = mx+c
0 = mx+c-y
0 = ax+by+c, where b=-1
c = ax¹+by¹
c = ax²+by²
ax¹+by¹=ax²+by²
a(x¹-x²)=b(y²-y¹)
a=b(y²-y¹)/(x¹-x²)
c=bx¹((y²-y¹)/(x¹-x²))+by¹
c = x¹((y²-y¹)/(x¹-x²))+y¹ if(a != 0)
b = 0 if(y¹ == y²)
a = 0 if(x¹ == x²)
m = (x¹-x²)/(y¹-y²)
16:05 2013-11-10
Line equation on form ax + by + c = 0 from two points x¹,y¹ x²,y²:
First check if slope form is possible: x¹ != x²
If so, then get slope form and convert it.
If not, it's a vertical line, which allows us a shortcut.