Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package recurs1;
- import java.util.*;
- public class j5 {
- public static void frac(int n, int s, double r, double rot, double xc, double yc)
- //r - для случая, когда s (кол-во сторон многоугольника) - нечетное
- {
- {
- double x[] = new double[s];
- double y[] = new double[s];
- for(int i = 0; i < s; i++){
- x[i] = xc + r*Math.cos(rot + 2*Math.PI*i/s);
- y[i] = yc + r*Math.sin(rot + 2*Math.PI*i/s);
- //System.out.printf("%f %f\n", x[i], y[i]);
- }
- StdDraw.filledPolygon(x, y);
- if(n != 1)
- {
- for(int j = 2; j <= n; j++)
- for(int i = 0; i < s; i++){
- 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);
- }
- }
- }
- }
- public static void frac(int n){
- frac(n, 6, .5/Math.pow(3, n-1), Math.PI*3/2, .5, .5);
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.print("n: ");
- int n = in.nextInt();
- frac(n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement