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”

  1. http://criminalbackgroundchecked.com/ on July 4th, 2012 12:03 pm

    ibuprofen is really a excellent pain reliever in spite of this i heard that
    this one have nasty side effects too

  2. ourmidland view website on July 7th, 2012 8:49 am

    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.

  3. scholarships for single mothers on July 8th, 2012 3:27 am

    home repair can be tough specially when you do not have any other idea at all about what you have
    been doing,,

  4. scholarships for college students|scholarships for college students in texas|2011 scholarships for college students|scholarships for college students in california|scholarships for college students 2011|easy scholarships for college students|grants and ss on July 8th, 2012 1:54 pm

    drug addiction is usually a menace to the society, it
    destroys lives and it destroys that the community

  5. grants for single mothers in florida on July 8th, 2012 3:21 pm

    Pretty nice post, thanks for the awesome article. Im having
    troubles subscribing to your internet websites feed. Thought Id let you know

  6. daycare assistance for single mothers on July 8th, 2012 3:50 pm

    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.

  7. cell phone lookup on July 8th, 2012 4:41 pm

    there isn’t any day in the month that i do not want to visit your blog.

  8. reverse cell phone lookup free with name on July 10th, 2012 4:19 am

    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.

  9. http://www.prlog.org/11306717-phone-number-lookup-is-your-partner-cheating-on-you.html on July 16th, 2012 12:27 pm

    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.

  10. reverse phone on July 16th, 2012 12:28 pm

    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

  11. http://www.prlog.org/11734629-phone-number-search-reverse-number-lookup.html on July 16th, 2012 12:46 pm

    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.

  12. cell phone number lookup on July 16th, 2012 1:52 pm

    Thanks for that the one of that the nicest internet sites i
    have read in the while.

  13. http://ezinearticles.com/?Free-Reverse-Phone-Lookup---Answer-To-The-Myth-About-Free-Cell-Phone-Number-Lookups&id=5986059 on July 16th, 2012 2:18 pm

    Where by have you found that the resource for the following post Awesome studying I have subscribed to your site feed.

  14. reverse phone lookup on July 16th, 2012 3:12 pm

    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.

  15. http://www.youtube.com/watch?v=c3-A_ZxBlSQ on July 16th, 2012 4:35 pm

    Utterly written subject material , Really enjoyed searching through .

  16. phone number lookup on July 16th, 2012 5:19 pm

    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.

  17. cell phone directory on July 16th, 2012 8:08 pm

    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.

  18. http://ezinearticles.com/?Cell-Phone-Number-Directories---Can-You-Use-It-to-Catch-a-Cheating-Partner?&id=5985845 on July 16th, 2012 8:12 pm

    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

  19. reverse address lookup on July 16th, 2012 8:43 pm

    I actually love that the approach you discuss this kind of topic.

  20. reverse phone lookup on July 16th, 2012 8:50 pm

    What’s up friends, nice article and fastidious arguments commented here, I am actually enjoying by these.

  21. reverse cell phone lookup on July 16th, 2012 10:06 pm

    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.

  22. people finder on July 17th, 2012 2:19 am

    It is rare knowledgeable folks for this topic, but
    you sound like theres more youre discussing!
    Thanks

  23. phone number search on July 17th, 2012 2:28 am

    i always look for golf courses with wellmaintained lawn
    and golf courses with very clean recreational area,,

  24. reverse phone number lookup on July 17th, 2012 2:29 am

    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.

  25. reverse phone lookup on July 18th, 2012 1:35 am

    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

  26. http://www.prlog.org/11261550-phone-number-lookup-catch-cheater-quickly.html on July 25th, 2012 1:51 am

    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!

  27. make money online on July 27th, 2012 6:23 am

    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!

  28. http://www.reversephonelookuped.com/ on August 5th, 2012 3:39 pm

    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.

  29. cell phone lookup on August 20th, 2012 8:34 am

    Strumming my pain with his fingers. Singing my life with his words.

    chantalmeNOTHIN