Saturday, July 2, 2011

Croissant equation and Prolog.

Computacional geometry and computer graphics are subjects I rarely play with, but I like their connection with the real matter. Today in CosmoCaixa museum I found mathematical equation for a croissant. That was quite amazing - full exhibition devoted for math and equations describing natural shapes. I see croissants often in Spain and I have to admit that I never thought about their shape as a mathematical expression.


This can be ordered like that:
bar.receive_order(client.put_words_in_mouth('Un croissant, por favor.').speak_up)
view raw croissant.rb hosted with ❤ by GitHub



This can be expressed as:



and be calculated with use of:
:- lib(ic).
croissant(X,Y,Z) :-
(X^2+Y^2+Z^2+7*sqrt(5)/2-11/2)^2 - ((1+sqrt(5))*X-7+3*sqrt(5))^2-(1+sqrt(5))^2*Y^2 $= 0,
locate([X,Y,Z], 1e-5).
# one of the solutions
croissant(X,Y,Z).
X = X{0.0 .. 7.4073630564431975e-6}
Y = Y{1.066573563196598 .. 1.0665754743970506}
Z = Z{7.4073630564431975e-6 .. 1.4814726112886395e-5}
view raw croissant.pl hosted with ❤ by GitHub

I wouldn't recommend to find solutions for this equation in Ruby, so the example is in ECLiPSe CLP. It is a great tool (environment) for solving contraint logic problems. It's also fun. For me.

1 comment:

  1. I saw this equation in Barselona museam! Funny!

    ReplyDelete