갈루아의 반서재

728x90

1. 원 그리기

원을 그리는 간단한 R 함수는 없다.

아래는 다각형을 가지고 대략적으로 원을 그리는 방법이다.

 

> plot.new()

> plot.window(xlim=c(-1.1,1.1), ylim=c(-1.1,1.1), asp=1)

> theta=seq(0,2*pi, length=72) // 180° = π, 2π 즉, 360° 를 72 로 나눈 것이므로 Change of angle = 5° 

> x=cos(theta)

> y=sin(theta)

> lines(x,y)

 

 

 

 

 

위의 그림에서 c = 1 이라고 하면,

좌표 X = (a,b) = (a/1, b/1) = (cosA, sinA) 가 된다.

 

theta = seq(0,2*pi, length=72) 의 간격대로 해당 값들을 구해보면 아래와 같다.

아래와 같은 72개의 점을 이은 셈이되는 것이다.

 

#

theta=seq(0,2*pi, length=72)

cos(theta)

sin(theta)

0

0

1.0000

0.0000

1

0.087266463

0.9962

0.0872

2

0.174532925

0.9848

0.1736

3

0.261799388

0.9659

0.2588

4

0.34906585

0.9397

0.3420

5

0.436332313

0.9063

0.4226

6

0.523598776

0.8660

0.5000

7

0.610865238

0.8192

0.5736

8

0.698131701

0.7660

0.6428

9

0.785398163

0.7071

0.7071

10

0.872664626

0.6428

0.7660

11

0.959931089

0.5736

0.8192

12

1.047197551

0.5000

0.8660

13

1.134464014

0.4226

0.9063

14

1.221730476

0.3420

0.9397

15

1.308996939

0.2588

0.9659

16

1.396263402

0.1736

0.9848

17

1.483529864

0.0872

0.9962

18

1.570796327

0.0000

1.0000

19

1.658062789

-0.0872

0.9962

20

1.745329252

-0.1736

0.9848

21

1.832595715

-0.2588

0.9659

22

1.919862177

-0.3420

0.9397

23

2.00712864

-0.4226

0.9063

24

2.094395102

-0.5000

0.8660

25

2.181661565

-0.5736

0.8192

26

2.268928028

-0.6428

0.7660

27

2.35619449

-0.7071

0.7071

28

2.443460953

-0.7660

0.6428

29

2.530727415

-0.8192

0.5736

30

2.617993878

-0.8660

0.5000

31

2.705260341

-0.9063

0.4226

32

2.792526803

-0.9397

0.3420

33

2.879793266

-0.9659

0.2588

34

2.967059728

-0.9848

0.1736

35

3.054326191

-0.9962

0.0872

36

3.141592654

-1.0000

0.0000

37

3.228859116

-0.9962

-0.0872

38

3.316125579

-0.9848

-0.1736

39

3.403392041

-0.9659

-0.2588

40

3.490658504

-0.9397

-0.3420

41

3.577924967

-0.9063

-0.4226

42

3.665191429

-0.8660

-0.5000

43

3.752457892

-0.8192

-0.5736

44

3.839724354

-0.7660

-0.6428

45

3.926990817

-0.7071

-0.7071

46

4.01425728

-0.6428

-0.7660

47

4.101523742

-0.5736

-0.8192

48

4.188790205

-0.5000

-0.8660

49

4.276056667

-0.4226

-0.9063

50

4.36332313

-0.3420

-0.9397

51

4.450589593

-0.2588

-0.9659

52

4.537856055

-0.1736

-0.9848

53

4.625122518

-0.0872

-0.9962

54

4.71238898

0.0000

-1.0000

55

4.799655443

0.0872

-0.9962

56

4.886921906

0.1736

-0.9848

57

4.974188368

0.2588

-0.9659

58

5.061454831

0.3420

-0.9397

59

5.148721293

0.4226

-0.9063

60

5.235987756

0.5000

-0.8660

61

5.323254219

0.5736

-0.8192

62

5.410520681

0.6428

-0.7660

63

5.497787144

0.7071

-0.7071

64

5.585053606

0.7660

-0.6428

65

5.672320069

0.8192

-0.5736

66

5.759586532

0.8660

-0.5000

67

5.846852994

0.9063

-0.4226

68

5.934119457

0.9397

-0.3420

69

6.021385919

0.9659

-0.2588

70

6.108652382

0.9848

-0.1736

71

6.195918845

0.9962

-0.0872

72

6.283185307

1.0000

0.0000

 

 

#

theta=seq(0,2*pi, length=72)

cos(theta)

sin(theta)

0

0

1.0000

0.0000

1

0.087266463

0.9962

0.0872

2

0.174532925

0.9848

0.1736

3

0.261799388

0.9659

0.2588

4

0.34906585

0.9397

0.3420

5

0.436332313

0.9063

0.4226

6

0.523598776

0.8660

0.5000

7

0.610865238

0.8192

0.5736

8

0.698131701

0.7660

0.6428

9

0.785398163

0.7071

0.7071

10

0.872664626

0.6428

0.7660

11

