Math Equations

Friday, February 28, 2014

How to setup AndEngine in Android Studio


This guide assumes that you have Android Studio, git, a terminal and rsync installed.
  1. Create and open the project in which AndEngine will be used.
  2. Create a module for AndEngine.
    File → Project Structure → Modules → + → Android Library → [Module name: AndEngine, Package name: org.andengine, Create activity: no] → Finish
  3. Tell the compiler to search the AndEngine module by adding a dependency.
    File → Project Structure → Modules → <the module that will use AndEngine> → Dependencies → + → Module dependency → :AndEngine
  4. Download AndEngine by running the following in a terminal:
    $ cd <project folder>
    $ git clone -b <GLES2 or GLES2-AnchorCenter> https://github.com/nicolasgramlich/AndEngine.git AndEngine.github
    $ rsync -a AndEngine.github/* AndEngine # This merges AndEngine.github and AndEngine
    $ rm -rf AndEngine.github
  5. Make a minor change to the file tree of AndEngine to make it work with Android Studio.
    $ cd <project folder>/AndEngine/src/main
    $ rm -r java/org
    $ mv org java
  6. Ensure that Android Studio notices the changes you did. Do this by right clicking on the AndEngine module in the Project tool window and choosing Synchronize 'AndEngine'.
You should now be able to use the core AndEngine package.

Optional: adding an extension

Adding an extension is much the same procedure, so I'll only list the additional things you need to do.
  • Before 2: To find the package name of the extension, browse the extension repo on github and look in AndroidManifest.xml.
  • After 3: Make the extension dependent on AndEngine.
  • At 5: This step may vary slightly. You may not need to do anything.

Fixing java.lang.UnsatisfiedLinkError

When I tried to use the physics extension, everything compiled fine, but when I ran my app, it crashed, logging: java.lang.UnsatisfiedLinkError: Couldn't load andenginephysicsbox2dextension from loader dalvik.system.PathClassLoader[...]: findLibrary returned null

That is, the .so files are not in the apk. Workaround:
  1. Manually copy <extension-module>/libs/* to a new folder <main-module>/lib
  2. Compress lib/ to lib.zip
  3. Rename lib.zip to lib.jar
  4. Add compile files('lib.jar') as a dependency in <main-module>/build.gradle
However, it must be noted that one has to update lib.jar manually in the future!

Happy coding!



Monday, February 24, 2014

A partial fraction decomposition

$$ \prod\limits_{i=0}^{n}{1 \over x + i} = {1 \over n!}\sum\limits_{i=0}^{n}{(-1)^i {n \choose i} \over x + i} $$

For example when \(n = 2\),
$$ {1 \over x(x + 1)(x + 2)} = {1 \over 2}({1 \over x} - {2 \over x + 1} + {1 \over x + 2}) $$

I have no proof yet.

Wednesday, February 5, 2014

A Musical Epiphany

I discovered something great today. It is possible to listen to notes of a chord selectively. If you play the chord C major {C, E, G} (all three tones at once), it is possible to listen to the chord as if a melody was played. For example you may hear the tone C followed by E followed by G followed by E again even though the keys are actually hit all at once.

Played:
Observed:

How is this possible? Can I do this? you ask. My answer is I don't know, but I suspect it has to do with resonance in the ears. When I do it, it feels as though some muscle deep in my ear is contracting or relaxing depending on the tone (contracting if the tone is higher). Try it and let me know your results!

What does this mean? How can it be investigated further? What applications are there? My hopes are that I will get good at doing it so that I can "tune into" (resonate at) any frequency that I want. I would then for any chord be able to plot a graph with observed intensity on the y-axis as a function of the frequency that I am looking for on the x-axis. Obviously, the ability can also come in handy when analysing music: is that a C6 or a Cmaj7? Last of all, it may be possible to develop a theory which connects the shape of the aforementioned graph to the feeling of the music. Instead of saying That's a C13+11! we might say That's Mount Everest!

Discovering this makes today a big day in my life. I'm going to be sentimental and write down the exact minute it happened. 2014-02-05 17.40 CET.