Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6942945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:05:30+00:00 2026-05-27T13:05:30+00:00

I’m doing a program for a recursive Sierpinski triangle and do not know how

  • 0

I’m doing a program for a recursive Sierpinski triangle and do not know how to change the points in arrays xm[] and ym[] in order to do this. to be more specific, when i run this program, only one outlined triangle with one blue inner triangle is drawn. any help would be greatly appreciated!

public class recursiveSierpinski {
   public static void draw(int n, double x0, double y0, double x1,
      double y1, double x2, double y2) {
      // if reach base case, method return
      if (n==0) return;
      // define array xm, ym to store x and y values of midpoints
      double [] xm = new double[3];
      double [] ym = new double[3];

      // assign midpoints’ values to xm and ym
      xm[0]= (x0+x1)/2;
      xm[1]= (x1+x2)/2;
      xm[2]= (x2+x0)/2;
      ym[0]= (y0+y1)/2;
      ym[1]= (y1+y2)/2;
      ym[2]= (y2+y0)/2;

      StdDraw.setPenColor(StdDraw.BLUE);
      StdDraw.filledPolygon(xm, ym); //this makes triangle
      xm[0]=xm[0]/2.0;
      ym[0]=ym[0]/2.0;
      xm[1]=xm[1]/2.0;
      ym[1]=ym[1]/2.0;
      xm[2]=xm[2]/2.0;
      ym[2]=ym[2]/2.0;

      draw(n,xm[0],ym[0],xm[1],ym[1],xm[2],ym[2]);
      draw(n,xm[1],ym[1],xm[2],ym[2],xm[0],ym[0]);
      draw(n,xm[2],ym[2],xm[0],ym[0],xm[1],ym[1]);

      // recursively draw the sub triangles (?)


     }
     public static void main(String[] args) {
     // N levels of recursion
     int N = Integer.parseInt(args[0]);
     // outline the triangle
     double t = Math.sqrt(3.0) / 2.0;
     StdDraw.line(0.0, 0.0, 1.0, 0.0);
     StdDraw.line(1.0, 0.0, 0.5, t);
     StdDraw.line(0.5, t, 0.0, 0.0);
     draw(N, 0.0, 0.0, 0.5, t, 1.0, 0.0);
     }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:05:31+00:00Added an answer on May 27, 2026 at 1:05 pm

    Try this:

    public class recursiveSierpinski {
       public static void draw(int n, double x0, double y0, double x1,
          double y1, double x2, double y2) {
          // if reach base case, method return
          if (n==0) return;
          // define array xm, ym to store x and y values of midpoints
          double [] xm = new double[3];
          double [] ym = new double[3];
    
          // assign midpoints’ values to xm and ym
          xm[0]= (x0+x1)/2;
          xm[1]= (x1+x2)/2;
          xm[2]= (x2+x0)/2;
          ym[0]= (y0+y1)/2;
          ym[1]= (y1+y2)/2;
          ym[2]= (y2+y0)/2;
    
          StdDraw.filledPolygon(xm, ym); //this makes triangle
    
          draw(n-1,xm[0],ym[0],xm[1],ym[1],x1,y1);
          draw(n-1,xm[1],ym[1],xm[2],ym[2],x2,y2);
          draw(n-1,xm[2],ym[2],xm[0],ym[0],x0,y0);
    
    
         }
         public static void main(String[] args) {
         // N levels of recursion
         int N = Integer.parseInt(args[0]);
         // outline the triangle
    
         double t = Math.sqrt(3.0) / 2.0;
    
    
         StdDraw.setPenColor(StdDraw.BLACK);
         // fill arrays initially to draw black solid TRIANGLE xm, ym = 0.0, 0.0, 0.5, t, 1.0, 0.0
         StdDraw.filledPolygon(xm, ym);
    
         StdDraw.setPenColor(StdDraw.WHITE);
         draw(N, 0.0, 0.0, 0.5, t, 1.0, 0.0);
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.