Convincing, Physically-Based Rotation

April 12th, 2007


To view this content, you need to install Java from java.com

Keys Source
x axis: w,s inertia
y axis: a,d matrix
z axis: q,e quaternion
reset: r vector

Built with Processing

Tips on using the applet:

If it at first doesn't work, try a shift-reload. To make the block spin, click on the applet, and hit one of the keys that are listed. To see some cool physics at work, press and hold one axis, and then press and hold another axis, so it goes into a real fit. Then you can watch as it stabilizes itself to be rotating around a single, happy, axis.
Note (4/13): My old physics teacher tells me that in the absence of torque this effect shouldn't occur. The axis of rotation should change over time, but it shouldn't tend towards the angular momentum. We are nailing down the reason why this is happening…
Note (4/14): It turns out that the damping effect is coming from my 1-st order Euler integration technique, which is highly inaccurate, especially given the fact that we are only running at about 30fps or so. It is interesting that the errors incurred in this calculation give rise to an almost identical effect as a damping medium such as air.

What's going on:

It can be very difficult to programmatically reproduce realistic free rotation of a rigid body onscreen. Just taking a look at the free rotation of a rectangular prism (a book with a rubber band around it) can really be intimidating. I have searched for a long time for a good way of doing this, and the answer finally came to me: Angular Momentum. Of all the things that are conserved, the least represented in lower-devision physics is angular momentum. Because it is necessarily conserved except in the case of applied torque, you can represent any constant rotational motion simply by having a vector representaton of the angular momentum. This provides a springboard for a host of complex behavior, because no matter what, given a rigid body, angular momentum is conserved. The axis about which an object rotates is not necessarily constant, in fact, it requires extreme symmetry to have an object exhibit this property. The traditional notion that angular momentum = rotational inertia * angular velocity is an extreme simplification, unless you consider the rotational inertia to be a 3×3 matrix. If you do this, given a stored angular momentum, you can invert the matrix, multiply the angular momentum (vector) by it, and you get the angular velocity (vector). This won't be the same at every time step, so you'll have to re-calculate it every time. However, this extra step gives a solid physics foundation for your rotation calculations, gives you an easy way to apply torques and forces to your object, and gives you an easily calculated rotation axis. Storing the inertia tensor (3×3 matrix) in inverted form means that at every frame you just have to perform a single matrix calculation every frame to get the angular velocity of the object.

Baja Travesia

April 5th, 2007

I just got back from the Baja Travesia, a 5 day adventure race in Mexico. It's unlikely I'll be able to respond quickly to emails, but you can read the race report!

New Template: LightBox JS v2.0

March 5th, 2007

Check out the demo template that shows how to use Lokesh Dhakar's excellent image gallery code in WebExport. Check it out on the templates page, or download it directly here:

LightBox JS v2.0 for WebExport: lightbox2.tgz

New Template: PostcardViewer

March 4th, 2007

Just passing along the excellent work of Sylvain Decaux: a WebExport template that does PostcardViewer templates. Grab it from the templates page, or grab it directly, here:

PostcardViewer.tgz

The Problem With Terrorists

February 18th, 2007

The problem with terrorists is that they have entropy on their side. The buildings they take down were coming down anyway, the planes they want to crash are perilously hanging in midair, just waiting for a nudge. It is so easy for them to cause so much damage, because they are working with chaos, not against it. People are very difficult to keep alive, requiring at least food, water, shelter, and some semblance of of structural integrity. Terrorists can take any of these away, by taking out a GMO farm, dropping some botulinium in the local water filtration plant, blowing up a few buildings, or rigging up an old-fashioned improvised explosive device in Iraq. When they do, they quickly undo untold years of effort on the part of your parents which made you into the complex and well-rounded individual that you are.

A classic childhood example happens inevitably every fall when a proud father spends a saturday afternoon raking the backyard. A few hours of work took what was a messy (albeit photogenic) ground-covering of leaves and made a neat pile in the middle of the lawn. It will sit there for a night, awaiting the next morning when daddy bags it up, and puts it either in the trash or the compost, depending on his political outlook. Unwittingly, he left it out all night long. It would take no more than one giddy leap from Calvin or Hobbes to return it to its ground state: all over the yard.

It takes a hen a few weeks of dedicated effort to squeeze out an egg (though they generally do have a few in the queue). This egg is a perfectly constructed vehicle for continuing the species. It awaits fertilization, at which point it provides a young chick everything it needs to become posterity; including a tough shell, capable of withstanding impressive situations (ever seen an egg drop competition?). When you crack this egg into a frying pan, you are leveraging heat to take it down to a less useful level: one that feeds you, but could never result in a baby chicken. It costs you maybe a few cents (free if you live in the desert) to fry the egg. Not even with 1000s of brilliant biochemists and billions of dollars could you take your fried egg and take it back to its earlier state. Now, we have plenty of eggs, and they make a delicious breakfast, so the threat from terrorists here is minimal.

A big bridge, however, is not so safe from attack. It takes civil engineers months to years to create a bridge, and that's just the construction. The government-payed corporations who actually do all of this take easily decades to plan out a bridge. It takes massive amounts of planning, resources, and human gusto to put together even the simplest highway overpass. It takes an oafish terrorist a few hours to excitedly pore over the Anarchist Cookbook, a few more to get the parts and supplies, and in a day or two they have a pretty nice little bomb. Strap it to a bridge, and thar she blows.

