Thursday 24 December 2015

Integrating with society



Captain's log: Stardate 24121.5


If you have a light cycle that is accelerating at rate $A$ units per frame and also turning $C$ degrees per frame, and you need to work out an equation to describe the light trail (a spiral), so you can do collision detection, then you're in the same boat I've been in for the last few weeks.

If not then feel free to skip down to after the maths for some other updates and pictures.

First a few definitions:
  • $u$ - Initial speed in terms of units per frame.
  • $a$ - Rate of acceleration in units per frame per frame.
  • $c$ - Angle in radians the bike can turn each frame.
  • $\theta$ - Initial angle of bike in radians (0 is +ve Y).
  • $t$ - Time in frames.
The speed of the bike at time $t$ is defined with the standard equation: $s = at+u$

The direction the bike is pointing at time $t$ is defined by the vector:

$\bar{d} = \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}$

Therefore the velocity of the bike at time $t$ is defined by the vector:

$\bar{v} = (at + u) \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}$

As we all know, position at time $T$ is $\begin{pmatrix} x \\ y \end{pmatrix}(T) = \int_{0}^{T} \bar{v}dt$

\[\begin{pmatrix} x \\ y \end{pmatrix}(T) = {\displaystyle \int_0^T} {(at + u) \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt} = \underbrace{ {\displaystyle \int_0^T} {at \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt} }_{\displaystyle \text{1}} + \underbrace{ {\displaystyle \int_0^T} {u \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt}}_{\displaystyle \text{2}}\]

Lets tackle this in two parts. First 2) the simpler term:

${\displaystyle \int_0^T} {u \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt} = {\displaystyle \frac{u}{c}}\left[\begin{pmatrix} -cos(ct + \theta) \\ sin(ct + \theta) \end{pmatrix}\right]_0^T = {\displaystyle \frac{u}{c}}\Bigg(\begin{pmatrix} -cos(cT + \theta) \\ sin(cT + \theta) \end{pmatrix} - \begin{pmatrix} -cos(\theta) \\ sin(\theta) \end{pmatrix} \Bigg)$

Now 1) the more complicated term:

${\displaystyle \int_0^T} {at \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt} = a{\displaystyle \int_0^T} {t \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt}$

We have to do this by parts. Remember:

$\int udv = uv - \int vdu$

So we define:

  • $u = t$
  • $dv = \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt$
Which gives us:

  • $du = dt$
  • $v = {\displaystyle \int} {\begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt} = {\displaystyle \frac{1}{c}} \begin{pmatrix} -cos(ct + \theta) \\ sin(ct + \theta) \end{pmatrix}$

$\begin{split}{\displaystyle \therefore}\quad a{\displaystyle \int_0^T} {t \begin{pmatrix} sin(ct + \theta) \\ cos(ct + \theta) \end{pmatrix}dt} & = a\left[{\displaystyle \frac{t}{c}} \begin{pmatrix} -cos(ct + \theta) \\ sin(ct + \theta) \end{pmatrix}\right]_0^T - {\displaystyle \frac{a}{c}\int_0^T} { \begin{pmatrix} -cos(ct + \theta) \\ sin(ct + \theta) \end{pmatrix}dt} \\ & = {\displaystyle \frac{aT}{C}}\begin{pmatrix} -cos(cT + \theta) \\ sin(cT + \theta) \end{pmatrix} - {\displaystyle \frac{a}{c^2}} \left[\begin{pmatrix} -sin(ct + \theta) \\ -cos(ct + \theta) \end{pmatrix} \right]_0^T \\ & = {\displaystyle \frac{aT}{C}}\begin{pmatrix} -cos(cT + \theta) \\ sin(cT + \theta) \end{pmatrix} - {\displaystyle \frac{a}{c^2}}\Bigg(\begin{pmatrix} -sin(cT + \theta) \\ -cos(cT + \theta) \end{pmatrix} - \begin{pmatrix} -sin(\theta) \\ -cos(\theta) \end{pmatrix}\Bigg) \\ & = {\displaystyle \frac{aT}{C}}\begin{pmatrix} -cos(cT + \theta) \\ sin(cT + \theta) \end{pmatrix} + {\displaystyle \frac{a}{c^2}}\Bigg(\begin{pmatrix} sin(cT + \theta) \\ cos(cT + \theta) \end{pmatrix} - \begin{pmatrix} sin(\theta) \\ cos(\theta) \end{pmatrix}\Bigg)\end{split}$

So finally we can add terms 1) and 2) together to get the position of the bike at time $T$

$\begin{split}\begin{pmatrix} x \\ y \end{pmatrix}(T) = & {\displaystyle \frac{u}{c}}\Bigg(\begin{pmatrix} -cos(cT + \theta) \\ sin(cT + \theta) \end{pmatrix} - \begin{pmatrix} -cos(\theta) \\ sin(\theta) \end{pmatrix} \Bigg) + \\ & {\displaystyle \frac{a}{c^2}}\Bigg(\begin{pmatrix} sin(cT + \theta) \\ cos(cT + \theta) \end{pmatrix} - \begin{pmatrix} sin(\theta) \\ cos(\theta) \end{pmatrix}\Bigg) + \\ & {\displaystyle \frac{aT}{C}}\begin{pmatrix} -cos(cT + \theta) \\ sin(cT + \theta) \end{pmatrix} \end{split}$


So there you go, you can sleep easy tonight knowing the maths has been done, and with that working I can collide with a spiraling light trail.


In other news, it's christmas! Amy spent the day making mince pies, and I spent it doing maths. We're about to have a big dinner with the family we live with.

Other than that we're heading to Peru on the 27th, and when we return on the 2nd we'll get a specific purpose visa, which we can use to apply for our proper visa. Our previous application was just to see if they objected to us, which they have replied saying they don't so all should go well with the actual application, giving us the right to stay in the country for a year as volunteers that definitely do not work with children.

We finished work last Sunday and are off until the 18th January, so that's cool. Lots of time to code more stuff! We finished work with a Christmas party for the people of one of the communities we work in. Tonnes of people turned up. We made Api (hot purple corn based drink) and Pastel (deep fat fried dough). Here are some pictures.

Api and Pastel

Here is little John riding a horse. He's the son of
the organisation's chef.

Here's me holding a tiny bunny rabbit that we found in a shop.

Here's a dog dressed as santa that we saw on the way to the shop.

Our clowns

Some of the people at the party.
In this you can see the typical attire
and dual plaits of the local women.



1 comment: