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.



Friday 11 December 2015

Everything hurts

Captain's log: Stardate 11121.5


It's been a while, because I wanted to wait for a few of the bigger things to occur before posting an update. Also Santi wasn't willing to pay me $10 for a speedy update.

Firstly here's a couple of pictures.

The view across the valley from Alta Buena Vista.

The rubble pile that we climb up and down to get to the centre.
The lady in front of me is Daniella one of the two Bolivian circus directors.

Me learning to club pass with Adaly, the other circus director.
Unfortunately he's leaving for the US soon.

Bex, if you are reading this, then know that I wanted to buy this for you.

The view down part of the vegetable section of La cancha (the big market).

Two of the kids we work with club passing, while one is riding a giraffe.

The 6 month old goat that lives at one of our training centres.
I got to stroke it's head the other week :)

Two kids passing fire clubs back to back.

Adaly and a kid passing fire clubs while both ride giraffes.

John the founder with Escarlet (the lady going to study in the US).

So one of the big things that happened, was last Friday (Stardate 04121.5) which was the kids put on a show in an open air theatre in town. We sold around 80 tickets, which isn't a huge amount, but was enough, and raised some money for the upcoming Christmas party (where I've been informed I'll be dressing as Santa). So yeah the show went pretty well, a lot of it was kind of sloppy, but what do you expect from a group of kids. However everything they did was really impressive. Here are a few pics.










The final act was my favourite and was a seriously impressive doubles silks routine with Adaly and Carlos (one of the kids). Unfortunately we don't have pictures of that, and TBH the only thing that would do it justice would be a video.

Amy found a man with a very small dog in the street and got pretty excited.

So the next big thing that happened is we too kthe kids on an excursion to an eco-lodge not too far away from one of the centres. So there's ~56 kids, 4 directors, 4 volunteers, some crusty Argentinian street jugglers and 3 mothers, and around 5 babies. For two days and a night camping. Oh and also 2 llamas. There was a swimming pool, the water pretty steadily got darker and darker over the two days, so we didn't end up swimming, just hanging around hoping that none of the kids managed to drown. It went  pretty well, but we're still really tired after sleeping for 12 hours last night.

On the first day we arrived, set up some tents, the kids swam for a bit, did a bit of juggling, and then we had a sports day kind of thing. With sack races, egg and spoon races, a tug of war and so on. In the evening the kids and Argentinians put on a bit of a show, which went pretty well, other than one of the kids falling off the shoulders of Adaly who was stood on a teetor board, both of which holding fire clubs, but kids bounce, at least here they do, and so he shrugged it off with nothing more than hurt pride. One of the Argentinians did a very impressive act with cigar boxes, which is one of the props I've never been able to do any of. After we ate dinner and watched some films and then went to bed. Most of the kids slept in tents we brought, with Amy, I and a few of the others sleeping on crash mats under a thatch roof (but no walls) thingy. We were woken up at about 0430 when the kids decided to wake up and start juggling and riding unicycles around where we were sleeping. John the founder told me later that he had asked them what they were doing, they responded with "Oh sorry John, we didn't see you there.". To which he replied: "Yes because it''s still dark, go back to bed.". This highly amuses me, although I'm not sure why. So yeah, I finally got out of bed at about 0600, and proceeded to join the kids in juggling around the sleeping people.

That day there were a few more activities but was mostly a "we're too tired to do anything because you woke us up at 0430, so go do whatever you want" kind of day. So I spent most of it learning new club juggling and helping John and Adaly BBQ a metric tonne of meat, and two vegetables. It was pretty good, but I had to carry 50Kg of charcoal and now everything hurts more.

Finally we packed everything down and loaded the kids in buses, and jumped in ourselves. There were about 4 or 5 kids in every set of two seats, it was quite impressive, it only could have been better if all the kids were dressed as clowns.

The llamas (please read in Spanish as yamas).

The egg and spoon race.

Me having a tug of war with one of Daniella's kids.
She started crying because I won and she fell into a plant...

Other than that we've been getting the Alta Buena Vista site a lot more organised, and I'm making a lot of progress in teaching them silks which is cool. We're going to get a couple more silks in the new year which will help, and then I want to start focusing one day a week or an hour a day or something on exercise, so they can actually do a lot more stuff without me having to lift their legs over their heads for them. Amy and I have run that centre by ourselves for a couple of days now, and unless we find more circus directors instructors soon, it looks like we'll be doing a lot more of that.

I've done a fair bit more work with the website, still really slow, but constantly learning and so getting faster and faster now.

Finally been doing more stuff with my Tron thingy. I know can drive the bike around, produce light trails that fade away when you disable them. Accelerate and Decelerate and show your speed in a bar in the top right. I'm working on collision detection, but I need to think about this carefully as these trails could get quite long. I decided I could have the straight bits as single rectangles which are easy to detect collisions with, and the curves I can store as circles which again are easy to detect collisions within. What gets harder is that since I can accelerate and brake, it's now possible to have spirals, so I'm trynig to work out how best to model those. Once I can get collisions working, I'll probably put a bunch of effort into graphics and try and make it a lot prettier than it is now, which is the main reason I'm doing any of this.

With that I'm done for now. We should hear about visas in the next week, so that will probably be when I next update.