Finding a Medoid with “Springs”

Update 2013: This is an old, unmaintained page that I wrote nearly a decade ago, available as an archive only. If it still works in your browser, you might want to consider disabling the Java plugin, which has become an ongoing security hazard. If the demo doesn’t work, please don’t install the Java plugin just for this!

Drag around the square anchors or the circular free mass. The mass will move and settle to an equilibrium position. Under the default settings this will be the medoid of the anchor positions. If you make the anchors form a line the mass will sit on top of the median anchor.

You need Java to work for this page. Sorry.

These are weird springs, they carry energy proportional to their length raised to a power. When the power is 1 (default) they will exert a force of constant magnitude regardless of extension. If you set the power to 2 they will be normal “Hookean” springs and the mass will equilibriate to the mean position. When damping is turned on, the dynamics dissipate all kinetic energy and the energy of the springs is minimised. Changing the damping and stiffness parameters change the nature of the dynamics leading up to equilibrium.

Rough Edges

To change the parameters you might have to resize your browser window first to get the applet to accept your keyboard input. If that doesn’t work, grab the .jar file and run with “java -jar”. Some parameter values cause the simulation to blow up: hit refresh on your browser. Erm and I know there is a bug or two, the simulation is by no means perfect. Sorry about all this, I’ve already wasted too much time to fiddle further.


Tom Minka pointed out some interesting properties and applications of the Medoid optimisation problem at Gatsby tea-time. This got me thinking about the energy function and then a fictitious system that would minimise it. I do realise that this is an ugly way to solve this problem; I just wanted to see how these “springs” would behave.

Thanks and technical information

I think is great. It’s fun, it’s educational and he’s made all of his code available under the GPL. All I have done to produce the above demo is add a class to the MyPhysicsLab code, the code including modifications is available.

The MyPhysicsLab FAQ might answer problems you have with this applet too. But bug me not them about problems specific to this applet.

Grumble (out of date, written in 2004)

Sun make Java too much hassle when working with free software. As a result, it isn’t packaged in my favourite operating system, and getting it to work on a non-i386 platform is a complete pain. Out of bitterness I wouldn’t have done this in Java if it wasn’t for the excellent existing code.