Archive for August, 2010

How to fix politics – ie. save the World

Posted in politics with tags , on August 21, 2010 by maxpower3141

Today a group of armed assailants invaded a luxury hotel in Rio de Janeiro, Braliz.

These are the kind of news that wake us up – why? Because it could affect us; Things like the Monsoon floods of Pakistan do not shock us, as we do not go there. So we shake it off with a “how terrible” – comment.

But things like this attack on our turf really make us think – What’s going on? How did we get here? And how can we fix the situation?

Well, in order to cut the story short, I will summarize the two news-items (and many more) into a single thought: We are screwed and the problem is poverty. Fix poverty and both of the problems above are avoided. Simple, eh? Of course this would solve a host of other problems as well.

Of course fixing poverty is not easy, but I’m afraid it is our only sane way out of a nasty deadlock – we still have some time to fix this, but of course we should keep in mind that the more we wait, the more severe the problems will get. Surely you can see problems caused by both local and worldwide poverty in your neighborhood?

No? And if you really try hard?

Another picture here:

One-fifth scale replica of the Statue of Liberty at Île des Cygnes


Eclipse: Too many files open problem – possible solution!

Posted in code on August 19, 2010 by maxpower3141

In my previous post I did a quick rant on how sucky open-source code is – well – I implied it in the context.

Just today I ran again into the problem (I now have ulimit -n and ulimit -Hn to 19000) so I started going through web trying to find real solution. The loveliest thing about this problem is that it doesn’t allow you to save your changes! So what do you do? Yes – copy the changes to clipboard, close the program open the file(s) in text-editor and apply the recent changes manually (and pray that there isn’t so many of them) – BRRRRRRR!!!! WRONG! In Linux, not even copy-paste works... Of course this most probably is not the fault of the lovely kernel but the problem lies most probably somewhere in the wonderful world of gnus, gnomes and so-forth, but damn.. πŸ™‚ I miss KDE 3.5.9.. πŸ™‚ Or maybe I should just get a mac – Ok, I’m not that desperate yet..

This forum-post shows the most promise – yet again you get stability by switching to code produced by people who are paid to do it. πŸ™‚ oh well.. πŸ™‚ Let’s see if it works – I plan to code now for a week with Eclipse open and lets see. Oh yes – the proposed solution is to switch from OpenJDK to Sun’s Java implementation – it figures… πŸ™‚

Btw. Have I ever mentioned to you that gnome sucks? It’s unfortunate that so does KDE4 now, but at least they are trying.

I will put a picture of Big Ben I took, in a vague effort to make my blog more graphical – enjoy!

Why Capitalism sucks ?

Posted in politics with tags , , on August 17, 2010 by maxpower3141

Simple question, with some nice bias built into it.

The answer is this: It does not lead to the best products in most product categories. It does work exceptionally well for products that are still being developed and improved, but a lot of the products are not this way.

It fails especially in producing durable products. I remember hearing from a friend, who had been talking to a local retailer in a small town, that they had to stop selling a particular brand of shoes in the store, because the customer wouldn’t come back for a looooong time to buy new shoes after buying a pair of that particular brand.

Therefore capitalism actually favors those kind of products that have shorter lifetime and keep sending the customer back for more. This ultimately leads to products with somewhat sloppy design and a lot of cut corners, that want to impose a certain type of tax for us. Just think about print cartridges – you know, the ink stuff? Ends up costing you tons of money if you print at home! With most computer equipment this is alleviated by the fact that the new computers are faster than the old ones, and therefore it is a smaller risk for computer manufacturers to build something that actually lasts – the optimal solution is one, where the computer usage starts to get more cumbersome and slow after a long time, making you long for that upgrade. Sounds familiar yet?

The thing is, that this list could go on and on, but I guess I have made my point already. So what can we do? Nothing? Well – that’s my first thought, since sadly capitalism is the only system we know that even remotely works. Of course in these sort of problem scenarios, we should step back, look at the big picture, identify path to solution and then go work on the details that one day will lead us there, but unfortunately political sciences – being the worst failed science of all – is somehow utterly incapable of employing this sort of thinking.

I think it might be due to capitalism – it seems very much, that in our modern western society, capitalism has employed politics as one of its tools in self-optimization, not the other way around.
Which is why Capitalism sucks.

