Exemplo n.º 1
0
        /// <summary>
        /// AngleBetween - the angle between 2 vectors
        /// </summary>
        /// <returns>
        /// Returns the the angle in degrees between vector1 and vector2
        /// </returns>
        /// <param name="vector1"> The first Vector </param>
        /// <param name="vector2"> The second Vector </param>
        public static double AngleBetween(Vector vector1, Vector vector2)
        {
            double sin = vector1._x * vector2._y - vector2._x * vector1._y;
            double cos = vector1._x * vector2._x + vector1._y * vector2._y;

            return Math.Atan2(sin, cos) * (180 / Math.PI);
        }
Exemplo n.º 2
0
 public static bool IsCCW(Point pt1, Point pt2, Point pt3)
 {
     Vector V21 = new Vector(pt2, pt1);
     Vector v23 = new Vector(pt2, pt3);
     return CrossProduct(V21, v23) > 0;  // sin(angle pt2 pt1 pt3) < 0, 180<angle pt2 pt1 pt3 <360
 }
Exemplo n.º 3
0
 public static bool IsClockwise(Point pt1, Point pt2, Point pt3)
 {
     Vector V21 = new Vector(pt2, pt1);
     Vector v23 = new Vector(pt2, pt3);
     return CrossProduct(V21, v23) < 0; // sin(angle pt1 pt2 pt3) > 0, 0<angle pt1 pt2 pt3 <180
 }
