1 from __future__
import division
5 class tracker (object):
7 __slots__
= 'xtol', 'vtol', 'a', 'v', 'x', 'y'
9 def __init__ (self
, a
= 0, xtol
= 0, vtol
= 0):
19 return '(%f -> %f)' % (self
.y
, self
.x
)
23 def __add__ (self
, other
):
24 return self
.y
+ float (other
)
26 def __sub__ (self
, other
):
27 return self
.y
- float (other
)
29 def __mul__ (self
, other
):
30 return self
.y
* float (other
)
32 def __floordiv__ (self
, other
):
33 return self
.y
// float (other
)
35 def __mod__ (self
, other
):
36 return self
.y
% float (other
)
38 def __divmod__ (self
, other
):
39 return divmod (self
.y
, float (other
))
41 def __pow__ (self
, other
):
42 return self
.y
** float (other
)
44 def __truediv__ (self
, other
):
45 return self
.y
/ float (other
)
49 def __radd__ (self
, other
):
50 return float (other
) + self
.y
52 def __rsub__ (self
, other
):
53 return float (other
) - self
.y
55 def __rmul__ (self
, other
):
56 return float (other
) * self
.y
58 def __rfloordiv__ (self
, other
):
59 return float (other
) // self
.y
61 def __rmod__ (self
, other
):
62 return float (other
) % self
.y
64 def __rdivmod__ (self
, other
):
65 return divmod (float (other
), self
.y
)
67 def __rpow__ (self
, other
):
68 return float (other
) ** self
.y
70 def __rtruediv__ (self
, other
):
71 return float (other
) / self
.y
73 __rdiv__
= __rtruediv__
75 def __iadd__ (self
, other
):
76 self
.y
+= float (other
)
78 def __isub__ (self
, other
):
79 self
.y
-= float (other
)
81 def __imul__ (self
, other
):
82 self
.y
*= float (other
)
84 def __ifloordiv__ (self
, other
):
85 self
.y
//= float (other
)
87 def __imod__ (self
, other
):
88 self
.y
%= float (other
)
90 def __ipow__ (self
, other
):
91 self
.y
**= float (other
)
93 def __itruediv__ (self
, other
):
94 self
.y
/= float (other
)
96 __idiv__
= __itruediv__
107 def __float__ (self
):
110 def update (self
, dt
):
120 from math
import sqrt
121 disc
= sqrt (v
* v
/ 2 + a
* (x
- y
))
127 except ZeroDivisionError:
132 self
.y
+= (v
+ dv
/ 2) * dt
136 self
.y
+= (v
+ dv
/ 2) * t
140 self
.y
+= (self
.v
+ dv
/ 2) * dt
144 self
.y
+= (v
+ dv
/ 2) * dt
147 if abs (self
.x
- self
.y
) < self
.xtol
and abs (self
.v
) < self
.vtol
: