示例#1
0
        /// <summary>
        /// Multiplies two vectors.
        /// </summary>
        /// <param name="vector1">Source vector.</param>
        /// <param name="vector2">Source vector.</param>
        /// <returns>Returns the product.</returns>
        public static Coordinates3D multiply(Coordinates3D vector1, Coordinates3D vector2)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.X * vector2.X;
            sol.Y = vector1.Y * vector2.Y;
            sol.Z = vector1.Z * vector2.Z;
            return(sol);
        }
示例#2
0
        /// <summary>
        /// Subtracts a scalar to all the coordinates of the source vector.
        /// </summary>
        /// <param name="vector1">Source vector.</param>
        /// <param name="value">The scalar to substract.</param>
        /// <returns>Returs the difference.</returns>
        public static Coordinates3D subtract(Coordinates3D vector1, float value)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.X - value;
            sol.Y = vector1.Y - value;
            sol.Z = vector1.Z - value;
            return(sol);
        }
示例#3
0
        /// <summary>
        /// Divides two vectors.
        /// </summary>
        /// <param name="vector1">The dividend.</param>
        /// <param name="vector2">The divisor.</param>
        /// <returns>Returns the division.</returns>
        public static Coordinates3D divide(Coordinates3D vector1, Coordinates3D vector2)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.X / vector2.X;
            sol.Y = vector1.Y / vector2.Y;
            sol.Z = vector1.Z / vector2.Z;
            return(sol);
        }
示例#4
0
        /// <summary>
        /// Multiplies the source vector by a scalar.
        /// </summary>
        /// <param name="vector1">Source vector.</param>
        /// <param name="value">The factor.</param>
        /// <returns>Returns the product.</returns>
        public static Coordinates3D multiply(Coordinates3D vector1, float value)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.X * value;
            sol.Y = vector1.Y * value;
            sol.Z = vector1.Z * value;
            return(sol);
        }
示例#5
0
        /// <summary>
        /// Calculates the cross product of two vectors.
        /// </summary>
        /// <param name="vector2">Source vector.</param>
        /// <returns>Returns the cross product of the source vectors.</returns>
        public static Coordinates3D cross(Coordinates3D vector1, Coordinates3D vector2)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.Y * vector2.Z - vector1.Z * vector2.Y;
            sol.Y = vector1.Z * vector2.X - vector1.X * vector2.Z;
            sol.Z = vector1.X * vector2.Y - vector1.Y * vector2.X;
            return(sol);
        }
示例#6
0
        /// <summary>
        /// Divides the source vector by an scalar.
        /// </summary>
        /// <param name="vector1">Source vector.</param>
        /// <param name="value">The divisor.</param>
        /// <returns>Returns the division.</returns>
        public static Coordinates3D divide(Coordinates3D vector1, float value)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.X / value;
            sol.Y = vector1.Y / value;
            sol.Z = vector1.Z / value;
            return(sol);
        }
示例#7
0
        /// <summary>
        /// Adds two vectors.
        /// </summary>
        /// <param name="vector1">Source vector.</param>
        /// <param name="vector2">Source vector.</param>
        /// <returns>Returns the sum.</returns>
        public static Coordinates3D add(Coordinates3D vector1, Coordinates3D vector2)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.X + vector2.X;
            sol.Y = vector1.Y + vector2.Y;
            sol.Z = vector1.Z + vector2.Z;
            return(sol);
        }
示例#8
0
        /// <summary>
        /// Adds a scalar to all the coordinates of the source vector.
        /// </summary>
        /// <param name="vector1">Source vector.</param>
        /// <param name="value">The scalar to add.</param>
        /// <returns>Returs the sum.</returns>
        public static Coordinates3D add(Coordinates3D vector1, float value)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.X + value;
            sol.Y = vector1.Y + value;
            sol.Z = vector1.Z + value;
            return(sol);
        }
示例#9
0
        // Normalize in the interval [-1, 1] the given 3D point.
        // The Z value is in the inverval [-1, 0], being 0 the closest distance.
        private Coordinates3D transformTo3DCoord(PointsFingers p, int width, int height, int distance)
        {
            Coordinates3D v = new Coordinates3D();

            v.X = p.Y / (width * 1.0f) * 2 - 1;
            v.Y = (1 - p.X / (height * 1.0f)) * 2 - 1;
            v.Z = (distance - 400) / -7600.0f;
            return(v);
        }