It took probably 30 people (19 actively in the planes, plus support) to orchestrate the 9/11 attacks. These 30 people took a few years off of the end of their lives to end those of thousands. They also took out two of the most impressive pieces of architecture in the world. Let's say the terrorists spent 300 person-years to pull of their stunt (30 people, 10 years). Ignoring the incalculable worth of the individual lives they ended, the structures they demolished took sometimes 3500 people at a time, and took 4 years to construct, we'll say 8000 man-years. From this example, we can see that to destroy something, it takes at most an order of magnitude less effort than to construct it. This is bad news.

Our entire society is the bastion of centralization. A large number of people get their water, power, and gas from a single, centralized place. Anybody who has played Sim-City knows how precarious this position is: if your water-treatment plant goes south, you get lots of little gray derelict buildings and your approval ratings drop. This is not a problem of patching a few holes in an old canoe: civilization in general is far easier to destroy than it is to create: just ask the Mayans. Ever since specialization of labor, we have become dependent on each other. The more people we depend on for our continued survival, the easier it is to screw us up. "Critical Infrastructure" to an African Tribesman is his spear and the nearby river. The list for the average american is miles long, including water, power, phones, food, gasoline, shipping, and the Internet, in no particular order. Each of these represents a ridiculously complex web of interaction that boils down to a simple service. Just talk to a civil engineer about how under-appreciated they are and you'll find out how many engineer-hours it takes to give you your water bill.

The point here is not that we are unsafe, but that we are looking at the problem in the wrong way. "Anti-Terrorism Measures" mean stricter port-control, and more of those things that beep when you wear a belt or carrying change into an airport. Presumably they beep with more sinister things than that, but I haven't tested that, have you? The secret that the politicians are hiding, is that these don't do a damned thing. This has been the story in Israel for years. They have invested billions of dollars into anti-terror measures that would make Dick Cheney blow his vice-presidential load. What has it done? Nothing. They still have suicide bombers pestering them, and they still get rockets lobbed at them every other day. The only way to keep society safe is to keep people happy. If someone really wants to fry society's egg, it's just waiting to happen, literally. While this is probably an interesting lesson to those studying statistical mechanics, it sucks for the rest of us. What we need to do is stop making people want to kill us.

The money spent on "Homeland Security" would literally be better spent giving books to schools in Iraq, or passing out condoms in Africa, or paying the 'russkies to keep track of their nuclear arsenal. Hell, we'd probably get more results, though admittedly less bang, for our buck if we just dumped greenbacks and love letters out of planes instead of smart bombs. Right now, if you walk up to anybody in Baghdad, statistically speaking, one of their loved ones was killed directly or indirectly by the USA. That's bad. This may sound like hippie drooling, but do the math. "All you need is love" is not quite right: food and antibiotics help, but love's a start. This is a question of monetary scale. We could give every man, woman, and child living in Iraq $150 a month for less than it takes to keep killing them. If you live in a glass house… you better not throw stones, even if you spent the extra money and got yourself reinforced concrete butting.

Still, we shouldn't be scared here because we're still got statistics on our side. The year after the worst attacks in U.S. history, 2002, there were 25% more deaths (across all age ranges, 3770 total) from "accidental drowning" than from terrorism in 2001 (2992 total). In other words… even in a good year for terrorists, they're still offing fewer people than swimming pools and bathtubs.

Meebo Live Chat

December 6th, 2006

I've been experimenting around with the amazing website, Meebo. It turns out it gives a lot more than just the ability to do AJAX-y AIM/Jabber: it lets you put a live chat box on your website, which is what I have done. If I'm online, feel free to give me a buzz about tech support issues, product ideas, etc. If I'm not, try again later, I'm a busy guy.

iPhoto Table Edit

December 2nd, 2006

menu.jpgI just finished up work on an iPhoto plugin that allows you to explicitly change various metadata fields in a spreadsheet format. It is a SIMBL-based plugin, and is available for download:

iPhotoTable.tgz

Basic Instructions: Install SIMBL, put iPhotoTable.bundle into /Library/Application Support/SIMBL/Plugins/, launch iPhoto, see the matrix edit function in iPhoto.

You can also change which fields are displayed, as well as which fields are available for batch edit. You can do this with Interface Builder. Simply open up the main "table.nib" file and add tables accordingly. Table Columns should have display titles, and "identifiers" that correspond to the actual metadata field. Elements in the field drop down the title property for metadata field choice, and the Attributed Title as the display name.

Left-Handed DVORAK Keyboards

November 29th, 2006

Keyboards are great, but if you want to use both your keyboard and your mouse effectively, at the same time, you're SOL. You can get expensive, cool, things like the FrogPad, or you can come up with a simpler, cheaper solution. After all, you have all the keys you need on the keyboard that you got with your computer, they are just placed badly for one-handed use! Well, the solution was invented a while ago, by Dvorak. He designed a keyboard layout for folks without a right arm, which is cool, because that arm can then be using a mouse. The actual keyboard layout is documented by the good folks at Wikipedia.

I have made a keyboard layout for MacOSX that transforms your current keyboard into a lefty-dvorak keyboard. Toss it in /Library/Keyboard Layouts/, Log out, log in again, and use a sharpie to write the new letters on your keyboard. You can always take it off with rubbing alcohol later.

Without further ado: Dvorak-Lefty.tgz

Note: Thanks to Tom for pointing out some issues with caps-lock, the new file deals (I hope) with this issue.

WebExport 1.0r132 Posted

September 27th, 2006

WebExport 1.0r132 fixes an issue with non-72dpi images which used to scale "blockily". Now they appear to be fixed. Comment here to let me know about issues with 1.0r132.