Space ship, somewhere well on its way to Jupiter and they’re having a real-time discussion with Mission Control on Earth. WTF Hollywood? Who the hell makes a Sci-Fi film and then doesn’t hire someone with at least a high-school level understanding of physics to check the script for nonsense? There’s a 3 second delay just talking to someone on the Moon for Pete’s sake.

According to Rotten Tomatoes this film is:

Claustrophobic and stylish, Europa Report is a slow-burning thriller that puts the science back into science fiction.

Except for that thing about the speed of light I suppose… Why is it so difficult to make a decent Science Fiction movie when there are so many good Science Fiction books out there?

Curve parameters, an analogy

September 28, 2013

While trying to explain curve parameters to my girlfriend (she was proofreading my previous blog post) we hit upon an apt analogy. Imagine you’re taking a car-trip from home to the nearest Hooters book-shop. It’s a good half-hour drive which takes you over two local roads and a motorway.

Road trip parameters

Road trip parameters

If the shape of the road you travel along equals the shape of a curve, then the curve parameters are analogous to the travel times. If you take this trip once every week, then you travel along the same roads every time. Thus the shape of the curve never changes. However some weeks you run into roadworks or thick fog or a traffic jam and then your travel times start to differ. Some parts of the trip may go faster than usual, others may go slower.

The point is that once you have the entire trip data (i.e. the entire curve data, not just the shape) you can then work out your location at 12:15. And you can work out in what direction you were travelling at 12:15. And you can work out your acceleration at 12:15. And you can work out the centrifugal force you were experiencing due to turning at 12:15. All of these properties can be computed as long as you have the curve (the route) and the correct curve parameter (the time).

It’s now also easy to see that parameters can have different densities in different portions of a curve, and how parameter density can be thought of as the ‘speed’ of a curve.

It even allows us to get a feeling for curve derivatives and why parameterization matters. Derivatives are used to compute the tangency and curvature and torsion of curves. A parallel can be drawn between those properties and the forces that push you into your car-seat due to acceleration. Or the forces that pull you out of your seat sideways because you’re turning too sharply. These forces don’t just depend on the shape of the road, they also depend on your travelling speed.

Curve Parameter Space

September 27, 2013

One of the more common misconceptions people have regarding computational geometry has to do with curve parameters. Since the mathematics of Nurbs curves are rather involved —much of it is certainly beyond high-school level— it is quite difficult to explain how control-point coordinates, control-point weights, curve degrees and knot-vectors all conspire to complicate the parameterization of a nurbs curve. My own grip on Nurbs maths is slippery at best so I think it’s better for everyone involved if I start this discussion using much simpler types of curves.

But before we can start talking about the problem, we should first lay down some ground rules for what sort of shapes qualify as ‘curves’:

  • A curve is a finite, one-dimensional object, existing in some space with an arbitrary number of dimensions. In this blog post I’ll only concern myself with two-dimensional and three-dimensional spaces as we are all familiar with them.
  • Every curve must have exactly two endpoints. No more, no less.
  • If the endpoints coincide, the curve is considered to be closed.
  • There may be no gaps on the interior of a curve, as that would result in more than two endpoints.
  • There may be no branching points on the curve, except where an endpoint is coincident with some interior point of the curve.

Basically, think of all possible curves as liquorice laces, you can stretch, bend, twist and kink them, but ultimately it’s nothing more than a bunch of deformations applied to a straight piece of chewy goop. Note that the definition above differs from the common mathematical definition of curves. Mathematicians tend to be far more inclusive and rigorous.

Read the rest of this entry »

Another Galapagos Tutorial

September 17, 2013

I’ve been thinking about Grasshopper 2.0 for a while now and there are a lot of facets to the project where I’d like to see improvement. One of the things I’m looking into is incorporating 3rd party code libraries that would provide advanced statistical and algorithmic functionality. One of the libraries I’ve been browsing is the Microsoft Solver Foundation whose main purpose is to solve optimization problems.

Looking for examples on how to use MSF I came across this blog post which poses a hypothetical (but not unrealistic) problem which can be cracked using an algorithmic solver. The post itself has some inconsistencies in the numbers it uses to describe the problem, so I’ll outline it briefly here as well:

  • You own a trading company and you’re looking to import some cheap-ass furniture from China and sell it to gullible Europeans for cut-throat prices. So the goal here is profit maximization.
  • We hire individual containers from a shipping company, and these containers have limits on how much weight you can put in. We’ll use a 500 kilogram limit in this tutorial. We are not concerned with volume limitations.
  • There are three types of furniture we can import; chairs, tables and bookcases (the original article uses cupboards instead of bookcases, but I wanted three items that start with different letters). Each has its own specific purchasing cost, profit margin and weight.
  • There is one additional constraint concerning purchasing cost; your company can only afford to spend 5000 Euros per container.

That’s it, simple enough. A profit function with three variables (amount of chairs, tables and bookcases respectively) and two hard constraints limiting the weight and purchasing costs.

Because of the weight and purchasing constraints this problem becomes non-trivial and an algorithmic approach would be good to have, if only to check your intuitions in case you’re doing the purchasing by hand.

This is a three-variable problem which means the phase space of all possible states is three-dimensional and the fitness landcape is a four-dimensional surface (if you don’t know what a fitness function/landscape is, please see this blog post or buy the Architectural Design publication with my article). I cannot draw a four-dimensional surface on a two-dimensional screen so instead I decided to just make sh*t up and hope it gets the point across regardless of being utter humbug:

Fitness Function with Constraints

Fitness Function with Constraints

Here you see a two-dimensional phase-space (let’s ignore bookcases for the time being and assume we only have to pick chairs and tables) with the resulting three-dimensional fitness landscape. From left to right we go from zero chairs to some arbitrary upper limit. From front to back we go from zero tables to some arbitrary upper limit. Every two-dimensional point is some combination (i.e. state) of chairs and tables. For every combination we can compute the profit that combination would generate, and this has been represented by the height of the landscape. The higher the surface, the more money we’re going to make. Find the highest point on the landscape and you know how many chairs and tables hit the sweet spot.

So far so good. But what about our constraints? Some combinations of chairs and tables are impossible either because they weigh too much or because they cost too much. So our landscape shouldn’t in fact exist at all when this is the case. This is known as a hard constraint and unfortunately in Galapagos it is impossible to add a hard constraint (at least for now).

Luckily we can mimic this effect with penalty clauses. We’re looking to maximize our profit, so what we’ll do is subtract a large amount of money if any of these constraints are overstepped. As long as we subtract enough, the solver will automatically avoid those areas. Enough theorizing, lets hook up some wires!

Read the rest of this entry »