示例#10
0
        /// <summary>
        /// Subtracts two vectors.
        /// </summary>
        /// <param name="vector1">Minuend vector.</param>
        /// <param name="vector2">Subtrahend vector.</param>
        /// <returns>Returns the difference .</returns>
        public static Coordinates3D subtract(Coordinates3D vector1, Coordinates3D vector2)
        {
            Coordinates3D sol = new Coordinates3D();

            sol.X = vector1.X - vector2.X;
            sol.Y = vector1.Y - vector2.Y;
            sol.Z = vector1.Z - vector2.Z;
            return(sol);
        }
示例#11
0
        /// <summary>
        /// Checks if two vectors are equals.
        /// </summary>
        /// <param name="obj">The vector to compare with.</param>
        /// <returns>Returns true if the vectors are equals, or false otherwise.</returns>
        public override bool Equals(object obj)
        {
            Coordinates3D other = (Coordinates3D)obj;

            if (this.X == other.X && this.Y == other.Y && this.Z == other.Z)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#12
0
        // Obtain the 3D normalized point and add it to the list of fingertips
        public void calculate3DPoints(int width, int height, int[] distance)
        {
            if(palm.X != -1 && palm.Y != -1)
                palm3D = transformTo3DCoord(palm, width, height, distance[palm.X * width + palm.Y]); // Calculate 3-D position of palm

            fingertips3D.Clear(); // Empty any unwanted data.
            for(int i = 0; i < fingertips.Count; ++i)
            {
                PointsFingers f = fingertips[i]; // Store the value of each element in f use it as parameter in transformTo3DCoord
                if (palm.X - fingertips[i].X < 20) //reduces the noise, limits fingertips to 20 pixel distance from center.
                {
                    fingertips3D.Add(transformTo3DCoord(f, width, height, distance[f.X * width + f.Y])); // Append the modified elements. The useful set of points are actually in fingertips3D
                }
            }
        }
示例#13
0
 // Obtain the 3D normalized point and add it to the list of fingertips
 public void calculate3DPoints(int width, int height, int[] distance)
 {
     if (palm.X != -1 && palm.Y != -1)
     {
         palm3D = transformTo3DCoord(palm, width, height, distance[palm.X * width + palm.Y]); // Calculate 3-D position of palm
     }
     fingertips3D.Clear();                                                                    // Empty any unwanted data.
     for (int i = 0; i < fingertips.Count; ++i)
     {
         PointsFingers f = fingertips[i];                                                         // Store the value of each element in f use it as parameter in transformTo3DCoord
         if (palm.X - fingertips[i].X < 20)                                                       //reduces the noise, limits fingertips to 20 pixel distance from center.
         {
             fingertips3D.Add(transformTo3DCoord(f, width, height, distance[f.X * width + f.Y])); // Append the modified elements. The useful set of points are actually in fingertips3D
         }
     }
 }
示例#14
0
 /// <summary>
 /// Calculates the distance between two vectors.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the distance between the vectors.</returns>
 public static float distance(Coordinates3D vector1, Coordinates3D vector2)
 {
     return((float)Math.Sqrt((vector1.X - vector2.X) * (vector1.X - vector2.X) + (vector1.Y - vector2.Y) * (vector1.Y - vector2.Y) +
                             (vector1.Z - vector2.Z) * (vector1.Z - vector2.Z)));
 }
示例#15
0
        /// <summary>
        /// Creates a unit vector from the specified vector. The result is a vector one unit in length pointing in the same direction as the original vector.
        /// </summary>
        /// <param name="vector1">Source vector.</param>
        /// <returns>The created unit vector.</returns>
        public static Coordinates3D normalize(Coordinates3D vector1)
        {
            float l = length(vector1);

            return(divide(vector1, l));
        }
示例#16
0
 /// <summary>
 /// Subtracts a scalar to all the coordinates of the source vector.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="value">The scalar to substract.</param>
 /// <returns>Returs the difference.</returns>
 public static Coordinates3D subtract(Coordinates3D vector1, float value)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.X - value;
     sol.Y = vector1.Y - value;
     sol.Z = vector1.Z - value;
     return sol;
 }
