繪製基數曲線
基數曲線是一條曲線,可順利通過一組指定的點。 若要繪製基數曲線,請建立 Graphics 物件,並將點陣列的位址傳遞至 Graphics::D rawCurve 方法。 下列範例會繪製通過五個指定點的鐘形基數曲線:
Point points[] = {Point(0, 100),
Point(50, 80),
Point(100, 20),
Point(150, 80),
Point(200, 100)};
Pen pen(Color(255, 0, 0, 255));
graphics.DrawCurve(&pen, points, 5);
下圖顯示曲線和五點。
基數樣條通過五個點的一幅圖解
您可以使用 Graphics 類別的 Graphics::D rawClosedCurve 方法來繪製封閉的基數曲線。 在封閉的基數曲線中,曲線會繼續在陣列的最後一個點,並與陣列中的第一個點連接。
下列範例會繪製通過六個指定點的封閉基數曲線。
Point points[] = {Point(60, 60),
Point(150, 80),
Point(200, 40),
Point(180, 120),
Point(120, 100),
Point(80, 160)};
Pen pen(Color(255, 0, 0, 255));
graphics.DrawClosedCurve(&pen, points, 6);
下圖顯示封閉曲線以及六點:
您可以將張力參數傳遞至 Graphics::DrawCurve 方法,來變更基數曲線的彎曲方式。 下列範例會繪製三個通過相同點集的基數曲線:
Point points[] = {Point(20, 50),
Point(100, 10),
Point(200, 100),
Point(300, 50),
Point(400, 80)};
Pen pen(Color(255, 0, 0, 255));
graphics.DrawCurve(&pen, points, 5, 0.0f); // tension 0.0
graphics.DrawCurve(&pen, points, 5, 0.6f); // tension 0.6
graphics.DrawCurve(&pen, points, 5, 1.0f); // tension 1.0
下圖顯示三條曲線及其緊張值。 請注意,當緊張度為 0 時,點會以直線連接。