摘要
-根据图形的定义,按照要求输出绘制图形中产生的点
原题目摘要
-

-

Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.

The Koch curve is well known as a kind of fractals.

You can draw a Koch curve in the following algorithm:

  • Divide a given segment (p1, p2) into three equal segments.
  • Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
  • Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
 0817 AOJ#Aizu ALDS1_5_C Koch Curve

You should start (0, 0), (100, 0) as the first segment.

Inputundefined

An integer n is given.

Outputundefined

Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.

Constraintsundefined

  • 0 ≤ n ≤ 6

Sample Input 1undefined

1

Sample Output 1undefined

0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000

Sample Input 2undefined

2

Sample Output 2undefined

0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000

题目理解
-使用递归的方式 进行一次操作,一次完整操作画出n=1的形状;计算过程中使用了向量的方式生成下个一点
注意
-三角函数计算的时候用的是弧度,使用的时候要换算,也不能使用整型变量
日期
-2017 08 17
附加
-
代码
-


1
#include <cstdio>
2
#include <algorithm>
3
#include <iostream>
4
#include <cstring>
5
#include <vector>
6
#include <stack>
7
#include <queue>
8
#include <list>
9
#include <set>
10
#include <map>
11
#include <memory>
12
#include <cmath>
13
using namespace std;
14
#define MAX 2003
15
16
int n;
17
struct Vector{
18
    double r;
19
    double theta;
20
    Vector operator *(double d){
21
        Vector t;
22
        t.r=r*d;
23
        t.theta=theta;
24
        return t;
25
    }
26
};
27
28
struct Point{
29
    double x,y;
30
    Point makeP (Vector v){
31
        Point t;
32
        t.x = x+v.r*cos(v.theta);
33
        t.y = y+v.r*sin(v.theta);
34
        return t;
35
    }
36
};
37
38
void showP(Point p){
39
    printf("%.8f %.8f\n",p.x,p.y);
40
}
41
42
double arc(double c){
43
    return (c/180)*3.1415926;
44
}
45
void koch(int depth,Point p,Vector v){
46
    if(depth==0){
47
        showP(p.makeP(v));
48
    }
49
    else{
50
        Vector v13;
51
        
52
        v13=v*(1.0/3);
53
        koch(depth-1,p,v13);//1
54
        
55
        p=p.makeP(v13);
56
        v13.theta+=arc(60);
57
        koch(depth-1,p,v13);//2
58
        
59
        
60
        p=p.makeP(v13);
61
        v13.theta-=arc(120);
62
        koch(depth-1,p,v13);//3
63
        
64
        
65
        p=p.makeP(v13);
66
        v13.theta+=arc(60);
67
        koch(depth-1,p,v13);//4
68
    }
69
}
70
71
72
void get_d(){
73
74
}
75
int main(){
76
 
77
    int t;
78
79
    scanf("%d",&t);
80
    
81
    Vector v;v.theta=0,v.r=100;
82
    Point p;p.x=0,p.y=0;
83
 
84
    showP(p);
85
    koch(t,p,v);
86
   return 0;
87
}

相关文章:

  • 2021-08-12
  • 2021-12-20
  • 2021-03-31
  • 2021-07-18
  • 2021-09-11
  • 2021-08-13
  • 2022-01-01
猜你喜欢
  • 2021-10-08
  • 2021-06-01
  • 2021-07-19
  • 2021-08-26
  • 2021-07-23
  • 2022-01-03
  • 2021-12-12
相关资源
相似解决方案