Friday, October 31, 2008

MinGW "ln -s"

I just spent about an hour looking for a problem that didn't exist, and it is all due to the fact that "ln -s" doesn't do what I expected it to in Msys/MinGW. I have an project that uses plugins for most of the UI and assumes that the plugins reside in a specific directory (./plugins in the application directory). Most of the time I use a cross-compiler so I don't have to leave linux land. When developing in windows, with release/debug targets, I link the plugin directory to the release directory that my plugins are compiled in (ln -s plugins/release plugins). The only reason plugins have ever not loaded was due to them missing some flags during link, or when one of my plugins has the same name as a core library that I use (only because the dll's aren't prefixed with "lib" like they are in linux). Anyway, some plugins were not loading, and I couldn't figure out why--trying of course the obvious aforementioned problems. As it turned out, the linked plugin directory was not being updated with the newly compiled plugins, meaning the minor changes that I made, which would have resulted in valid plugins, were not being used. Anyhow, I spent far too long on this until realizing that the sym link was not a sym link at all.

Wednesday, October 22, 2008

Lighting rod simulation



Have been talking with a friend about simulating and rendering electricity for some other projects recently. I encountered a self-contained paper (http://www.cs.unc.edu/~geom/LIGHTNING/lightning.pdf) on the subject and spent a little time this evening hacking up a quick implementation of the simulating a bolt. It's way simpler than I expected, and gives me one more reason to be glad (yes I'm glad) I'm friends, I'm friends, with the Laplace/Poisson equations.

Anyhow, a crappy rendering using a coarse grid (no tracing lines, or anything fancy), blurred and combined with the gimp. I guess blogger doesn't like the gif I uploaded, so this entire post was a waste.

Friday, October 3, 2008

Voronoi


I can officially almost add 2D delaunay triangulation (or voronoi diagrams) to the list of things I have implemented (if I actually had a list it would be pretty long by now). But why bother, you ask? Well, every time I have needed Delaunay, which is more often than you would think, I seemed to end up using popen with the program qhull and writing my input data to a file and reading from the popen (or by setting up a fifo to do the writing with dup/dup2). Although this works, it is nice to have a lightweight version.

Anyway, this is blog more about debugging than anything. I implemented a version of Fortune's algorithm (from Computational Geometry: Algorithms and Applications) without using an AvlTree (yeah, I know it is not quite n*log(n), but it is fast enough). The implementation is rather straightforward, but I stumbled on a few oversights. First, was determining when the breakpoints on the beach line will converge, and second was the allowance of the sweep line to move in the reverse direction for circle events.

For the first problem, I ended up just computing the circumcenter of the 3 points, hypothetically moving the sweep-line to its y-coordinate and testing whether the breakpoints were close enough to each other. Detecting these events incorrectly will result in the data structure representation of the beach line becoming inconsistent. This for the most part made everything almost work.

Unfortunately, while checking for possible circle events, I was throwing away those events that should have already happened (e.g., y-coordinate greater than current sweep line). This turns out to be a no-no, as when I removed this check (after looking several other places for the source of the problem) everything worked great. Just finished running a script to check the triangulations with those returned from Octave, and the number of triangles seems to check out, so I am assuming that the results are okay--not very thorough, I know, but the ones I inspected visually seemed to be identical.

There are several algorithms that are named after people (e.g., Dijkstra), that seem like they are rather obvious and someone surely others would have come up with if. I'm not so sure Fortune's algorithm fits into this category.

Anyway, it sure looks neat to watch it in action. I almost gave up looking for the problem this evening. I wonder how many problems were really close to being solved and just needed a little more perseverance. I'm glad I wasted about 2 hours looking for these problems, even if I never end up using this code. Still some cleaning up to do.

Thursday, October 2, 2008

Back from Japan

Got back from Japan the day before last, and although I thought I was over Jet lag it appears I am not. As my extra early wakefulness is due to Japan, it is appropriate that I write something about Japan, namely some trip details, during it.

I went to Japan on last minute notice, where by last minute I mean I booked my flight a week before it departed. My primary reason for going was to force myself to do things that I felt like saying no to as a friend had just recently asked me if I wanted to join him on his journey. I met up with the so called friend and another friend in the airport at Vancouver before connecting to Tokyo--where we would meet up with a Japanase friend that was hosting us.

The trip was meant to be more of relaxing than tourist, with plenty of skateboarding and casual sightseeing. Tokyo harbours some crazy skate spots, plenty of marble ledges and crazy rails. Everywhere we went we saw flatbars that were potentially skateable. We did end up skating quite a bit, some parks and several street spots, but it turned out that transportation from our resident Tokyo satellite to the scattered Tokyo spots limited the number of spots we could hit. The skateboarders in Japan were super fun to skate with; always good vibes, and they would always be stoked on tricks landed. The skaters all had crazy pop.

Skateboarding aside, much of the trip, at least from my perspective, was lived with a beer in hand: beer while walking, shopping, driving in cars, or riding the trains. Not because I am a heavy drinker, but because it was acceptable (or was it) and available. I arrived in Japan a recent vegetarian, with hopes of sticking to my eating habits. This turned out to be rather difficult, as most dishes had meat in them and a translator was not always on hand during ordering to decode the menus or make special requests. The food, restaurant or convenience store, was pretty much always good. Once I overcame the meat eating aspect, I started to enjoy the seafood as well--something I hadn't been a fan of in the past. Before going, others told me how they missed even the convenience store food; I now understand what they meant.

Of course, many aspects of life appeared to be the same in Tokyo as they are in Canada. Besides the long commute from the Tokyo suberb we stayed at (1 hour by train), the other main things had to be never ending little technological advances such as their toilets, mechanical sushi vendors at restaurants, and coffee vending machines with video display of the coffee being made. Public toilets rarely had soap. Smoking is still acceptable in restaurants, so I smoked. Drink vending machines are everywhere, and they contain cold coffee lattes--I drank several of these daily. Hot brewed coffee is harder to come by than a cold latte (from a vending machine); a grande cup of hot from Starbucks is about 400 yen (roughly $4CAN), where strangely a specialty latte was not too much more. Things like pizza and fries were also fairly expensive. Transit was also fairly expensive, our daily train commute costing upwards of $10 one way (car travel was even worse due to highway tolls). All these little things aside, one of the most notable differences was the overall tolerance of the Japanese people. Even when someone getting cut off by another driver (or bike, or person), they didn't seem to get frustrated or upset like they would have here in North America. Another testament to Japan is how safe you feel there. How could it be any other way, when you can leave your bike without locking it and know it will be there when you return.

Japan was great, the people are nice, the food is good, and there is cold coffee everywhere. I'm happy that we didn't completely do the tourist thing on this trip, as it gives me another good reason to return to Japan. Also, my camera broke in a sake induced drunken bike ride, so I'll have to return just to take the pictures I would have taken.