Exemplo n.º 4
0
 /// <summary>
 /// Equals - compares this Vector with the passed in object.  In this equality
 /// Double.NaN is equal to itself, unlike in numeric equality.
 /// Note that double values can acquire error when operated upon, such that
 /// an exact comparison between two values which
 /// are logically equal may fail.
 /// </summary>
 /// <returns>
 /// bool - true if "value" is equal to "this".
 /// </returns>
 /// <param name='value'>The Vector to compare to "this"</param>
 public bool Equals(Vector value)
 {
     return Vector.Equals(this, value);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Compares two Vector instances for object equality.  In this equality
 /// Double.NaN is equal to itself, unlike in numeric equality.
 /// Note that double values can acquire error when operated upon, such that
 /// an exact comparison between two values which
 /// are logically equal may fail.
 /// </summary>
 /// <returns>
 /// bool - true if the two Vector instances are exactly equal, false otherwise
 /// </returns>
 /// <param name='vector1'>The first Vector to compare</param>
 /// <param name='vector2'>The second Vector to compare</param>
 public static bool Equals(Vector vector1, Vector vector2)
 {
     return vector1.X.Equals(vector2.X) &&
     vector1.Y.Equals(vector2.Y);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Subtract: Point - Vector
 /// </summary>
 /// <returns>
 /// Point - The result of the subtraction
 /// </returns>
 /// <param name="point"> The Point from which the Vector is subtracted </param>
 /// <param name="vector"> The Vector which is subtracted from the Point </param>
 public static Point Subtract(Point point, Vector vector)
 {
     return new Point(point._x - vector._x, point._y - vector._y);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Offset - return the result of offsetting rect by the offset provided
 /// If this is Empty, this method is illegal.
 /// </summary>
 public static Rect Offset(Rect rect, Vector offsetVector)
 {
     rect.Offset(offsetVector.X, offsetVector.Y);
     return rect;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Multiply: double * Vector
 /// </summary>
 public static Vector Multiply(double scalar, Vector vector)
 {
     return new Vector(vector._x * scalar,
     vector._y * scalar);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Multiply: Vector / double
 /// </summary>
 public static Vector Divide(Vector vector, double scalar)
 {
     return vector * (1.0 / scalar);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Subtract: Vector - Vector
 /// </summary>
 public static Vector Subtract(Vector vector1, Vector vector2)
 {
     return new Vector(vector1._x - vector2._x,
     vector1._y - vector2._y);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Add: Vector + Point
 /// </summary>
 public static Point Add(Vector vector, Point point)
 {
     return new Point(point._x + vector._x, point._y + vector._y);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Add: Vector + Vector
 /// </summary>
 public static Vector Add(Vector vector1, Vector vector2)
 {
     return new Vector(vector1._x + vector2._x,
     vector1._y + vector2._y);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Transform - Transforms each Vector in the array by this matrix.
 /// </summary>
 /// <param name="vectors"> The Vector array to transform </param>
 public void Transform(Vector[] vectors)
 {
     if (vectors != null)
     {
         for (int i = 0; i < vectors.Length; i++)
         {
             MultiplyVector(ref vectors[i]._x, ref vectors[i]._y);
         }
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Transform - returns the result of transforming the Vector by this matrix.
 /// </summary>
 /// <returns>
 /// The transformed vector
 /// </returns>
 /// <param name="vector"> The Vector to transform </param>
 public Vector Transform(Vector vector)
 {
     Vector newVector = vector;
     MultiplyVector(ref newVector._x, ref newVector._y);
     return newVector;
 }
Exemplo n.º 15
0
 public static double DistancePointLine(Point pt, Point lnA, Point lnB)
 {
     Vector v1 = new Vector(lnA, lnB);
     Vector v2 = new Vector(lnA, pt);
     v1.Normalize();
     return Math.Abs(CrossProduct(v2, v1));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Multiply: Vector * Matrix
 /// </summary>
 public static Vector Multiply(Vector vector, Matrix matrix)
 {
     return matrix.Transform(vector);
 }
Exemplo n.º 17
0
 /// <summary>
 /// CrossProduct - Returns the cross product: vector1.X*vector2.Y - vector1.Y*vector2.X
 /// </summary>
 /// <returns>
 /// Returns the cross product: vector1.X*vector2.Y - vector1.Y*vector2.X
 /// </returns>
 /// <param name="vector1"> The first Vector </param>
 /// <param name="vector2"> The second Vector </param>
 public static double CrossProduct(Vector vector1, Vector vector2)
 {
     return vector1._x * vector2._y - vector1._y * vector2._x;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Multiply - Returns the dot product: vector1.X*vector2.X + vector1.Y*vector2.Y
 /// </summary>
 /// <returns>
 /// Returns the dot product: vector1.X*vector2.X + vector1.Y*vector2.Y
 /// </returns>
 /// <param name="vector1"> The first Vector </param>
 /// <param name="vector2"> The second Vector </param>
 public static double Multiply(Vector vector1, Vector vector2)
 {
     return vector1._x * vector2._x + vector1._y * vector2._y;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Offset - translate the Location by the offset provided.
        /// If this is Empty, this method is illegal.
        /// </summary>
        public void Offset(Vector offsetVector)
        {
            if (IsEmpty)
            {
                throw new System.InvalidOperationException("Rect_CannotCallMethod");
            }

            _x += offsetVector._x;
            _y += offsetVector._y;
        }
Exemplo n.º 20
0
 /// <summary>
 /// Determinant - Returns the determinant det(vector1, vector2)
 /// </summary>
 /// <returns>
 /// Returns the determinant: vector1.X*vector2.Y - vector1.Y*vector2.X
 /// </returns>
 /// <param name="vector1"> The first Vector </param>
 /// <param name="vector2"> The second Vector </param>
 public static double Determinant(Vector vector1, Vector vector2)
 {
     return vector1._x * vector2._y - vector1._y * vector2._x;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Constructor which sets the initial values to bound the point provided and the point
 /// which results from point + vector.
 /// </summary>
 public Rect(Point point,
 Vector vector)
     : this(point, point + vector)
 {
 }
Exemplo n.º 22
0
 /// <summary>
 /// Compares two Vector instances for fuzzy equality.  This function
 /// helps compensate for the fact that double values can
 /// acquire error when operated upon
 /// </summary>
 /// <param name='vector1'>The first Vector to compare</param>
 /// <param name='vector2'>The second Vector to compare</param>
 /// <returns>Whether or not the two Vector instances are equal</returns>
 public static bool AreClose(Vector vector1, Vector vector2)
 {
     return DoubleUtil.AreClose(vector1.X, vector2.X) &&
     DoubleUtil.AreClose(vector1.Y, vector2.Y);
 }