Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Koch {
- private static int startingn;
- // plot Koch curve of order n, with given step size
- private static double getArea(int n) {
- //Output Variable
- int output = 0;
- //Times the Koch Snowflake has progressed
- int timesran = startingn-n;
- //Amount of sides on the Koch Snowflake
- int sides = 3;
- //Number of bases for each traignle on each snowflake
- int s = 3;
- //The loop runs x amount of times per progressions in the snowflake.
- for(int i = 1; i <= timesran; i++) {
- //Calculating the area of each progression per triangle.
- if(i == 1) {
- output +=
- (Math.sqrt(3) * Math.pow(sides,2)) / 4;
- } else {
- sides = sides*4;
- output +=
- sides * ((Math.sqrt(3) * Math.pow((sides/s),2)) / 4);
- s = s*3;
- }
- }
- //Returning the total area.
- return output;
- }
- public static void main(String[] args) {
- startingn = 5;
- double step = 1.0 / Math.pow(3.0, startingn);
- System.out.println(getArea(3));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement