다음을 통해 공유


방법: 카디널 스플라인 그리기

카디널 스플라인은 주어진 점의 집합을 매끄럽게 통과하며 그려지는 곡선입니다. 카디널 스플라인을 그리려면 Graphics 개체를 만들고 점 배열의 주소를 DrawCurve 메서드에 전달합니다.

종 모양 카디널 스플라인 그리기

  • 다음 예제에서는 지정된 다섯 개의 점을 통과하는 종 모양의 카디널 스플라인을 그립니다. 아래 그림에서는 곡선과 다섯 개의 점을 보여 줍니다.

    카디널 스플라인

        Dim points As Point() = { _
           New Point(0, 100), _
           New Point(50, 80), _
           New Point(100, 20), _
           New Point(150, 80), _
           New Point(200, 100)}

        Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
        e.Graphics.DrawCurve(pen, points)

Point[] points = {
   new Point(0, 100),
   new Point(50, 80),
   new Point(100, 20),
   new Point(150, 80),
   new Point(200, 100)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points);

닫힌 카디널 스플라인 그리기

  • Graphics 클래스의 DrawClosedCurve 메서드를 사용하여 닫힌 카디널 스플라인을 그립니다. 닫힌 카디널 스플라인에서는 곡선이 배열의 마지막 점을 지나 배열의 첫 번째 점으로 다시 연결됩니다. 다음 예제에서는 지정된 여섯 개의 점을 통과하는 닫힌 카디널 스플라인을 그립니다. 아래 그림에서는 여섯 개의 점을 따라 그려진 닫힌 스플라인을 보여 줍니다.

카디널 스플라인

        Dim points As Point() = { _
           New Point(60, 60), _
           New Point(150, 80), _
           New Point(200, 40), _
           New Point(180, 120), _
           New Point(120, 100), _
           New Point(80, 160)}

        Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
        e.Graphics.DrawClosedCurve(pen, points)

Point[] points = {
   new Point(60, 60),
   new Point(150, 80),
   new Point(200, 40),
   new Point(180, 120),
   new Point(120, 100),
   new Point(80, 160)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawClosedCurve(pen, points);

카디널 스플라인의 굴곡 변경

  • 장력 인수를 DrawCurve 메서드에 전달하여 카디널 스플라인의 굴곡 정도를 변경합니다. 다음 예제에서는 동일한 점 집합을 통과하는 세 개의 카디널 스플라인을 그립니다. 아래 그림에서는 세 가지 스플라인 및 각각의 장력 값을 보여 줍니다. 장력 값이 0이면 점은 직선으로 연결됩니다.

카디널 스플라인

        Dim points As Point() = { _
           New Point(20, 50), _
           New Point(100, 10), _
           New Point(200, 100), _
           New Point(300, 50), _
           New Point(400, 80)}

        Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
        e.Graphics.DrawCurve(pen, points, 0.0F)
        e.Graphics.DrawCurve(pen, points, 0.6F)
        e.Graphics.DrawCurve(pen, points, 1.0F)

Point[] points = {
   new Point(20, 50),
   new Point(100, 10),
   new Point(200, 100),
   new Point(300, 50),
   new Point(400, 80)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points, 0.0f);
e.Graphics.DrawCurve(pen, points, 0.6f);
e.Graphics.DrawCurve(pen, points, 1.0f);

코드 컴파일

앞의 예제는 Windows Forms에서 사용해야 하며 Paint 이벤트 처리기의 매개 변수인 PaintEventArgs e를 필요로 합니다.

참고 항목

기타 리소스

선, 곡선 및 도형

곡선 구성 및 그리기