Saturday, June 28, 2008

Status report: week 5

This week I was implementing Mirtich's V-Clip algorithm for collision detection.

Also I found several bugs in my functions, which took some time to fix. To check the code I used QuickCheck properties. I expect to finish V-Clip during the first half of the following week, if everthing goes fine.

I also found time to cabalize and haddockize Hpysics. Note that you need haddock 2 to build docs, because earlier versions don't like parallel arrays syntax.

Also, there was an interesting challenge with QuickCheck. To test some things I need to generate non-zero vectors. I tried the following:

nonzero :: Gen Vec
nonzero = do
  v <- arbitrary
  if norm v > 0 then return v else nonzero

(i.e. if we got zero vector, just generate another one until we get what we want), but for some reason this code doesn't terminate. To understand why, I probably should learn more about how QuickCheck's rng works, but I won't complain if someone explains this effect :)

Wednesday, June 25, 2008

V-Clip algorithm (status update)

Finally, I've found an algorithm which should be relatively easy to implement. It is Mirtich's V-Clip algorithm described in this paper.

It is similar to Lin-Canny algorithm (they both are based on Voronoi regions and even uses the same theorem), but advantage of V-Clip is that it avoids finding the closest points of two features (that was the problem I could not resolve last week).

So, I'm going to dive deeply in the paper and try to implement that algorithm.

Friday, June 20, 2008

Status report: week 4

This week went not so good as I was planning.

I wanted to implement simple ad-hoc cubic collision geometry to test collisions with rotation. So I started with calculating closest features of two polyhedra (this would also be useful for Lin-Canny algorithm), but when it came to faces it became too cumbersome (and this part isn't very extensible, because it deals specifically with squares, not generic polygons).

So, I decided to spend some time reading papers on this topic and looking for acceptable solution.

If I won't find anything better, I'll end up implementing Lin-Canny algorithm (I don't want to do this atm, because it's not very simple and requires some reorganizing of simulation process). As always, suggestions are welcome!

Friday, June 13, 2008

Status report: week 3

This week I devoted to rotation. To test it I added cubic shape.

I use quaternions to represent orientation of body in space (see Quaternions and spatial rotation).

To integrate orientation of body over time, numerical methods of solving differential equations are used. Currently I use Euler method, but it can be easily replaced by any other, see Hpysics.ODE. Differential equation itself is produced by Hpysics.Simulation.rotationDE.

Finally, I added rotation visualization, so if you compile vis.hs, you can watch falling rotating cube.

Next, I need to handle collisions properly with respect to rotation. So, I'll need to implement collision detection for cubic shape, and when bodies collide, angular momentum should be added in addition to linear.

I also think about documentation, which should be added at some point. On the one hand, haddock is convenient with its hyperlinks. On the other, literate haskell is interesting alternative. It can be less formal and more descriptive then haddock.

Saturday, June 7, 2008

Status report: week 2

During this week I dived into OpenGL and finished with a simple visualization. It isn't very fancy, but at least now I can say engine produces some physically plausible results.

Another achievements include rewriting vectors as data types and writing few unit tests.

The next thing I'm going to do is to add some 3d physics, namely, friction, restitution and rotation.