Пример #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public bool IsParallel(Vector2D v)
 {
     return 0d == RobustDeterminant.SignOfDet2x2(_x, _y, v._x, v._y);
 }
Пример #2
0
 /// <summary>
 /// Creates a new vector instance based on <paramref name="v"/>.
 /// </summary>
 /// <param name="v">The vector</param>
 public Vector2D(Vector2D v)
 {
     _x = v._x;
     _y = v._y;
 }
Пример #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        public double AngleTo(Vector2D v)
        {
            var a1 = Angle();
            var a2 = v.Angle();
            var angDel = a2 - a1;

            // normalize, maintaining orientation
            if (angDel <= -System.Math.PI)
                return angDel + AngleUtility.PiTimes2;
            if (angDel > System.Math.PI)
                return angDel - AngleUtility.PiTimes2;
            return angDel;
        }
Пример #4
0
 /// <summary>
 /// Creates a new vector from an existing one.
 /// </summary>
 /// <param name="v">The vector to copy</param>
 /// <returns>A new vector</returns>
 public static Vector2D Create(Vector2D v)
 {
     return new Vector2D(v);
 }
Пример #5
0
 /// <summary>
 /// Computes the dot-product of two vectors
 /// </summary>
 /// <param name="v">A vector</param>
 /// <returns>The dot product of the vectors</returns>
 public double Dot(Vector2D v)
 {
     return _x * v._x + _y * v._y;
 }
Пример #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public double Angle(Vector2D v)
 {
     return AngleUtility.Diff(v.Angle(), Angle());
 }
Пример #7
0
 /// <summary>
 /// Computes the distance between this vector and another one.
 /// </summary>
 /// <param name="v">A vector</param>
 /// <returns>The distance between the vectors</returns>
 public double Distance(Vector2D v)
 {
     double delx = v._x - _x;
     double dely = v._y - _y;
     return System.Math.Sqrt(delx * delx + dely * dely);
 }
Пример #8
0
 /// <summary>
 /// Computes the weighted sum of this vector
 /// with another vector,
 /// with this vector contributing a fraction
 /// of <tt>frac</tt> to the total.
 /// <para/>
 /// In other words, 
 /// <pre>
 /// sum = frac * this + (1 - frac) * v
 /// </pre>
 /// </summary>
 /// <param name="v">The vector to sum</param>
 /// <param name="frac">The fraction of the total contributed by this vector</param>
 /// <returns>The weighted sum of the two vectors</returns>
 public Vector2D WeightedSum(Vector2D v, double frac)
 {
     return Create(
             frac * _x + (1.0 - frac) * v._x,
             frac * _y + (1.0 - frac) * v._y);
 }
Пример #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public Vector2D Average(Vector2D v)
 {
     return WeightedSum(v, 0.5);
 }
Пример #10
0
 /// <summary>
 /// Subtracts <paramref name="v"/> from this vector instance
 /// </summary>
 /// <param name="v">The vector to subtract</param>
 /// <returns>The result vector</returns>
 public Vector2D Subtract(Vector2D v)
 {
     return Create(_x - v._x, _y - v._y);
 }
Пример #11
0
 /// <summary>
 /// Adds <paramref name="v"/> to this vector instance.
 /// </summary>
 /// <param name="v">The vector to add</param>
 /// <returns>The result vector</returns>
 public Vector2D Add(Vector2D v)
 {
     return Create(_x + v._x, _y + v._y);
 }