Quaternions are an Extension of Complex Numbers

May 13, 2009

Quaternions are two things: an extension of the complex numbers and a handy way of representing rotations in computer graphics.  I’m only covering the first one here.  This actually wasn’t covered at GDC, probably because you don’t actually have to understand quaternions to look up the algorithms for using them. I like being complete.

i2 = -1

i is the square root of negative one. They teach that in algebra 1 (or maybe it’s algebra 2). Complex numbers are numbers that have i in them; they look like a + bi, as if i were a variable. (3i) * (4i) = 12i2 = -12.

Quaternions are complex numbers except that they have 3 magic letters instead of 1; the familiar i, as well as j and k. Imaginative, I know.

In quaternions i isn’t the square root of negative one. It’s a square root of negative one. So are j and k.

i2 = j2 = k2 = -1

There are a couple more rules for Quats, but really not that many:


  1. ij = k
  2. ji = -k
  3. jk = i
  4. kj = -i
  5. ki = j
  6. ik = -j

Notice that ij != ji. Multiplication is not commutative (in fact it’s anti-commutative; ab = -ba. These rules are enough to multiply two quats, via one big distribution:

(a1 + b1i + c1j + d1k) (a2 + b2i + c2j + d2k)

= a1(a2 + b2i + c2j + d2k)
+ b1i(a2 + b2i + c2j + d2k)
+ c1j(a2 + b2i + c2j + d2k)
+ d1j(a2 + b2i + c2j + d2k)

= a1a2 + a1b2i + a1c2j + a1d2k
+ b1a2i + b1b2i2 + b1c2ij + b1d2ik
+ c1a2j + c1b2ji + c1c2j2 + c1d2jk
+ d1a2k + d1b2ki + d1c2kj + d1d2k2

= a1a2 + a1b2i + a1c2j + a1d2k
+ b1a2i - b1b2 + b1c2k - b1d2j
+ c1a2j - c1b2k - c1c2 + c1d2i
+ d1a2k + d1b2j - d1c2i - d1d2

= (a1a2 - b1b2 - c1c2 - d1d2)
+ (a1b2 + b1a2 + c1d2 - d1c2)i
+ (a1c2 - b1d2+ c1a2 + d1b2)j
+ (a1d2 + b1c2 - c1b2 + d1a2)k


I lost the bet

May 13, 2009

IMG_0462Bethany and Matt, whom I watched eat dinner, speculated that everyone would fall into two categories; the people who wanted to see me break, and the supporters who wanted to see me succeed.  I thought everyone would fall into the wanting-to-see-me-break category.  I was closer to right, but still wrong.

It turns out that everyone fell into the you’re-an-idiot category, and most of them tried to talk me out of the bet.  Our VP of engineering tried to redefine “monkey chow” so that I could eat real food under a different name.  Our health food guru, Manish, was of the opinion that “you should get out of the bet.  There’s organic food, and then there’s normal food, and then there’s animal food.  Animal food companies get sued all the time for leaving poison in their food.”   Dusty handed a monkey chow pellet to Manish, suggesting that he smell it.  “No,” argued Manish.

I had some trouble thinking straight yesterday and the day before.  I didn’t know if it was from not eating enough, or from something they put in the chow.  I guessed that it might have been the caffeine pill I took (no coffee allowed during the bet, remember?)  So, yesterday, no caffeine pill, and the inability to think was even worse.  That was the real deal-breaker.  I need to be able to think.

IMG_0466I was getting pretty frustrated with the stuff already anyway.  The taste was tolerable; it was how much of a pain it is to eat.  It’s dry and crusty, and takes a long time to chew up.  I tried making a monkey chow shake in the blender, but it might as well have been a sand shake; it all falls to the bottom and won’t pour out.  I had to chow down on pellets for almost a half hour just to go from too-hungry to merely hungry.

So, it’s over.  I gave up yesterday, before lunch – which was omakase at Kanpai, a $35 value, paid for by my manager.  And tonight is the free $200 sushi at Sawa that the company is also picking up.  All of these were real reasons to drop off the “diet” too, especially since the bet was only for $100.

The Chow Is Here; The Bet Is On

May 11, 2009

We  agreed that the bet started when the monkey chow got here.   I didn’t realize this when I wrote about the bet earlier today, but Dusty had already bought some chow, and sprung it on me today.  This is a real dick move, for several reasons:

  1. Dusty sprung this on me knowing that I already had a sub I was going to eat.  Now I have to throw it away, and he refuses to pay for it.
  2. Dusty knew that I had a dinner date tonight with my cousin and her boyfriend, who are moving away from the bay area in two weeks.  This was going to be one of my last chances to see her before she moved away.  I had to drive them to the restaurant and watch them eat.
  3. On Friday, IMVU was going to treat me to a $200 sushi dinner as a reward for some work I did several months ago.  Dusty did not know about this one, although the original version of this post claimed otherwise.  Now I can’t go.  Yes, I realize that the bet is for less than $200.  I’m still going to win.  Maybe I can get IMVU to reschedule.

The monkey chow is actually pretty good.  It tastes like life cereal.  It takes a long time to eat because it’s so dry, so I tried blending it up with some water.  Monkey Chow smoothies aren’t so bad either.  There’s a weird aftertaste, but I bought three big bottles off mouthwash – one for home, one for work, and one or the car.

Dusty says he was worried that starting the bet today might be too much of a dick move, but that he conferred with several of my other former friends, who said it would be cool.

Monkey Chow

May 11, 2009

Two of my friends were making fun of me for eating very quickly. The joke is that I don’t taste food. “Ha ha,” I agreed. Then one of them said I might succeed where this guy failed.  I think I could do it.  Dusty thinks I can’t.  We bet $100.



So, when we get around to ordering it, I’ll be eating nothing but monkey chow and water for a month, after which I’ll be $100 richer.  The $100 should more than cover the mouthwash expenses I’ll undoubtedly incur during the “experience.”

Step 2 part 2: I suck at setup

April 21, 2009

I went back to the project portal I had so much trouble finding yesterday, and resumed the walkthrough for getting my security key / certificate set up. The instructions told me to go to a specific page to download my certificate, but that page told me I didn’t even have one. I had to submit another request, and get another certificate going. It seems like Apple considers me a Team of One (Be All That You Can Be!), so I had to sign up both as the team lead and as a team member. Also, I had to approve my team member certificate, since I’m the team administrator. Kinda made me feel powerful. Apple also had to approve me separately both as team admin and as team member, so I had to wait for that, but as yesterday, it was almost immediate.

I moved on to getting my phone into development mode. By now I’m pretty good at finding the tutorials for how to do things on apple’s site, but that doesn’t mean that they’re any good! The instructions start with:

  • Download the iPhone OS Disk Image (.dmg) from the iPhone Dev Center for the Apple device you are using.

They don’t say where you can do that, and I couldn’t find it. Before I looked around for solutions, I decided to try building my Hello World app to see if it gets through the errors I had yesterday. Success! I got a different error:

CodeSign error: a valid provisioning profile is required for product type ‘Application’ in SDK ‘Device – iPhone OS 2.2.1’

Sounds like xCode has a problem with my 3GI still.  So, back to getting my iPhone into developer mode! At least Apple’s keeping me on track. Sure enough, the first google result for “Download the iPhone OS Disk Image (.dmg) from the iPhone Dev Center for the Apple device you are using”  was a forum where someone else had the same problem. The first few solutions on the forum direct you to no-longer-existent links to the download.  The solution I tried: tell iTunes to “restore” my phone, which, as it turns out, means “crank for 45 minutes and leave the phone in the same state.”  It deleted everything off there, maybe installed the OS I want, and is now re-uploading all my music on there.  We’re waiting on that right now.  It looked like a long block, so I decided to use the time for today’s blog post.

Yesterday, the great Steven Peterson read my blog and had a lot of helpful suggestions for how to get started.  He’s got a delicious page that, hilariously, I can’t link you to here because I stored the URL in a note on my iPhone.

Oh, hey!  It finished.  Huh.  It restored all my media files but threw away all my apps, including the one that was tracking my diet.  And it turns out I lost the link, so we’ll have to wait and see whether Steven reads my blog again today.  For now, let’s see whether I can build my Hello World app.

Steven, and guy who commented on my blog yesterday, I understand that I don’t have to do this step right now 🙂  In fact, if I switch xCode to use the simulator instead of my 3G, I get 3 other compile-time errors.  I’ll deal with them later.  For now I really want to know that I have all the pieces ready to go.

Anyway, no, it appears the iPhone restore was in vain.  Same error.  Let’s ask the Google.  Damnit; none of those solutions are going to work for me, and I’m out of time.  Be back tomorrow.

iPhone App development step 2: Keychain

April 21, 2009

So I paid my $99 and got approved by Apple. Many months passed during which I never had a free weekend. This week, my roommate and I decided we’d get up 2 hours early every day and work on a personal project during those two hours, so for the last hour and a half I’ve finally done some iPhone development. Well, setup for it.

During the last few months, I’ve been asking some other iPhone developers I know how to get started, and gotten some tips; a couple different ideas for how to test-drive an app, ways to get started, and such. None of them mattered this morning; I ended the morning being blocked by something completely unforeseen.

I already downloaded and installed the 2.2.1 SDK, not really knowing what that means. I guess it’s a text editor, build system, and standard library for the iPhone. I found xCode, the editor, on my computer, and walked through apple’s Hello World iPhone tutorial. It involved the creation of a project and the retyping of some code without understanding it (the language is objective C), then a build and a run. The build failed with this message:

CodeSign error: Code Signing Identity ‘iPhone Developer’ does not match any code-signing certificate in your keychain. Once added to the keychain, touch a file or clean the project to continue.

Sounded like Apple’s SDK won’t even build your project for you locally unless it has some authentication. I didn’t know what keychain was, but it sounds like Pageant. I googled this error and saw lots of forums threads I didn’t understand, then looked around apple’s website. It said that I needed an “iPhone Development Certificate,” which I wrongly assumed I already had. It turns out that what I have is membership in the iPhone Developer Program, which is different. What that gets me, according to apple, is the ability to apply for an “iPhone Development Certificate”, which is what the SDK requires. To apply for an iPhone Development Certificate, I needed to create a Certificate (some kind of crypto key, created by an apple program called Keychain) and submit it in a Certificate Request.

The instructions for creating a Certificate were only hinted at, not explained, in the developer section of the apple website. They said I needed to go to the “iPhone Developer Program Portal” to actually get instructions and submit the certificate request. When I tried to log into the portal, it walked me through the developer signup steps (including the $99 payment, again) – turns out this was a bad cookie horking my session. At the end of the signup, the developer webpage told me I’m already a developer, and wanted me to sign out. I signed out and back in, and lo, I had a link to the “iPhone Developer Program Portal”!

In it were wrong instructions for how to create a Certificate Request. In particular, they assumed the wrong location for the program (KeyChain) that creates the security keys, one of which I need to submit. (Also, I learned that OS version numbers have magic names. “Leopard” is the one Apple expects me to have. I don’t know what jungle cat my mac mini is actually running.) At Dusty’s suggestion, I used the finder to launch KeyChain, and from there the walk-through worked fine. I created a key and submitted it with a Certificate Request. At that point, I was blocked until Apple approved the request, so I dropped development for the day and started writing this blog entry.

About halfway through typing this up, Apple approved my Certificate Request, so I can get started again. Unfortunately, my 2 hours for today are almost up, so I’ll have to pick up here tomorrow morning. See you then!

iPhone App development step 1: Giving Apple $100

April 21, 2009


This post is from February, merged from my other (now defunct) blog

Steps -2 and -1 were buying a mac mini and a 16GB 3GI. Accomplished. Worth the money on their own, actually! Step 0 was coming up with an idea for an app. This was hard to do. Most of the good app ideas have already been done. However, considering what kind of apps are succeeding, maybe I’m wrong about what’s a good idea! Nonetheless, I have an idea.

Today was when I made what I consider my first real step towards making my app: paying Apple $100. I signed up at their site, filled out their survey, and maybe they’ll let me try to make them some money. If not, I hear they’ll give my money back. It’s a bit underhanded, if you ask me – them taking my money when I apply and giving it back only when they reject me. It makes me feel like I wasn’t charged, but they get to float the money, and it then motivates them to delay rejections. Hmph.

So, the next steps, not necessarily in this order, are going to be:

  • Read up on objective C (begun)
  • Read up on the iPhone platform
  • Set up a version control system on my fancy new mac

None of them are blocked on Apple accepting me as an iPhone developer. The ones that are AFAIK:

  • Convert my iPhone into developer mode
  • Set up Apple’s development environment
  • Set up a testing environment (TDD FTW!)

I’ll get started on these and resolve which ones are actually blocked by Apple. More posts to follow, as well as reports on how the learning is going.