public SteinerPoint2D(Vector2D a, Vector2D b, int i) { ID = i; parent = new Vector2D[2]; parent[0] = a; parent[1] = b; }
public Vector2DCollection(Vector2D[] vectors, int capacity) { Capacity = capacity; CurrentCount = vectors.Length; if (Capacity < CurrentCount) { throw (new CollectionCapacityException()); } Vectors = vectors; }
public Vector2D(Vector2D v) : base(v) { }
/// <summary> /// Returns a normalized vector perpendicular to this vector. Equivalent to rotating this vector 90 degrees clockwise. /// </summary> /// <returns>A normalized vector perpendicular to this vector.</returns> public Vector2D UnitNormal() { Vector2D normal = new Vector2D(Y, -X); return normal.Normalize();; }
/// <summary> /// Rotates this vector counter-clockwise about the origin by <paramref name="radians"/> radians /// </summary> /// <param name="radians">Number of radians to rotate by</param> public Vector2D Rotate(double radians) { Vector2D v = new Vector2D(this); double cos = Math.Cos(radians); double sin = Math.Sin(radians); v.X = this.X * cos - this.Y * sin; v.Y = this.X * sin + this.Y * cos; return v; }
/// <summary> /// Returns the angle by rotate a around b. [0, 2pi) /// </summary> /// <param name="a">the first vector.</param> /// <param name="b">the second vector.</param> /// <returns>the angle.</returns> public static double RotateAngle(Vector2D a, Vector2D b) { double d = b.Arg - a.Arg; if (d < 0) { d += 2 * Math.PI; } return d; }
/// <summary> /// Returns the determinant of two vectors, that is, the determinant of the 2 x 2 matrix they form. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The determinant of <paramref name="a"/> and <paramref name="b"/>.</returns> public static double Determinant(Vector2D a, Vector2D b) { return a.X * b.Y - a.Y * b.X; }
/// <summary> /// Returns the cross product of two vectors. The cross product of the 2 2D vectors a and b is defined /// as the determinant of the 2 by 2 matrix (a, b) where the vectors are written in row or column order. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The cross product of <paramref name="a"/> and <paramref name="b"/>.</returns> public static Vector2D Cross(Vector2D a, Vector2D b) { return new Vector2D(a.X * b.Y , - a.Y * b.X); }
/// <summary> /// Returns the angle between two vectors. (-pi, pi] /// </summary> /// <param name="a">the first vector.</param> /// <param name="b">the second vector.</param> /// <returns>the angle.</returns> public static double Angle(Vector2D a, Vector2D b) { double d = b.Arg - a.Arg; if (d > Math.PI) { d -= 2 * Math.PI; } else if (d < -Math.PI) { d += 2 * Math.PI; } return d; }
public Matrix2D(Vector2D a, Vector2D b) : base(new Vector[]{(Vector)a, (Vector)b}) { }
private void Triangulation(int a, int b, int c) { Debug.Assert(a != b && b != c && c != a); Triangle2D triangle = new Triangle2D(this.polygon.GetPoint(a), this.polygon.GetPoint(b), this.polygon.GetPoint(c)); GhostTriangle2D ghost = new GhostTriangle2D(a, b, c); this.triangles.Add(triangle); this.ghostTriangles.Add(ghost); if (lineSegments.Count < polygon.VertexCount - 3) { Vector2D internalSegment = new Vector2D(a, c); LineSegment2D lineSegment = new LineSegment2D(this.polygon.GetPoint(a), this.polygon.GetPoint(c)); this.lineSegments.Add(lineSegment); this.internalSegments.Add(internalSegment); } }
public Vector2DCollection(Vector2D[] vectors) { Capacity = vectors.Length; Vectors = vectors; CurrentCount = Capacity; }
public void Union(Vector2DCollection vector2DCollection) { Capacity += vector2DCollection.Capacity; Vector2D[] vectors = new Vector2D[Capacity]; this.Vectors.CopyTo(vectors, 0); vector2DCollection.Vectors.CopyTo(vectors, this.Count); this.Vectors = vectors; CurrentCount += vector2DCollection.Count; }
public void Add(Vector2D vector) { try { base.Add(); } catch (CollectionCapacityException e) { string emsg = e.Message; this.Capacity *= 2; Vector2D[] vectors = new Vector2D[Capacity]; this.Vectors.CopyTo(vectors, 0); this.Vectors = vectors; base.Add(); } Vectors[CurrentCount - 1] = vector; }