Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1.  
  2. package recurs1;
  3.  
  4. import java.util.*;
  5.  
  6. public class j5 {
  7.    
  8.     public static void frac(int n, int s, double r, double rot, double xc, double yc)
  9.             //r - для случая, когда s (кол-во сторон многоугольника) - нечетное
  10.     {
  11.         {
  12.             double x[] = new double[s];
  13.             double y[] = new double[s];
  14.             for(int i = 0; i < s; i++){
  15.                 x[i] = xc + r*Math.cos(rot + 2*Math.PI*i/s);
  16.                 y[i] = yc + r*Math.sin(rot + 2*Math.PI*i/s);
  17.                 //System.out.printf("%f %f\n", x[i], y[i]);
  18.             }
  19.             StdDraw.filledPolygon(x, y);
  20.             if(n != 1)
  21.             {
  22.                 for(int j = 2; j <= n; j++)
  23.                     for(int i = 0; i < s; i++){
  24.                         frac(j-1, s, r, rot+Math.PI+Math.PI*i*2/s, (x[i]-xc)*2*Math.pow(3, j-2)+xc, (y[i]-yc)*2*Math.pow(3, j-2)+yc);
  25.                     }
  26.             }
  27.         }
  28.     }
  29.  
  30.     public static void frac(int n){
  31.         frac(n, 6, .5/Math.pow(3, n-1), Math.PI*3/2, .5, .5);
  32.     }
  33.    
  34.     public static void main(String[] args) {
  35.         Scanner in = new Scanner(System.in);
  36.         System.out.print("n: ");
  37.         int n = in.nextInt();
  38.         frac(n);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement