🔺
Fractal Graphics With OpenGL
  • Introduction
  • 저자 소개
  • Fractal에 대하여
  • 재귀적 프랙탈
  • 칸토어 먼지
  • 시어핀스키 양탄자
  • 코호 곡선
  • 코호섬
  • C곡선
  • 드래곤 곡선
  • 이진 나무
  • L-SYSTEM
  • L-SYSTEM 을 활용한 프랙탈
  • 부록 : 거북이 그래픽스의 이해
Powered by GitBook
On this page

Was this helpful?

코호섬

Previous코호 곡선NextC곡선

Last updated 5 years ago

Was this helpful?

코호 곡선으로 둘러 싸여진 폐곡선이 코호 섬이다. 코호 섬을 코호눈송이라고도 한다. 위 오른쪽은 차수가 5인 코호섬인데 차수가 무한대가 되면 어떻게 될까? 섬 외곽선의 길이가 무한대가 된다. 길이가 무한한 선이 유한한 면적을 둘러싸는 것이다. 무척이나 아리달쏭하다 ;] 시어핀스키 양탄자 및 가스켓이나 코호섬, 보통 사람들의 상식에는 벗어난다. 그래서 시어핀스키나 코호 모두 발표 당시에는 '맛이 조금 간 사람(?)' 으로 외면당했다. 이들을 구제해 준 사람이 만델브로트이고 이제는 그들은 시대를 앞서 갔던 사람으로 칭송받고 있다.

알고리즘

  1. 코호 곡선을 그린다.

  2. 오른쪽으로 120 도 회전하여 코호 곡선을 그린다.

  3. 오른쪽으로 120 도 회전하여 코호 곡선을 그린다.

위의 알고리즘을 코드로 표현하면 다음과 같다.

void RenderWindow::KochIsland(int n)
{
    KochCurve(n);
    turtle.Right(120); KochCurve(n);
    turtle.Right(120); KochCurve(n);
}

아래는 차수 3의 코호섬을 그린 결과와 전체 코드이다.

#include "lib\egl.h"
#include "turtle.h"

using namespace egl;

class RenderWindow : public Window
{
private:
    Turtle turtle;
public:
    void KochCurve(int n);
    void KochIsland(int n);
    virtual void RenderGLScene(void);
    virtual void OnSize(WPARAM wParam, LPARAM lParam);
};

void RenderWindow::KochCurve(int n)
{
    if(n==0)
    {
        turtle.Forward(1.0f);
    }
    else
    {
        KochCurve(n-1);
        turtle.Left(60); KochCurve(n-1);
        turtle.Right(120); KochCurve(n-1);
        turtle.Left(60); KochCurve(n-1);
    }
}

void RenderWindow::KochIsland(int n)
{
    KochCurve(n);
    turtle.Right(120); KochCurve(n);
    turtle.Right(120); KochCurve(n);
}

void RenderWindow::RenderGLScene(void)
{
    Window::RenderGLScene();

    glTranslatef(0.0f, 0.0f, -35.0f);

    turtle.SetStartPoint(-12.0f, 7.0f, 0.0f);
    KochIsland(3);
}

void RenderWindow::OnSize(WPARAM wParam, LPARAM lParam)
{
    GLsizei width = LOWORD(lParam);
    GLsizei height = HIWORD(lParam);

    if (height == 0)
        height = 1; 

    glViewport( 0, 0, width, height ); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 

    gluPerspective(54.0f, GLfloat(width)/GLfloat(height), 1.0f, 1000.0f);

    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    RenderWindow app;
    if(!app.Create(FALSE, "Fractal - Koch Island"))
        return EXIT_FAILURE;
    return app.Run();
}