public static bool operator ==(Vector3d v0, Vector3d v1) { return (Tolerance.IsIgnorable(v0.X - v1.X) && Tolerance.IsIgnorable(v0.Y - v1.Y) && Tolerance.IsIgnorable(v0.Z - v1.Z)); }
public void Normalize() { var norm = Norm; if (Tolerance.IsIgnorable(norm)) { return; } X = X / norm; Y = Y / norm; }
/// <summary> /// 点が平面上に乗るかどうかを判定します /// </summary> /// <param name="point"></param> /// <returns>true -> 平面上に乗る, false -> 平面上に乗らない</returns> public bool IsOn(Vector3d point) { // 直線と平面との交点計算 var line = new Line(point, Normal); var intersection = line.GetIntersection(this); if (!intersection.HasValue) { return(false); } // 交点と入力点との距離計算 return(Tolerance.IsIgnorable((intersection.Value - point).Norm)); }
/// <summary> /// 点が多角形の境界or内部に含まれるかを判定します /// [契約] 点は多角形が成す平面上に乗ると前提します /// </summary> /// <param name="point">点</param> /// <returns></returns> public bool IsInOrOn(Vector3d point) { // 角度の総和法 // \sum_{i} theta_{i} = 2 \pi => in // \sum_{i} theta_{i} = 0 => out // Procedure // (1) 各頂点へのベクトルの計算 // (2) 各角度の計算 // (1) var vectors = new Vector3d[Points.Length]; for (var i = 0; i < Points.Length; ++i) { vectors[i] = Points[i] - point; if (Tolerance.IsIgnorable(vectors[i].Norm)) { return(true); } } // (2) // (r_{i} | r_{i + 1}) = |r_{i}| |r_{i + 1}| cos theta // theta は鋭角の方 var normal = this.Normal; var sumAngle = 0d; for (var i = 0; i < Points.Length; ++i) { var i_next = (i + 1) % Points.Length; var angle = Math.Acos( Vector3d.DotProduct(vectors[i], vectors[i_next]) / (vectors[i].Norm * vectors[i_next].Norm)); // vectors[ i ]×vectors[ i_next ] と normal の方向を比較し, // 鋭角となる向きが逆行するかどうかを判定 if (Vector3d.ScalarTripletProduct(normal, vectors[i], vectors[i_next]) < 0) { angle = -angle; } sumAngle += angle; } var isIn = sumAngle > Math.PI; return(isIn); }
// Norm( v1 )^{2} Norm( v2 )^{2} - (v1 | v2)^{2} が 0 なら平行 public bool AreParallel(Vector2d v) { return(Tolerance.IsIgnorable( (Norm * Norm) * (v.Norm * v.Norm) - DotProduct(this, v) * DotProduct(this, v))); }
// (v1 | v2) が 0 なら直角 public bool AreOrthogonal(Vector2d v) => Tolerance.IsIgnorable(DotProduct(this, v));
public static bool operator ==(Vector2d v0, Vector2d v1) => Tolerance.IsIgnorable(v0.X - v1.X) && Tolerance.IsIgnorable(v0.Y - v1.Y);