平面
空間にある平面
空間内にある平面を Microsoft.Xna.Framework.Plane 構造体で表すことができます。
[TypeConverterAttribute("typeof(Microsoft.Xna.Framework.Design.PlaneConverter)")] [SerializableAttribute] public struct Plane : IEquatable<Plane>
平面は法線ベクトル(面に対して垂直なベクトル)と面までの距離で表します。これらの値はオーバーロードされているコンストラクタから設定できます。
public Plane (float a, float b, float c, float d)
public Plane (Vector3 normal, float d)
public Plane (Vector4 value)
public Plane (Vector3 point1, Vector3 point2, Vector3 point3)
a パラメータ、b パラメータ c パラメータには順に法線の X 要素、Y 要素、Z 要素を指定します。または Vector3 型の normal パラメータに法線ベクトルを直接指定することもできます。d パラメータは原点から法線に沿った面までの距離を指定します。Vector4 型の value パラメータは、法線ベクトルを X 要素、Y 要素、Z 要素で表し、面までの距離を W 要素で表します。
3 つの Vector3 型の値を受けるコンストラクタは三角形から平面を割り出します。point1 パラメータ、point2 パラメータ、point3 パラメータには、それぞれ三角形の頂点座標を指定します。ポリゴンから平面を得るときに便利です。
法線ベクトルに沿った面までの距離は負で表される値です。例えば、原点から Z 軸に向かって距離 1 にある平面は、法線ベクトル (0, 0, 1) と距離 -1 で表します。もしくは法線ベクトル (0, 0, -1) と距離 1 でも同じです。
using System.Diagnostics; using Microsoft.Xna.Framework; public class TestGame : Game { public static void Main(string[] args) { Vector4 value = new Vector4(0, 0, -1, 3); Vector3 point1 = new Vector3(0, 1, 2); Vector3 point2 = new Vector3(1, -1, 2); Vector3 point3 = new Vector3(-1, -1, 2); Plane plane1 = new Plane(); Plane plane2 = new Plane(1, 0, 0, 10); Plane plane3 = new Plane(Vector3.Up, 5); Plane plane4 = new Plane(value); Plane plane5 = new Plane(point1, point2, point3); Debug.WriteLine("plane1=" + plane1); Debug.WriteLine("plane2=" + plane2); Debug.WriteLine("plane3=" + plane3); Debug.WriteLine("plane4=" + plane4); Debug.WriteLine("plane5=" + plane5); } }
コード1は Plane 構造体の各種コンストラクタで初期化した平面の値を出力しています。
平面の法線ベクトルは Normal フィールドから、距離は D フィールドから設定または取得できます。
public Vector3 Normal
public float D
平面は、これらのフィールドを通して任意で変更できます。
using System.Diagnostics; using Microsoft.Xna.Framework; public class TestGame : Game { public static void Main(string[] args) { Plane plane = new Plane(); plane.Normal = new Vector3(0, 0, 1); plane.D = -1; Debug.WriteLine("Normal=" + plane.Normal + ", Distance=" + plane.D); } }
コード2は平面の法線ベクトルと距離をフィールドから設定しています。