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!
Case Study 3: Sierpinski Triangle A fractal is a geometric object that is self-similar. That is,...
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...