Question

Case Study 3: Sierpinski Triangle A fractal is a geometric object that is self-similar. That is, if you zoom in on the object, it retains the same appearance or structure. One such fractal is the Sierpinski Triangle which is formed by drawinga triangle and removing an internal triangle drawn by connecting the midpoints of the outer triangles sides. This process is repeated recursively ad infinitum. This process is illustrated for the first four iterations in the figure below. Figure 1Sierpinski Triangle, 4 iterations A Java applet has been provided to you (unl.cse.recursion.SierpinskiTriangle) that recursively draws the Sierpinski Triangle for a specified number of recursive iterations. Since this is an applet, you can run it without having a main method. The depth of the recursion is specified in the paint method. It will be your task to modify this program to count the total number of triangles that a recursion of depth n will ultimately render.
media%2Fef9%2Fef9caeb7-c10d-4abd-a976-8d
0 0
Add a comment Improve this question Transcribed image text
Answer #1
int countTriangles(int depth) {
    if(depth == 0) {
        // 0 depth has only one triangle
        return 1;
    } else {
        // 1 Single triangle, results in 4 triangle
        // Out of those 4 triangles, the corner 3
        // triangles are
        // recursively broke into other triangles.
        return 1 + 3 * countTriangles(depth - 1);
    }
}

Hi. please find the answer above.. i have given comments so that it is very easy for you to understand the flow. In case of any doubts, please ask in comments. If the answer helps you, please upvote. Thanks!

Add a comment
Know the answer?
Add Answer to:
Case Study 3: Sierpinski Triangle A fractal is a geometric object that is self-similar. That is,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we...

    One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we will look at ways in which we can model geometric objects comprised of polygons. Here, we want to examine the interactive part. Let’s start by writing an application that will let the user specify a series of axis- aligned rectangles interactively. Each rectangle can be defined by two mouse positions at diagonally opposite corners. Consider the event listener canvas.addEventListener("mousedown", function() { gl.bindBuffer(gl.ARRAY_BUFFER, vBuffer); if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT