public static Vector2D Lerp(Vector2D value1, Vector2D value2, float amount) { Vector2D vector2 = new Vector2D(); vector2.X = value1.X + (value2.X - value1.X) * amount; vector2.Y = value1.Y + (value2.Y - value1.Y) * amount; return vector2; }
// add this vector with the parameter vector // and return the result public Vector2D Add(Vector2D Vec) { Vector2D NewVec = new Vector2D(); NewVec.X = X + Vec.X; NewVec.Y = Y + Vec.Y; return NewVec; }
// find the angle between this vector and the parameter vector public double AngleTo(Vector2D Vec) { double AdotB = DotProduct(Vec); double ALstarBL = Length() * Vec.Length(); if (ALstarBL == 0) { return 0.0; } return 180.0 / Math.PI * System.Math.Acos(AdotB / ALstarBL); }
// translate the current matrix public void SetToTranslation(Vector2D TransVec) { matrix.SetValue(TransVec.X, 0, 2); matrix.SetValue(TransVec.Y, 1, 2); }
// translate this point by the parameter vector public void TranslateBy(Vector2D Vec) { //if Vec.Length() > 1.0 Then X = X + Vec.X; Y = Y + Vec.Y; //End if }
public Vector2D Divide(Double Value) { Vector2D newvec = new Vector2D(); newvec.X = X / Value; newvec.Y = Y / Value; return newvec; }
// find the unit vector and return it public Vector2D UnitVector() { Vector2D Vec = new Vector2D(); double len = Length(); if (len == 0.0) { Vec.SetVector(0.0, 0.0); return Vec; } Vec.X = X / len; Vec.Y = Y / len; return Vec; }
// copy constructor public Vector2D(Vector2D Vec) { X = Vec.X; Y = Vec.Y; }
public Vector2D Multiply(Double Value) { Vector2D newvec = new Vector2D(); newvec.X = X * Value; newvec.Y = Y * Value; return newvec; }
// subtract this vector with the parameter vector // and return the result public Vector2D Subtract(Vector2D Vec) { Vector2D NewVec = new Vector2D(); NewVec.X = X - Vec.X; NewVec.Y = Y - Vec.Y; return NewVec; }
// checks whether this vector is perpendicular to the parameter vector public Boolean IsPerpendicularTo(Vector2D Vec) { double Ang = AngleTo(Vec); if (Ang == (90 * System.Math.PI / 180.0)) { return true; } else { return false; } }
// checks whether this vector is parallel to the parameter vector public Boolean IsParallelTo(Vector2D Vec) { Vector2D Vec1 = UnitVector(); Vector2D Vec2 = Vec.UnitVector(); if ((Vec1.X == Vec2.X && Vec1.Y == Vec2.Y) || (Vec1.X == -Vec2.X && Vec1.Y == -Vec2.Y)) { return true; } else { return false; } }
// checks whether this vector is equal to the parameter vector public Boolean IsEqualTo(Vector2D Vec) { if (X == Vec.X && Y == Vec.Y) { return true; } else { return false; } }
// checks whether this vector is codirectional to the parameter vector public Boolean IsCodirectionalTo(Vector2D Vec) { Vector2D Vec1 = UnitVector(); Vector2D Vec2 = Vec.UnitVector(); if (Vec1.X == Vec2.X && Vec1.Y == Vec2.Y) { return true; } else { return false; } }
// dot product of this vector and the parameter vector public double DotProduct(Vector2D Vec) { return (X * Vec.X) + (Y * Vec.Y); }