Export (0) Print
Expand All

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.

  NameDescription
Public methodVectorInitializes a new instance of the Vector structure.
Top

  NameDescription
Public propertyLengthGets the length of this vector.
Public propertyLengthSquaredGets the square of the length of this vector.
Public propertyXGets or sets the X component of this vector.
Public propertyYGets or sets the Y component of this vector.
Top

  NameDescription
Public methodStatic memberAdd(Vector, Point)Translates the specified point by the specified vector and returns the resulting point.
Public methodStatic memberAdd(Vector, Vector)Adds two vectors and returns the result as a Vector structure.
Public methodStatic memberAngleBetweenRetrieves the angle, expressed in degrees, between the two specified vectors.
Public methodStatic memberCrossProductCalculates the cross product of two vectors.
Public methodStatic memberDeterminantCalculates the determinant of two vectors.
Public methodStatic memberDivideDivides the specified vector by the specified scalar and returns the result as a Vector.
Public methodEquals(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 methodEquals(Vector) Compares two vectors for equality.
Public methodStatic memberEquals(Vector, Vector)Compares the two specified vectors for equality.
Public methodGetHashCodeReturns the hash code for this vector. (Overrides ValueType.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberMultiply(Double, Vector) Multiplies the specified scalar by the specified vector and returns the resulting Vector.
Public methodStatic memberMultiply(Vector, Double) Multiplies the specified vector by the specified scalar and returns the resulting Vector.
Public methodStatic memberMultiply(Vector, Matrix)Transforms the coordinate space of the specified vector using the specified Matrix.
Public methodStatic memberMultiply(Vector, Vector)Calculates the dot product of the two specified vectors and returns the result as a Double.
Public methodNegateNegates this vector. The vector has the same magnitude as before, but its direction is now opposite.
Public methodNormalize Normalizes this vector.
Public methodStatic memberParseConverts a string representation of a vector into the equivalent Vector structure.
Public methodStatic memberSubtractSubtracts the specified vector from another specified vector.
Public methodToString()Returns the string representation of this Vector structure. (Overrides ValueType.ToString().)
Public methodToString(IFormatProvider)Returns the string representation of this Vector structure with the specified formatting information.
Top

  NameDescription
Public operatorStatic memberAddition(Vector, Point) Translates a point by the specified vector and returns the resulting point.
Public operatorStatic memberAddition(Vector, Vector)Adds two vectors and returns the result as a vector.
Public operatorStatic memberDivision Divides the specified vector by the specified scalar and returns the resulting vector.
Public operatorStatic memberEquality Compares two vectors for equality.
Public operatorStatic memberExplicit(Vector to Point)Creates a Point with the X and Y values of this vector.
Public operatorStatic memberExplicit(Vector to Size)Creates a Size from the offsets of this vector.
Public operatorStatic memberInequalityCompares two vectors for inequality.
Public operatorStatic memberMultiply(Double, Vector) Multiplies the specified scalar by the specified vector and returns the resulting vector.
Public operatorStatic memberMultiply(Vector, Double)Multiplies the specified vector by the specified scalar and returns the resulting vector.
Public operatorStatic memberMultiply(Vector, Matrix) Transforms the coordinate space of the specified vector using the specified Matrix.
Public operatorStatic memberMultiply(Vector, Vector) Calculates the dot product of the two specified vector structures and returns the result as a Double.
Public operatorStatic memberSubtractionSubtracts one specified vector from another.
Public operatorStatic memberUnaryNegationNegates the specified vector.
Top

  NameDescription
Explicit interface implemetationPrivate methodIFormattable.ToStringThis 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.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Show:
© 2014 Microsoft