# Vector 结构

## 定义

``public value class Vector : IFormattable``
``````[System.ComponentModel.TypeConverter(typeof(System.Windows.VectorConverter))]
public struct Vector : IFormattable``````
``````[System.ComponentModel.TypeConverter(typeof(System.Windows.VectorConverter))]
[System.Serializable]
public struct Vector : IFormattable``````
``````[<System.ComponentModel.TypeConverter(typeof(System.Windows.VectorConverter))>]
type Vector = struct
interface IFormattable``````
``````[<System.ComponentModel.TypeConverter(typeof(System.Windows.VectorConverter))>]
[<System.Serializable>]
type Vector = struct
interface IFormattable``````
``````Public Structure Vector
Implements IFormattable``````

Vector

## 示例

``````// 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;
``````
``````' Adds a Vector to a Vector using the overloaded + operator.

Dim vector1 As New Vector(20, 30)
Dim vector2 As New Vector(45, 70)
Dim vectorResult As New Vector()

' vectorResult is equal to (65,100)
vectorResult = vector1 + vector2
``````

## 注解

Point表示固定位置，但 Vector 表示方向和量 (例如，速度或加速度) 。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.

### XAML 属性用法XAML Attribute Usage

``````<object property="x,y"/>
-or-
<object property="x y"/>
``````

xx

yy

## 构造函数

 初始化 Vector 结构的新实例。Initializes a new instance of the Vector structure.

## 属性

 获取此向量的长度。Gets the length of this vector. 获取此向量的长度的平方。Gets the square of the length of this vector. 获取或设置此向量的 X 分量。Gets or sets the X component of this vector. 获取或设置此向量的 Y 分量。Gets or sets the Y component of this vector.

## 方法

 按指定向量平移指定点，并返回结果点。Translates the specified point by the specified vector and returns the resulting point. 将两个向量相加并将结果以 Vector 结构的形式返回。Adds two vectors and returns the result as a Vector structure. 检索两个指定向量之间的角度（用度表示）。Retrieves the angle, expressed in degrees, between the two specified vectors. 计算两个向量的叉积。Calculates the cross product of two vectors. 计算两个向量的行列式。Calculates the determinant of two vectors. 将指定向量除以指定标量，并将结果以 Vector 形式返回。Divides the specified vector by the specified scalar and returns the result as a Vector. 确定指定的 Object 是不是 Vector 结构，如果是，则确定其是否与此向量具有相同的 X 和 Y 值。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. 比较两个向量是否相等。Compares two vectors for equality. 比较两个指定向量是否相等。Compares the two specified vectors for equality. 返回此向量的哈希代码。Returns the hash code for this vector. 将指定标量与指定向量相乘，并返回结果 Vector。Multiplies the specified scalar by the specified vector and returns the resulting Vector. 将指定向量与指定标量相乘，并返回结果 Vector。Multiplies the specified vector by the specified scalar and returns the resulting Vector. 使用指定的 Matrix 变换指定向量的坐标空间。Transforms the coordinate space of the specified vector using the specified Matrix. 计算两个指定向量的点积并将结果以 Double 形式返回。Calculates the dot product of the two specified vectors and returns the result as a Double. 对此向量求反。Negates this vector. 向量的大小与以前相同，但现在的方向与以前相反。The vector has the same magnitude as before, but its direction is now opposite. 规范化此向量。Normalizes this vector. 将向量的字符串表示形式转换为等效的 Vector 结构。Converts a string representation of a vector into the equivalent Vector structure. 从一个指定向量中减去另一个指定向量。Subtracts the specified vector from another specified vector. 返回此 Vector 结构的字符串表示形式。Returns the string representation of this Vector structure. 使用指定的格式设置信息返回此 Vector 结构的字符串表示形式。Returns the string representation of this Vector structure with the specified formatting information.

## 运算符

 按指定向量平移点，并返回结果点。Translates a point by the specified vector and returns the resulting point. 将两个向量相加并将结果以向量形式返回。Adds two vectors and returns the result as a vector. 将指定向量除以指定标量，并返回结果向量。Divides the specified vector by the specified scalar and returns the resulting vector. 比较两个向量是否相等。Compares two vectors for equality. 使用此向量的 Point 和 X 值创建 Y。Creates a Point with the X and Y values of this vector. 根据此向量的偏移量创建 Size。Creates a Size from the offsets of this vector. 比较两个向量是否不相等。Compares two vectors for inequality. 将指定标量与指定向量相乘，并返回结果向量。Multiplies the specified scalar by the specified vector and returns the resulting vector. 将指定向量与指定标量相乘，并返回结果向量。Multiplies the specified vector by the specified scalar and returns the resulting vector. 使用指定的 Matrix 变换指定向量的坐标空间。Transforms the coordinate space of the specified vector using the specified Matrix. 计算两个指定向量结构的点积并将结果以 Double 形式返回。Calculates the dot product of the two specified vector structures and returns the result as a Double. 从一个指定向量中减去另一个指定向量。Subtracts one specified vector from another. 对指定向量求反。Negates the specified vector.

## 显式接口实现

 此成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构，但不能在代码中直接使用。This member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明，请参见 ToString(String, IFormatProvider)。For a description of this member, see ToString(String, IFormatProvider).