Quantcast
Channel: Programming – Roy Tanck's weblog
Viewing all articles
Browse latest Browse all 14

Math problem: Why does this work?

$
0
0

gifloopcoder animation

A couple of days ago, I was playing around with Gif Loop Coder, and I set out to create an animation where a number of line segments would form a flower-like shape. You can see the effect above.

To create the flower shape, I placed a number of circles on the canvas, spaced evenly around – and touching – the center point (the dark circles above). I figured it would be hard to determine which parts of the circle to actually draw to get just the outer shape (drawn in white). But instead, I got it right on the first try, and this has been bugging me since. It works, but I don’t know why it works.

The angle of the cirle that gets drawn is 360 degrees – a full circle – divided by the number of circles, times two. So for 7 circles, the math is simpy “(360/7)*2”. I was expecting this to be much, much more complex.

In this animation’s code, the number of circles (or “flower leafs”) is a variable, and this very simple formula work with every value of that variable. I just can’t figure out the logic behind this.

Any ideas? Please leave a comment!

— UPDATE —

My friend Hjalmar posted the solution on his blog (and below as a comment). The following image he provided clearly shows why the formula works. His post offers a lot more detail.

circles6

Thanks Hjalmar!


Viewing all articles
Browse latest Browse all 14

Trending Articles