2 out of 2 rated this helpful - Rate this topic

Vector Structure

Represents a displacement in 2-D space.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[SerializableAttribute]
[TypeConverterAttribute(typeof(VectorConverter))]
public struct Vector : IFormattable
<object property="x,y"/>
-or-
<object property="x y"/>

XAML Values

x

The vector's X component. For more information, see the X property.

y

The vector's Y component. For more information, see the Y property.

The Vector type exposes the following members.

  Name Description
Public method Vector Initializes a new instance of the Vector structure.
Top
  Name Description
Public property Length Gets the length of this vector.
Public property LengthSquared Gets the square of the length of this vector.
Public property X Gets or sets the X component of this vector.
Public property Y Gets or sets the Y component of this vector.
Top
  Name Description
Public method Static member Add(Vector, Point) Translates the specified point by the specified vector and returns the resulting point.
Public method Static member Add(Vector, Vector) Adds two vectors and returns the result as a Vector structure.
Public method Static member AngleBetween Retrieves the angle, expressed in degrees, between the two specified vectors.
Public method Static member CrossProduct Calculates the cross product of two vectors.
Public method Static member Determinant Calculates the determinant of two vectors.
Public method Static member Divide Divides the specified vector by the specified scalar and returns the result as a Vector.
Public method Equals(Object) Determines whether the specified Object is a Vector structure and, if it is, whether it has the same X and Y values as this vector. (Overrides ValueType.Equals(Object).)
Public method Equals(Vector) Compares two vectors for equality.
Public method Static member Equals(Vector, Vector) Compares the two specified vectors for equality.
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Returns the hash code for this vector. (Overrides ValueType.GetHashCode().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Static member Multiply(Double, Vector) Multiplies the specified scalar by the specified vector and returns the resulting Vector.
Public method Static member Multiply(Vector, Double) Multiplies the specified vector by the specified scalar and returns the resulting Vector.
Public method Static member Multiply(Vector, Matrix) Transforms the coordinate space of the specified vector using the specified Matrix.
Public method Static member Multiply(Vector, Vector) Calculates the dot product of the two specified vectors and returns the result as a Double.
Public method Negate Negates this vector. The vector has the same magnitude as before, but its direction is now opposite.
Public method Normalize Normalizes this vector.
Public method Static member Parse Converts a string representation of a vector into the equivalent Vector structure.
Public method Static member Subtract Subtracts the specified vector from another specified vector.
Public method ToString() Returns the string representation of this Vector structure. (Overrides ValueType.ToString().)
Public method ToString(IFormatProvider) Returns the string representation of this Vector structure with the specified formatting information.
Top
  Name Description
Public operator Static member Addition(Vector, Point) Translates a point by the specified vector and returns the resulting point.
Public operator Static member Addition(Vector, Vector) Adds two vectors and returns the result as a vector.
Public operator Static member Division Divides the specified vector by the specified scalar and returns the resulting vector.
Public operator Static member Equality Compares two vectors for equality.
Public operator Static member Explicit(Vector to Point) Creates a Point with the X and Y values of this vector.
Public operator Static member Explicit(Vector to Size) Creates a Size from the offsets of this vector.
Public operator Static member Inequality Compares two vectors for inequality.
Public operator Static member Multiply(Double, Vector) Multiplies the specified scalar by the specified vector and returns the resulting vector.
Public operator Static member Multiply(Vector, Double) Multiplies the specified vector by the specified scalar and returns the resulting vector.
Public operator Static member Multiply(Vector, Matrix) Transforms the coordinate space of the specified vector using the specified Matrix.
Public operator Static member Multiply(Vector, Vector) Calculates the dot product of the two specified vector structures and returns the result as a Double.
Public operator Static member Subtraction Subtracts one specified vector from another.
Public operator Static member UnaryNegation Negates the specified vector.
Top
  Name Description
Explicit interface implemetation Private method IFormattable.ToString This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see ToString.
Top

A Point represents a fixed position, but a Vector represents a direction and a magnitude (for example, velocity or acceleration). Thus, the endpoints of a line segment are points but their difference is a vector; that is, the direction and length of that line segment.

In XAML, the delimiter between the X and Y values of a Vector can be either a comma or a space.

Some cultures might use the comma character as the decimal delimiter instead of the period character. XAML processing for invariant culture defaults to en-US in most XAML processor implementations, and expects the period to be the decimal delimiter. You should avoid using the comma character as the decimal delimiter if specifying a Vector in XAML, because that will clash with the string type conversion of a Vector attribute value into the X and Y components.

The following example shows how to add two Vector structures.


// Adds a Vector to a Vector using the overloaded + operator.  

Vector vector1 = new Vector(20, 30);
Vector vector2 = new Vector(45, 70);
Vector vectorResult = new Vector();


// vectorResult is equal to (65,100)
vectorResult = vector1 + vector2;


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