title: Why won't the right side of my recursive Sierpinski Triangle draw correctly?
body: <p>I'm writing a program in Java to make a Recursive Sierpinski Triangle, to the middle and left side of the triangle it draws recursively like a master-stroke.</p>
  <p>However, anything to do with the right side of the triangle simply will not draw.</p>
  <p>Here is some code, I'll explain how it works so you have an easier time reading it.</p>
  <p>The first thing it does is establish a height for the triangle in the height function.</p>
  <p>Height is called in filledTriangle which uses length as an argument (which is 1) and is then passed to a variable hei.</p>
  <p>I then use a simple set of coordinates.</p>
  <p>x0, x1, x2.
  y0 , y1, y2.</p>
  <p>After that I set up my midpoints, because all a midpoint in a Sierpinski Triangle is are the sum of 2 points divided by 2.</p>
  <p>After that, I pass my midpoints X and Y into an array, and voila , a triforce is made!</p>
  <p>So naturally, I attempt to create a recursive triangle for the left. The left works masterfully.</p>
  <p>Then I plug the arguments into the right and it simply doesn't work.</p>
  <pre><code>/*************************************************************************
   *  Compilation:  javac Sierpinski.java
   *  Execution:    java Sierpinski
   *
   *  @author:
   *
   *************************************************************************/
  
  public class Sierpinski {
  
      // Height of an equilateral triangle whose sides are of the specified length. 
      public static double height(double length) {
             return (Math.sqrt(3.0)*length)/2.0; 
      // WRITE YOUR CODE HERE
      }
  
  
      // Draws a filled equilateral triangle whose bottom vertex is (x, y) 
      // of the specified side length. 
      public static void filledTriangle(double x, double y, double length) {
      double hei = height(length); 
      
     
  
      double x0 = x-x; 
      double x1 = x;
      double x2 = x/2;
      double y0 = y;
      double y1 = y;
      double y2 = hei;  
      double ACx = (x0 + x1)/2; 
      double ACy = (y0 + y1)/2;  
      double BCx = (x1 + x2)/2; 
      double BCy = (y1 + y2)/2;
      double BAx = (x0 + x2)/2; 
      double BAy = (y0 + y2)/2; 
      double [] X ={ACx, BCx, BAx};
      double [] Y ={ACy, BCy, BAy};
      
      //Lines 39-42 Draw our main triangle. 
      StdDraw.line(x0,y0,x1,y1); 
      StdDraw.line(x0,y0,x2,y2); 
      StdDraw.line(x2,y2,x1,y1); 
      
      //This fills the triangles displaced by X and Y.. 
      //StdDraw.filledPolygon(X, Y);
      //StdDraw.line(BCx, BCy ,ACx ,ACy);
      //StdDraw.line(ACx, ACy, BAx, BAy);
      //StdDraw.line(BAx, BAy, BCx, BCy);
      StdDraw.filledPolygon(X,Y); 
      
      
      
       //WRITE YOUR CODE HERE
      }
  
      // Draws a Sierpinski triangle of order n, such that the largest filled 
      // triangle has bottom vertex (x, y) and sides of the specified length. 
      public static void sierpinski(int n, double x, double y, double length) { 
              filledTriangle(x, y, length); 
          if(n &lt;= 1)
              filledTriangle(x, y, length);
          else{
               //sierpinski(n--,x/2,y,length/2); 
               sierpinski(n--, x+x/2,y,length/2);
              //sierpinski(n--, x+0.5,y, length/2); 
              
          }
      // WRITE YOUR CODE HERE
      }
  
      // Takes an integer command-line argument n; 
      // draws the outline of an equilateral triangle (pointed upwards) of length 1; 
      // whose bottom-left vertex is (0, 0) and bottom-right vertex is (1, 0); and 
      // draws a Sierpinski triangle of order n that fits snugly inside the outline. 
      public static void main(String[] args) {
          //StdDraw.setScale(-1.5, +1.5);
          filledTriangle(1, 0, 1);
          sierpinski(Integer.parseInt(args[0]), 1, 0, 1);
          //sierpinski(Integer.parseInt(args[0]),1.0,1.0,1);
      // WRITE YOUR CODE HERE 
      }
  }
  
  </code></pre>
  <p>I commented out the left and top triangle to focus solely on the right, what I did for the right sierpinski Triangle was simply do x+x/2 for the x-coordinate.</p>
  <p>What I think the answerr should be for the right recursive side is : sierpinski(n--, x+x/2,y,length/2);</p>
  <p>I not only thought about this, but I wrote it down on paper, this should definitely work, but it just draws the leftest triangle from the (0,0) coordinate up to a strange height and the rightest triangle on some weird angle outside the bounds. The more I fidget with it, the more I realize that it isn't going to work and my math somewhere was off. But, I'm not sure where.</p>
  <p>Can anyone please assist?</p>