Vector Vector Vector Vector Struct

定义

表示二维空间中的位移。Represents a displacement in 2-D space.

public value class Vector : IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.VectorConverter))]
[System.Serializable]
public struct Vector : IFormattable
type Vector = struct
    interface IFormattable
Public Structure Vector
Implements IFormattable
继承
属性
实现

示例

下面的示例演示如何添加两个Vector结构。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;
' 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

注解

表示固定位置, Vector但表示方向和量 (例如, 速度或加速度)。 PointA 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 中, XYVector之间的分隔符可以是逗号或空格。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 处理器实现中, 用于固定区域性的 XAML 处理默认为 en-us, 并期望句点是小数分隔符。XAML processing for invariant culture defaults to en-US in most XAML processor implementations, and expects the period to be the decimal delimiter. 如果在Vector XAML 中指定了, 则应避免使用逗号字符作为小数分隔符, 因为这将与Vector属性值到XY组件的字符串类型转换冲突。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.

XAML 属性用法XAML Attribute Usage

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

XAML 值XAML Values

xx
向量的 X 分量。The vector's X component. 有关更多信息,请参见 X 属性。For more information, see the X property.

yy
向量的 Y 分量。The vector's Y component. 有关更多信息,请参见 Y 属性。For more information, see the Y property.

构造函数

Vector(Double, Double) Vector(Double, Double) Vector(Double, Double) Vector(Double, Double)

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

属性

Length Length Length Length

获取此向量的长度。Gets the length of this vector.

LengthSquared LengthSquared LengthSquared LengthSquared

获取此向量的长度的平方。Gets the square of the length of this vector.

X X X X

获取或设置此向量的 X 分量。Gets or sets the X component of this vector.

Y Y Y Y

获取或设置此向量的 Y 分量。Gets or sets the Y component of this vector.

方法

Add(Vector, Point) Add(Vector, Point) Add(Vector, Point) Add(Vector, Point)

按指定向量平移指定点,并返回结果点。Translates the specified point by the specified vector and returns the resulting point.

Add(Vector, Vector) Add(Vector, Vector) Add(Vector, Vector) Add(Vector, Vector)

将两个向量相加并将结果以 Vector 结构的形式返回。Adds two vectors and returns the result as a Vector structure.

AngleBetween(Vector, Vector) AngleBetween(Vector, Vector) AngleBetween(Vector, Vector) AngleBetween(Vector, Vector)

检索两个指定向量之间的角度(用度表示)。Retrieves the angle, expressed in degrees, between the two specified vectors.

CrossProduct(Vector, Vector) CrossProduct(Vector, Vector) CrossProduct(Vector, Vector) CrossProduct(Vector, Vector)

计算两个向量的叉积。Calculates the cross product of two vectors.

Determinant(Vector, Vector) Determinant(Vector, Vector) Determinant(Vector, Vector) Determinant(Vector, Vector)

计算两个向量的行列式。Calculates the determinant of two vectors.

Divide(Vector, Double) Divide(Vector, Double) Divide(Vector, Double) Divide(Vector, Double)

将指定向量除以指定标量,并将结果以 Vector 形式返回。Divides the specified vector by the specified scalar and returns the result as a Vector.

Equals(Vector) Equals(Vector) Equals(Vector) Equals(Vector)

比较两个向量是否相等。Compares two vectors for equality.

Equals(Vector, Vector) Equals(Vector, Vector) Equals(Vector, Vector) Equals(Vector, Vector)

比较两个指定向量是否相等。Compares the two specified vectors for equality.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的 Object 是不是 Vector 结构,如果是,则确定其是否与此向量具有相同的 XY 值。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.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此向量的哈希代码。Returns the hash code for this vector.

Multiply(Double, Vector) Multiply(Double, Vector) Multiply(Double, Vector) Multiply(Double, Vector)

将指定标量与指定向量相乘,并返回结果 VectorMultiplies the specified scalar by the specified vector and returns the resulting Vector.

Multiply(Vector, Double) Multiply(Vector, Double) Multiply(Vector, Double) Multiply(Vector, Double)

将指定向量与指定标量相乘,并返回结果 VectorMultiplies the specified vector by the specified scalar and returns the resulting Vector.

Multiply(Vector, Matrix) Multiply(Vector, Matrix) Multiply(Vector, Matrix) Multiply(Vector, Matrix)

