Esempio n. 1
0
 /// <summary>
 /// Scalar multiplies a vector by a real number
 /// </summary>
 /// <param name="number">Scale number</param>
 /// <param name="vector">The vector witch we scalarly multiply</param>
 /// <returns>Scaled vector</returns>
 private static Vector ScalarMultiply(double number, Vector vector)
 {
     double x = Math.Abs(number) * vector.X;
     double y = Math.Abs(number) * vector.Y;
     double value = Math.Sqrt(x * x + y * y);
     Vector result = new Vector(value, vector.angle);
     if (number < 0)
         return -result;
     else
         return result;
 }
Esempio n. 2
0
        /// <summary>
        /// Draw an arrow representing the vector
        /// </summary>
        /// <param name="g">A graphics object to be used to draw the arrow</param>
        /// <param name="location">A point where to draw the beginong of the arrow</param>
        /// <param name="color">A color in witch the arrow will be drawn in</param>
        /// <param name="pen">A pen used for draing the line representing the vector</param>
        public void Draw(Graphics g, Point location, Color color, Pen pen)
        {
            Vector start = new Vector(location);
            Vector end = start + this;

            PointF startPopint = new PointF((float)start.X, (float)start.Y);
            PointF endPoint = new PointF((float)end.X, (float)end.Y);

            g.DrawLine(pen, startPopint, endPoint);
        }
Esempio n. 3
0
 /// <summary>
 /// Adds two vectors
 /// </summary>
 /// <param name="vector1">First vector</param>
 /// <param name="vector2">Second vector</param>
 /// <returns>The resulting vector from the addition</returns>
 private static Vector Addition(Vector vector1, Vector vector2)
 {
     double x = vector1.X + vector2.X;
     double y = vector1.Y + vector2.Y;
     double value = Math.Sqrt(x * x + y * y);
     double angle = Math.Atan2(y, x);
     Vector result = new Vector(value, angle);
     return result;
 }
Esempio n. 4
0
 //the oposite vector of this vector
 public static Vector operator -(Vector vector)
 {
     Vector result = new Vector(vector.Value, Math.PI + vector.Angle); // 180 + angle is the opposite angle
     return result;
 }