次の方法で共有


方法 : カーディナル スプラインを描画する

更新 : 2007 年 11 月

カーディナル スプラインとは、指定された一連の点を滑らかに結ぶ曲線のことです。カーディナル スプラインを描画するには、Graphics オブジェクトを作成し、点の配列のアドレスを DrawCurve メソッドに渡します。

鐘型のカーディナル スプラインの描画

  • 指定した 5 つの点を結ぶ鐘型のカーディナル スプラインを描画する例を次に示します。この曲線と 5 つの点を次の図に示します。

    カーディナル スプライン

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 メソッドを使用します。閉じたカーディナル スプラインの場合、曲線は配列内の最後の点と、配列内の最初の点を結びます。指定された 6 つの点を結ぶ、閉じたカーディナル スプラインを描画する例を次に示します。この閉じたスプラインと 6 つの点を次の図に示します。

カーディナル スプライン

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 メソッドにテンション引数を渡します。一連の同じ点を結ぶ 3 つのカーディナル スプラインを描画する例を次に示します。この 3 つのスプラインとそのテンション値を次の図に示します。テンションが 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 フォームと一緒に使用することが想定されていて、Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。

参照

その他の技術情報

直線、曲線、および図形

曲線の作成と描画