使用指定的 Matrix 变换指定向量的坐标空间。Transforms the coordinate space of the specified vector using the specified Matrix.

Multiply(Vector, Vector) Multiply(Vector, Vector) Multiply(Vector, Vector) Multiply(Vector, Vector)

计算两个指定向量的点积并将结果以 Double 形式返回。Calculates the dot product of the two specified vectors and returns the result as a Double.

Negate() Negate() Negate() Negate()

对此向量求反。Negates this vector. 向量的大小与以前相同,但现在的方向与以前相反。The vector has the same magnitude as before, but its direction is now opposite.

Normalize() Normalize() Normalize() Normalize()

规范化此向量。Normalizes this vector.

Parse(String) Parse(String) Parse(String) Parse(String)

将向量的字符串表示形式转换为等效的 Vector 结构。Converts a string representation of a vector into the equivalent Vector structure.

Subtract(Vector, Vector) Subtract(Vector, Vector) Subtract(Vector, Vector) Subtract(Vector, Vector)

从一个指定向量中减去另一个指定向量。Subtracts the specified vector from another specified vector.

ToString() ToString() ToString() ToString()

返回此 Vector 结构的字符串表示形式。Returns the string representation of this Vector structure.

ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider)

使用指定的格式设置信息返回此 Vector 结构的字符串表示形式。Returns the string representation of this Vector structure with the specified formatting information.

操作员

Addition(Vector, Vector) Addition(Vector, Vector) Addition(Vector, Vector) Addition(Vector, Vector)

将两个向量相加并将结果以向量形式返回。Adds two vectors and returns the result as a vector.

Addition(Vector, Point) Addition(Vector, Point) Addition(Vector, Point) Addition(Vector, Point)

按指定向量平移点,并返回结果点。Translates a point by the specified vector and returns the resulting point.

Division(Vector, Double) Division(Vector, Double) Division(Vector, Double) Division(Vector, Double)

将指定向量除以指定标量,并返回结果向量。Divides the specified vector by the specified scalar and returns the resulting vector.

Equality(Vector, Vector) Equality(Vector, Vector) Equality(Vector, Vector) Equality(Vector, Vector)

比较两个向量是否相等。Compares two vectors for equality.

Explicit(Vector to Point) Explicit(Vector to Point) Explicit(Vector to Point) Explicit(Vector to Point)

使用此向量的 PointX 值创建 YCreates a Point with the X and Y values of this vector.

Explicit(Vector to Size) Explicit(Vector to Size) Explicit(Vector to Size) Explicit(Vector to Size)

根据此向量的偏移量创建 SizeCreates a Size from the offsets of this vector.

Inequality(Vector, Vector) Inequality(Vector, Vector) Inequality(Vector, Vector) Inequality(Vector, Vector)

比较两个向量是否不相等。Compares two vectors for inequality.

Multiply(Vector, Matrix) Multiply(Vector, Matrix) Multiply(Vector, Matrix) Multiply(Vector, Matrix)

使用指定的 Matrix 变换指定向量的坐标空间。Transforms the coordinate space of the specified vector using the specified Matrix.

Multiply(Vector, Vector) Multiply(Vector, Vector) Multiply(Vector, Vector) Multiply(Vector, Vector)

计算两个指定向量结构的点积并将结果以 Double 形式返回。Calculates the dot product of the two specified vector structures and returns the result as a Double.

Multiply(Double, Vector) Multiply(Double, Vector) Multiply(Double, Vector) Multiply(Double, Vector)

将指定标量与指定向量相乘,并返回结果向量。Multiplies the specified scalar by the specified vector and returns the resulting vector.

Multiply(Vector, Double) Multiply(Vector, Double) Multiply(Vector, Double) Multiply(Vector, Double)

将指定向量与指定标量相乘,并返回结果向量。Multiplies the specified vector by the specified scalar and returns the resulting vector.

Subtraction(Vector, Vector) Subtraction(Vector, Vector) Subtraction(Vector, Vector) Subtraction(Vector, Vector)

从一个指定向量中减去另一个指定向量。Subtracts one specified vector from another.

UnaryNegation(Vector) UnaryNegation(Vector) UnaryNegation(Vector) UnaryNegation(Vector)

对指定向量求反。Negates the specified vector.

显式界面实现

IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider)

此成员支持 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).

适用于

另请参阅