示例#17
0
 // Normalize in the interval [-1, 1] the given 3D point.
 // The Z value is in the inverval [-1, 0], being 0 the closest distance.
 private Coordinates3D transformTo3DCoord(PointsFingers p, int width, int height, int distance)
 {
     Coordinates3D v = new Coordinates3D();
     v.X = p.Y / (width * 1.0f) * 2 - 1;
     v.Y = (1 - p.X / (height * 1.0f)) * 2 - 1;
     v.Z = (distance - 400) / -7600.0f;
     return v;
 }
示例#18
0
 /// <summary>
 /// Calculates the distance between two vectors.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the distance between the vectors.</returns>
 public static float distance(Coordinates3D vector1, Coordinates3D vector2)
 {
     return (float)Math.Sqrt((vector1.X - vector2.X) * (vector1.X - vector2.X) + (vector1.Y - vector2.Y) * (vector1.Y - vector2.Y) +
         (vector1.Z - vector2.Z) * (vector1.Z - vector2.Z));
 }
示例#19
0
 /// <summary>
 /// Divides two vectors.
 /// </summary>
 /// <param name="vector1">The dividend.</param>
 /// <param name="vector2">The divisor.</param>
 /// <returns>Returns the division.</returns>
 public static Coordinates3D divide(Coordinates3D vector1, Coordinates3D vector2)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.X / vector2.X;
     sol.Y = vector1.Y / vector2.Y;
     sol.Z = vector1.Z / vector2.Z;
     return sol;
 }
示例#20
0
 /// <summary>
 /// Calculates the smaller angle between two vectors.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the angle in radians.</returns>
 public static float angle(Coordinates3D vector1, Coordinates3D vector2)
 {
     return((float)Math.Acos((vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z) / (length(vector1) * length(vector2))));
 }
示例#21
0
 /// <summary>
 /// Creates a unit vector from the specified vector. The result is a vector one unit in length pointing in the same direction as the original vector.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <returns>The created unit vector.</returns>
 public static Coordinates3D normalize(Coordinates3D vector1)
 {
     float l = length(vector1);
     return divide(vector1, l);
 }
示例#22
0
 /// <summary>
 /// Calculates the smaller angle between two vectors.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the angle in radians.</returns>
 public static float angle(Coordinates3D vector1, Coordinates3D vector2)
 {
     return (float)Math.Acos((vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z) / (length(vector1) * length(vector2)));
 }
示例#23
0
 /// <summary>
 /// Calculates the distance between two vectors.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the distance between the vectors squared.</returns>
 public static float SqauredDistance(Coordinates3D vector1, Coordinates3D vector2)
 {
     return (vector1.X - vector2.X) * (vector1.X - vector2.X) + (vector1.Y - vector2.Y) * (vector1.Y - vector2.Y) +
         (vector1.Z - vector2.Z) * (vector1.Z - vector2.Z);
 }
示例#24
0
 /// <summary>
 /// Adds two vectors.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the sum.</returns>
 public static Coordinates3D add(Coordinates3D vector1, Coordinates3D vector2)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.X + vector2.X;
     sol.Y = vector1.Y + vector2.Y;
     sol.Z = vector1.Z + vector2.Z;
     return sol;
 }
示例#25
0
 /// <summary>
 /// Copy and create a new instance of Vector3FT.
 /// </summary>
 /// <param name="other">The Vector3FT to copy.</param>
 public Coordinates3D(Coordinates3D other)
 {
     this.X = other.X;
     this.Y = other.Y;
     this.Z = other.Z;
 }
示例#26
0
 /// <summary>
 /// Calculates the distance between two vectors.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the distance between the vectors squared.</returns>
 public static float SqauredDistance(Coordinates3D vector1, Coordinates3D vector2)
 {
     return((vector1.X - vector2.X) * (vector1.X - vector2.X) + (vector1.Y - vector2.Y) * (vector1.Y - vector2.Y) +
            (vector1.Z - vector2.Z) * (vector1.Z - vector2.Z));
 }
