Microsoft.Xna.Framework.Vector2.Dot C# (CSharp) Method

Dot() public static method

Calculates the dot product of two vectors and writes the result to a user-specified variable. If the two vectors are unit vectors, the dot product returns a floating point value between -1 and 1 that can be used to determine some properties of the angle between two vectors. For example, it can show whether the vectors are orthogonal, parallel, or have an acute or obtuse angle between them.
public static Dot ( Vector2 &value1, Vector2 &value2, float &result ) : void
value1 Vector2 Source vector.
value2 Vector2 Source vector.
result float [OutAttribute] The dot product of the two vectors.
return void
        public static void Dot(ref Vector2 value1, ref Vector2 value2, out float result)
        {
            result = value1.X * value2.X + value1.Y * value2.Y;
        }
        /// <summary>Turns the current vector into a unit vector. The result is a vector one unit in length pointing in the same direction as the original vector.</summary>

Same methods

Vector2::Dot ( Vector2 value1, Vector2 value2 ) : float

Usage Example

コード例 #1
0
        public float DistanceToSquared(ref Vector3 vector, out Segment connectingSegment)
        {
            float segmentLength = (float)this.GetLength();

            Vector2 normalizedLine = new Vector2(
                (float)(Point2.X - Point1.X) / segmentLength,
                (float)(Point2.Y - Point1.Y) / segmentLength);

            Vector2 pointVector = new Vector2((float)(vector.X - Point1.X), (float)(vector.Y - Point1.Y));

            float length = Vector2.Dot(pointVector, normalizedLine);

            if (length < 0)
            {
                connectingSegment.Point1 = new Point(ref vector);
                connectingSegment.Point2 = Point1;

                return((float)connectingSegment.GetLengthSquared());
            }
            else if (length > segmentLength)
            {
                connectingSegment.Point1 = new Point(ref vector);
                connectingSegment.Point2 = Point2;

                return((float)connectingSegment.GetLengthSquared());
            }
            else
            {
                connectingSegment.Point1 = new Point(ref vector);
                connectingSegment.Point2 = new Point(Point1.X + length * normalizedLine.X,
                                                     Point1.Y + length * normalizedLine.Y);

                return((float)connectingSegment.GetLengthSquared());
            }
        }
All Usage Examples Of Microsoft.Xna.Framework.Vector2::Dot