About Coulombic Friction models

Posted in code, physics with tags , , on August 16, 2010 by maxpower3141

So I have been lately somewhat involved in modeling Coulombic friction in my (perhaps game-) physics simulations project, as you can see from my post on writing test code and the first O’Caml rant.

Just today I spent some time in augmenting the test-case for the static friction case, and it occurred to me, that you, my loyal reader and supporter, might be interested in what is involved with the math and code when implementing these kind of models, so here we go again:

First of all, let us set the background: We are interested in this case friction between two bodies connected with some kind of constraint – let this constraint be realized by the equation: \phi(x_i) = 0. The function \phi(x_i) could be almost anything involving the coordinates x_i, i = 1, 2, 3, \ldots – for example in my test-case has \phi(x, y) = \sin x + y = 0, which just tells that whatever the rest of the dynamics are, the point-body described by the coordinates (x, y) should always lie on the negative sine-curve.

Then basic Lagrangian mechanics tells us that there exists a quantity \lambda, which ensures that when one applies the force(s) F_i = \lambda \frac{\partial \phi}{\partial x_i} to the body (bodies), then the constraint can be satisfied. This force is the contact or normal force of the constraint and it has the special property that it doesn’t perform any physical work, because it is always orthogonal to the movement-vector of the body.

Then the typical, and quite accurate model, for friction force caused by the constraint \phi is that the movement of the body (/ the relative movement of the bodies) is slowed down by a force that is linearly proportional in magnitude to the normal force of the constraint F_i = \lambda \frac{\partial \phi}{\partial x_i}. Then of course the magnitude of the constraint force is \| F_i \| = | \lambda | \sqrt{\sum_i \left(\frac{\partial \phi}{\partial x_i}\right)^2} and the proportionality constant of the friction force is slightly higher in case the body is not (bodies are not) moving.

Until now, I have mostly concentrating on the dynamical friction, where the friction force is completely opposite to the velocity vector of the bodies v_i:
F^{fric}_i = - \xi \frac{v_i}{\|v\|} \| F_i \| = - \xi \frac{v_i}{\|v\|} | \lambda | \sqrt{\sum_i \left(\frac{\partial \phi}{\partial x_i}\right)^2}, where \xi is the coefficient of the friction.

Now we get to the actual predicament: How to do this in practice? The force is proportional to another force, but alas, it is the absolute value that it is proportional to! We would get perfect model for linear dependence – meaning something like F^{fric}_i = \lambda \ldots, but we do have linear dependency on the velocity – almost: it is linearly dependent on the direction of the velocity.

In order to study this, I devised three models how to numerically solve them:

1) Make the linear dependency on the velocity linear and use other values from previous known state – this results effectively in:
F^{fric}_i = - \xi \frac{v_i}{\|v_0\|} | \lambda_0 | \sqrt{\sum_i \left(\frac{\partial \phi}{\partial x_i^0}\right)^2}, where v_0 is the previous velocity, \lambda_0 is the previous Lagrange multiplier and x_i^0 are the coordinates from previous state. The nice thing about this model is that it is really simple and computationally inexpensive to implement, but it has the weird property that the velocity used comes from two different points in time, but according to my tests the model is quite ok (except for really smally velocities).

2) Make the force linearly dependent on the Lagrange multiplier \lambda, \rightarrow
F^{fric}_i = - \xi \frac{v_i^0}{\|v_0\|} \lambda \  sign (\lambda_0)\  \sqrt{\sum_i \left(\frac{\partial \phi}{\partial x_i^0}\right)^2}
Here of course |\lambda| = \lambda \  sign (\lambda_0) is always true, except when the constraint force changes directions between two time-steps, but in these situations normally anyways the bodies can drift apart (in case we have a normal contact-constraint \phi(x_i) \ge 0) and the model works nicely as it is completely up-to-date with the constraint force, but alas it is somewhat more complex to compute.

The third option, that I haven’t tried out yet, is to just throw away all quantities of current step and just throw the entire force on the right-hand-side of the dynamics equation, making it basically a constant force over each time-step and this just might be completely sufficient for my purposes but all this still requires some work and testing, as the dynamics model I’m using is somewhat novel. Hopefully I can share more about that later on. For now, I bid you good night.