示例#27
0
 /// <summary>
 /// Multiplies the source vector by a scalar.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="value">The factor.</param>
 /// <returns>Returns the product.</returns>
 public static Coordinates3D multiply(Coordinates3D vector1, float value)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.X * value;
     sol.Y = vector1.Y * value;
     sol.Z = vector1.Z * value;
     return sol;
 }
示例#28
0
 /// <summary>
 /// Calculates the dot product of two vectors. Returns a floating point value between -1 and 1.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the dot product of the source vectors.</returns>
 public static float dot(Coordinates3D vector1, Coordinates3D vector2)
 {
     return((vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z) / (length(vector1) * length(vector2)));
 }
示例#29
0
 /// <summary>
 /// Multiplies two vectors.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the product.</returns>
 public static Coordinates3D multiply(Coordinates3D vector1, Coordinates3D vector2)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.X * vector2.X;
     sol.Y = vector1.Y * vector2.Y;
     sol.Z = vector1.Z * vector2.Z;
     return sol;
 }
示例#30
0
 /// <summary>
 /// Divides the source vector by an scalar.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="value">The divisor.</param>
 /// <returns>Returns the division.</returns>
 public static Coordinates3D divide(Coordinates3D vector1, float value)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.X / value;
     sol.Y = vector1.Y / value;
     sol.Z = vector1.Z / value;
     return sol;
 }
示例#31
0
 /// <summary>
 /// Returns the length of the source vector.
 /// </summary>
 /// <returns>The length of the vector.</returns>
 public static float length(Coordinates3D vector1)
 {
     return (float)Math.Sqrt(vector1.X * vector1.X + vector1.Y * vector1.Y + vector1.Z * vector1.Z);
 }
示例#32
0
 /// <summary>
 /// Copy and create a new instance of Vector3FT.
 /// </summary>
 /// <param name="other">The Vector3FT to copy.</param>
 public Coordinates3D(Coordinates3D other)
 {
     this.X = other.X;
     this.Y = other.Y;
     this.Z = other.Z;
 }
示例#33
0
 /// <summary>
 /// Calculates the dot product of two vectors. Returns a floating point value between -1 and 1.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the dot product of the source vectors.</returns>
 public static float dot(Coordinates3D vector1, Coordinates3D vector2)
 {
     return (vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z) / (length(vector1) * length(vector2));
 }
示例#34
0
 /// <summary>
 /// Calculates the cross product of two vectors.
 /// </summary>
 /// <param name="vector2">Source vector.</param>
 /// <returns>Returns the cross product of the source vectors.</returns>
 public static Coordinates3D cross(Coordinates3D vector1, Coordinates3D vector2)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.Y * vector2.Z - vector1.Z * vector2.Y;
     sol.Y = vector1.Z * vector2.X - vector1.X * vector2.Z;
     sol.Z = vector1.X * vector2.Y - vector1.Y * vector2.X;
     return sol;
 }
示例#35
0
 /// <summary>
 /// Returns the length of the source vector.
 /// </summary>
 /// <returns>The length of the vector.</returns>
 public static float length(Coordinates3D vector1)
 {
     return((float)Math.Sqrt(vector1.X * vector1.X + vector1.Y * vector1.Y + vector1.Z * vector1.Z));
 }
示例#36
0
 /// <summary>
 /// Adds a scalar to all the coordinates of the source vector.
 /// </summary>
 /// <param name="vector1">Source vector.</param>
 /// <param name="value">The scalar to add.</param>
 /// <returns>Returs the sum.</returns>
 public static Coordinates3D add(Coordinates3D vector1, float value)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.X + value;
     sol.Y = vector1.Y + value;
     sol.Z = vector1.Z + value;
     return sol;
 }
示例#37
0
 /// <summary>
 /// Subtracts two vectors.
 /// </summary>
 /// <param name="vector1">Minuend vector.</param>
 /// <param name="vector2">Subtrahend vector.</param>
 /// <returns>Returns the difference .</returns>
 public static Coordinates3D subtract(Coordinates3D vector1, Coordinates3D vector2)
 {
     Coordinates3D sol = new Coordinates3D();
     sol.X = vector1.X - vector2.X;
     sol.Y = vector1.Y - vector2.Y;
     sol.Z = vector1.Z - vector2.Z;
     return sol;
 }