Fractal curve — Sierpinski arrowhead
Yesterday I wrote about the Koch curve, and today I’m writing about the Sierpinski arrowhead curve. The two fractal curves have a lot in common.
Wikipedia has some good illustrations.
The Sierpinski arrowhead curve draws an equilateral triangle with a bunch of triangular holes in it. It can be described with two substituting production rules: (A –> B-A-B) and (B –> A+B+A). A and B recurse and at the bottom do the same thing — draw a line. Plus and minus (+ and -) mean turn 60 degrees either left or right. The terminating point of the Sierpinski arrowhead curve is always the same provided you recurse an even number of times and you halve the length of the line at each recursion. If you recurse to an odd depth (order is odd) then you end up turned 60 degrees, at a different point in the triangle.
This is easy to describe in code. Given these drawing functions:
void draw_line( double distance); void turn( int angle_in_degrees);
The code to draw an (approximate) Sierpinski arrowhead curve looks like this.
void curve( unsigned order, double length, int angle)
{
if ( 0 == order ) {
draw_line( length);
} else {
curve( order - 1, length / 2, - angle);
turn( + angle);
curve( order - 1, length / 2, + angle);
turn( + angle);
curve( order - 1, length / 2, - angle);
}
}
void sierpinski_arrowhead_curve( unsigned order, double length)
{
// If order is even we can just draw the curve.
if ( 0 == (order & 1) ) {
curve( order, length, +60);
}
else /* order is odd */ {
turn( +60);
curve( order, length, -60);
turn( +60);
}
}
The number of line segments is (3 ** order), and there is exactly one turn between any two adjacent lines. If you negate the starting angle you flip the triangle upside down.
You can also make a star or a hexagon.
void sierpinski_arrowhead_star( unsigned order, double length)
{
sierpinski_arrowhead_curve( order, length);
turn( -60);
sierpinski_arrowhead_curve( order, length);
turn( -60);
sierpinski_arrowhead_curve( order, length);
turn( -60);
sierpinski_arrowhead_curve( order, length);
turn( -60);
sierpinski_arrowhead_curve( order, length);
turn( -60);
sierpinski_arrowhead_curve( order, length);
turn( -60); /* full circle, back where we started */
}
void sierpinski_arrowhead_hexagon( unsigned order, double length)
{
sierpinski_arrowhead_curve( order, length);
turn( +60);
sierpinski_arrowhead_curve( order, length);
turn( +60);
sierpinski_arrowhead_curve( order, length);
turn( +60);
sierpinski_arrowhead_curve( order, length);
turn( +60);
sierpinski_arrowhead_curve( order, length);
turn( +60);
sierpinski_arrowhead_curve( order, length);
turn( +60); /* full circle, back where we started */
}
Disclaimer: I haven’t tested these functions. I’m just coding into the wild blue here.
Comments
29 Responses to “Fractal curve — Sierpinski arrowhead”
ibuprofen is really a excellent pain reliever in spite of this i heard that
this one have nasty side effects too
The “Grand Theft Auto chases, the blazing gunfights, and that
the audacious wrecking ball jewelry heist look cool then again these scenes seem from place in
this lackluster buddy comedy.
home repair can be tough specially when you do not have any other idea at all about what you have
been doing,,
drug addiction is usually a menace to the society, it
destroys lives and it destroys that the community
Pretty nice post, thanks for the awesome article. Im having
troubles subscribing to your internet websites feed. Thought Id let you know
It’s such as you read my thoughts! You seem to recognize a large amount approximately this, such as you wrote that the guide in it or something. I feel someone to just could do with several percent to drive the message home a tiny bit, then again other than that, which can be first-class blog. A fantastic read. I will definitely be back.
there isn’t any day in the month that i do not want to visit your blog.
Nice blog. Excellent theme except of footer. I actually for instance this post.
It’s amazing what you wrote here. I hope you will write something so amazing soon.
Im impressed, I have to admit. Truly rarely should i encounter a
blog thats both educative and entertaining, and without a doubt, you might have hit that the nail around
that the head. Your concept is outstanding the catch is something
not enough consumers are speaking intelligently about.
Were delighted i stumbled across this inside my find some thing regarding this.
Researchers have prepared an animal model of major depressive disorder which is contingent on an unusual genetic mutation that appears to
cause that the condition in most of people who inherit it
Hi, I do think this is a great website. I
stumbledupon it ;) I’m going to revisit yet again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.
Thanks for that the one of that the nicest internet sites i
have read in the while.
Where by have you found that the resource for the following post Awesome studying I have subscribed to your site feed.
I’m not sure where you are getting your info, but good topic. I needs to spend some time learning much more or understanding more. Thanks for fantastic information I was looking for this info for my mission.
Utterly written subject material , Really enjoyed searching through .
Pretty element of content. I just stumbled upon
your weblog and in accession capital to assert that I find out really enjoyed account your weblog
posts. Anyway I will be subscribing to your feeds or even I achievement you find out admission to consistently
speedily.
What’s up, constantly i used to check weblog posts here in the early hours in the dawn, for the reason that i love to gain knowledge of more and more.
Hello! Would you mind if I share your blog with my twitter group Theres plenty of folks
that I think would really appreciate your content.
Please let me be acquainted with. Thank you
I actually love that the approach you discuss this kind of topic.
What’s up friends, nice article and fastidious arguments commented here, I am actually enjoying by these.
Thanks for every other informative web site. Where else may I get that type of information written in such an ideal manner?
I’ve a undertaking that I am just now running on, and I’ve been on the glance out for such info.
It is rare knowledgeable folks for this topic, but
you sound like theres more youre discussing!
Thanks
i always look for golf courses with wellmaintained lawn
and golf courses with very clean recreational area,,
Spot on with this writeup, I truly believe this web site requirements considerably more consideration.
Ill probably be once more to discover far more,
thank you for that information.
There have been numerous fascinating time limits in this posting however I dont recognize if
I see all of them center to heart. There is some validity on
that the other hand Im going to take hold opinion until I check into it further.
Fine article , thanks so we want extra! Included in FeedBurner as properly
You are an ocean of knowledge, otherwise how is it feasible to write and express your opinion on every topic so without problems.
Bow before you!
Thanks a lot for sharing this with all of us you actually recognize what you are talking about!
Bookmarked. Kindly also visit my site =. We could have a link exchange contract between us!
Hey, I just hopped over to your site by tactic of StumbleUpon.
Now not one thing I would usually read, conversely I
appreciated your thoughts none the less. Thanks for making something worth reading.
Strumming my pain with his fingers. Singing my life with his words.
chantalmeNOTHIN