Btw, I’m planning on modeling the rest-friction case as just conditional constraint in the tangent-space of the original constraint. More on that to come. πŸ™‚

Writing test-code

Posted in code, physics, visualization with tags , on August 11, 2010 by maxpower3141

One of the tasks, that in my knowledge is too often neglected (well you know I do this!), is writing test-code for new functionality.

Recently in my post on an O’Caml rant, I was complaining how O’Caml made it impossible for me to do the “simplest of all computer operations” – sleep. I simply wanted to make my CPU(s) idle for a while after drawing some visualization graphics, in order to produce a fluid animation, and it seemed hopeless. I just went on and implemented (the dreaded) busy-loop. πŸ™‚

This test-case, even though it provided visual confirmation that my dynamic friction model (well the first option anyways – I have 2 others to check still) was ok, but it was lacking something important: Error analysis – the Final Frontier for programmers, where even the uber-nerds wont go without some serious recommending.

There are a few easy things we can check out in these sort of cases:

1) Distance from constraint manifolds (for both position and velocity variables)
2) Constraint force (I actually projected the total force vector to constraint-manifold normal. subtracted gravity before projection in order to measure directly the force felt by particle due to constraint)
3) Friction force (should depend linearly on the constraint force)

Computing these values turned out to be already a task, but visualizing them over time turned out even larger task – here’s the gif-animation:

Animating particle sliding on the sine curve

Of course the classical “O’Caml list-reverse” happened, so that the plot is like a polygraph, lie-detector type of curve (For me this happens all the time with O’Caml lists – and of course any iteration through the list inverts it! :))

But furthermore the results seem good, except one tiny thing: The friction force seems to diverge when going through zero-velocity of the particle – how very odd, no? I spent already some time verifying the math – it all matches, so what’s wrong? I know my friction model in this case is not perfect, but the discrepancy should not be so noticeable.

Well, the (yet again too obvious) solution was that this model had only implemented dynamical friction!

    Rest friction not yet implemented!!

. D’Oh! πŸ™‚ The classical – without rest friction the plot is supposed to look something like that!!!

So well, moving on to implement rest friction and then to try the two other friction models! I’ll be back with more cool things! … Like more code… And physics.. and math.. and.. Uh.. Yeah – I know – super cool!Well, I am having a glass of wine while coding now, so, I guess I’m not completely hopeless, yet? Ok? And if I play a tad on my guitar?


Update: Watchmen

Posted in cinema on August 11, 2010 by maxpower3141

Finished watching Watchmen the other day (see previous post) and I can’t explain it, but somehow I was a tad disappointed by the ending – it was clever, but not clever enough – a bit too obvious, even though somewhat controversial, yet somewhat overly optimistic, when put in perspective with the rest of the film.

Just watch the whole movie and you’ll see what I’m talking about – it’s still very much worth it.

(Disclaimer: following links contain trailers of said movies that contain graphic violence – follow the links at your own discretion)

Just that the ending, for me, is not the most beautiful part of cinematic history. These, in my heart, go to Seven, Audition and Tesis (although this is in hindsight an almost too obvious slap in the face) – Hopefully I can write something about them later on, but I find it funny, that when asked, Takashi Miike (the director of Audition), said that he made the movie to shock people – oh my, what execution. πŸ™‚ Of course the alert reader will find a reoccurring theme in all of these… πŸ™‚

Watchmen RULES!

Posted in cinema on August 5, 2010 by maxpower3141

Yesterday I made myself finally watch Watchmen, well the first hour of it until now, and it is quite spectacular! Here’s one of the trailers from YouTube:

I somehow resisted watching this for a long time, for some very odd reason (I think marketing people could actually discover something by studying why this movie repels), and now that I started, I have to say that I just love it!

Somehow I had the idea that this would be some kind of comedy or parody of retired super-heroes, and it didn’t seem very interesting to me, but in reality this is an extremely harsh movie, where the poor are poor and the rich are lost – kind of like, uh, mm, reality? It is just mesmerizing!

But up until now, I only managed to watch the first hour, so please, don’t spoil the ending for me! πŸ™‚