0.959931089

0.5736

0.8192

12

1.047197551

0.5000

0.8660

13

1.134464014

0.4226

0.9063

14

1.221730476

0.3420

0.9397

15

1.308996939

0.2588

0.9659

16

1.396263402

0.1736

0.9848

17

1.483529864

0.0872

0.9962

18

1.570796327

0.0000

1.0000

19

1.658062789

-0.0872

0.9962

20

1.745329252

-0.1736

0.9848

21

1.832595715

-0.2588

0.9659

22

1.919862177

-0.3420

0.9397

23

2.00712864

-0.4226

0.9063

24

2.094395102

-0.5000

0.8660

25

2.181661565

-0.5736

0.8192

26

2.268928028

-0.6428

0.7660

27

2.35619449

-0.7071

0.7071

28

2.443460953

-0.7660

0.6428

29

2.530727415

-0.8192

0.5736

30

2.617993878

-0.8660

0.5000

31

2.705260341

-0.9063

0.4226

32

2.792526803

-0.9397

0.3420

33

2.879793266

-0.9659

0.2588

34

2.967059728

-0.9848

0.1736

35

3.054326191

-0.9962

0.0872

36

3.141592654

-1.0000

0.0000

37

3.228859116

-0.9962

-0.0872

38

3.316125579

-0.9848

-0.1736

39

3.403392041

-0.9659

-0.2588

40

3.490658504

-0.9397

-0.3420

41

3.577924967

-0.9063

-0.4226

42

3.665191429

-0.8660

-0.5000

43

3.752457892

-0.8192

-0.5736

44

3.839724354

-0.7660

-0.6428

45

3.926990817

-0.7071

-0.7071

46

4.01425728

-0.6428

-0.7660

47

4.101523742

-0.5736

-0.8192

48

4.188790205

-0.5000

-0.8660

49

4.276056667

-0.4226

-0.9063

50

4.36332313

-0.3420

-0.9397

51

4.450589593

-0.2588

-0.9659

52

4.537856055

-0.1736

-0.9848

53

4.625122518

-0.0872

-0.9962

54

4.71238898

0.0000

-1.0000

55

4.799655443

0.0872

-0.9962

56

4.886921906

0.1736

-0.9848

57

4.974188368

0.2588

-0.9659

58

5.061454831

0.3420

-0.9397

59

5.148721293

0.4226

-0.9063

60

5.235987756

0.5000

-0.8660

61

5.323254219

0.5736

-0.8192

62

5.410520681

0.6428

-0.7660

63

5.497787144

0.7071

-0.7071

64

5.585053606

0.7660

-0.6428

65

5.672320069

0.8192

-0.5736

66

5.759586532

0.8660

-0.5000

67

5.846852994

0.9063

-0.4226

68

5.934119457

0.9397

-0.3420

69

6.021385919

0.9659

-0.2588

70

6.108652382

0.9848

-0.1736

71

6.195918845

0.9962

-0.0872

72

6.283185307

1.0000

0.0000

 

 

 

 

2. 또 다른 예제

 

 

> x1 = seq(0, 1, length = 20)

> y1 = rep(0, 20) // 0 을 20번 반복

> x2 = rep(0, 20)

> y2 = seq(0.75, 0, length = 20)

> plot.new()

> plot.window(xlim = c(0, 1), ylim = c(0,0.75), asp = 1)

> segments(x1, y1, x2, y2) // (x1, y1) 에서 (x2, y2) 로 선 긋기

 

 

from

to

 

x1

y1

x2

y2

0

0.00

0

0

0.750

1

0.05

0

0

0.713

2

0.10

0

0

0.675

3

0.15

0

0

0.638

4

0.20

0

0

0.600

5

0.25

0

0

0.563

6

0.30

0

0

0.525

7

0.35

0

0

0.488

8

0.40

0

0

0.450

9

0.45

0

0

0.413

10

0.50

0

0

0.375

11

0.55

0

0

0.338

12

0.60

0

0

0.300

13

0.65

0

0

0.263

14

0.70

0

0

0.225

15

0.75

0

0

0.188

16

0.80

0

0

0.150

17

0.85

0

0

0.113

18

0.90

0

0

0.075

19

0.95

0

0

0.038

20

1.00

0

0

0.000

 

 

 

from

to

 

x1

y1

x2

y2

0

0.00

0

0

0.750

1

0.05

0

0

0.713

2

0.10

0

0

0.675

3

0.15

0

0

0.638

4

0.20

0

0

0.600

5

0.25

0

0

0.563

6

0.30

0

0

0.525

7

0.35

0

0

0.488

8

0.40

0

0

0.450

9

0.45

0

0

0.413

10

0.50

0

0

0.375

11

0.55

0

0

0.338

12

0.60

0

0

0.300

13

0.65

0

0

0.263

14

0.70

0

0

0.225

15

0.75

0

0

0.188

16

0.80

0

0

0.150

17

0.85

0

0

0.113

18

0.90

0

0

0.075

19

0.95

0

0

0.038

20

1.00

0

0

0.000

 

 

728x90