Variant of the Sierpinski curves in C++; help

  • Comp Sci
  • Thread starter John O' Meara
  • Start date
  • Tags
    Curves
In summary: Here's some pseudocode that might help you get started:```In summary, the Sierpinski curve can be drawn using a simple recursive formula. A 0th order curve is a straight line, while higher order curves are made up of 3 lower-order curves arranged in an "L" shape. To draw a curve of any order, keep track of the current order and draw the appropriate number of lower-order curves in the correct orientation.
  • #1
John O' Meara
330
0
Code:
using namespace std;

enum direction {north, east, south, west };

direction right(direction d)
{ // return the direction to the right (clockwise)
  switch(d) {
    case north:  return east;
    case east:   return south;
    case south: return west;
    case west:  return north;
   }
}

ostream& operator<<(ostream& c, direction d)
{ // write a direction
  switch(d) {
    case north:   c << "north"; break;
    case east:     c << " east"; break;
    case south:   c << "south"; break;
    case west:    c << " west"; break;
   }
}

void edge(direction d, int i);
direction left(direction d);

void Sierpinski(int i)
{ // Draw Sierpinski curve of order i
  direction d = north;
  do {
    edge(d, i);
    d = right(d);
  }while(d != north);
}

direction left(direction d, int i)
{ // Return direction to the left (counterclockwise)
  switch(d) {
    case north:    return west;
    case east:     return north;
    case south:   return east;
    case west:    return south;
   }
}

void edge(direction d, int i)
{
   if(i == -1)
       cout << d << " 2 cm\n";
   else {
       edge(left(d), i-1);
       edge(d, i-1);
       edge(right(d), i-1);
   }
}

int main()
{
   Sierpinski(1);

   return 0;
}
The question is question 3 in the attachment. The program above for a first order curve Sierpinski(1); it "draws" a zero order curve and then overwirtes that cross shape three times. I cannot get it to draw the first order or higher order curves. Because the only other symmetry I can see in the zero order curve is central symmetry in the center of the cross. I don't know how to break the zero order curve down to simplier components, than north, south, east and west directions? Looking at the attachment is the only way you are going to know what I am talking about, there are drawings of zero, first, second and third order curves. Thanks for the help in advance.
 

Attachments

  • Scan_Doc0006.pdf
    1.4 MB · Views: 217
Physics news on Phys.org
  • #2
Sorry for the long question. ![enter image description here][1] [1]: https://i.stack.imgur.com/W5aXF.png</code>I am trying to make a program that will draw a Sierpinski curve of any order. The program I have written can only draw the zero order curve. Here is my code. A:The Sierpinski curve is defined by a simple recursive formula. You can look at it like this:A 0th order curve is just a straight line.A 1st order curve is made up of 3 0th order curves, arranged in an "L" shape.A 2nd order curve is made up of 3 1st order curves, arranged in an "L" shape.A 3rd order curve is made up of 3 2nd order curves, arranged in an "L" shape.etc.So, all you need to do is keep track of what order you're drawing, and draw the appropriate number of lower-order curves in the right orientation.
 

Related to Variant of the Sierpinski curves in C++; help

1. What is a variant of the Sierpinski curve?

A variant of the Sierpinski curve is a fractal pattern that is based on the Sierpinski triangle, but with some modifications to its construction or iterations. It is a self-similar and infinitely repeating pattern that is commonly used in computer graphics and programming.

2. How is the Sierpinski curve constructed in C++?

The Sierpinski curve can be constructed in C++ using a recursive algorithm. This involves dividing a triangle into smaller triangles and repeating this process on each smaller triangle until the desired level of detail is achieved. The code for this can vary depending on the specific variant of the curve being created.

3. What is the benefit of using a variant of the Sierpinski curve in C++?

Using a variant of the Sierpinski curve in C++ can have several benefits. It allows for the creation of visually interesting and complex patterns with relatively simple code. It also helps with understanding recursion and fractal geometry, which are important concepts in computer science.

4. Are there any limitations to creating a variant of the Sierpinski curve in C++?

As with any programming task, there can be limitations when creating a variant of the Sierpinski curve in C++. Some limitations may include the amount of memory and processing power available, as well as the specific capabilities of the programming language being used.

5. Can I modify the code for a variant of the Sierpinski curve in C++?

Yes, the code for a variant of the Sierpinski curve in C++ can be modified to create different variations of the pattern. You can experiment with changing the number of iterations, the size and shape of the initial triangle, and other parameters to create unique and interesting variations of the curve.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
925
  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
979
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
4
Views
718
Back
Top