通过


Vector 结构

定义

表示二维空间中的偏移量。

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

示例

以下示例演示如何添加两个 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

注解

A Point 表示固定位置,但 Vector 表示方向和数量级(例如速度或加速)。 因此,线段的端点是点,但它们的区别是向量;即该线段的方向和长度。

在 XAML 中XY,分隔符与值Vector之间的分隔符可以是逗号或空格。

某些区域性可能会使用逗号字符作为小数分隔符,而不是句点字符。 固定区域性的 XAML 处理默认在大多数 XAML 处理器实现中 en-US,并且预期句点为小数分隔符。 如果在 XAML 中指定Vector字符,则应避免使用逗号字符作为小数分隔符,因为这将与属性值的字符串类型转换VectorXY组件冲突。

XAML 属性用法

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

XAML 值

x 矢量的 X 组件。 有关详细信息,请参阅 X 属性。

y 矢量的 Y 组件。 有关详细信息,请参阅 Y 属性。

构造函数

名称 说明
Vector(Double, Double)

初始化结构的新实例 Vector

属性

名称 说明
Length

获取此矢量的长度。

LengthSquared

获取此向量长度的平方。

X

获取或设置 X 此矢量的组件。

Y

获取或设置 Y 此矢量的组件。

方法

名称 说明
Add(Vector, Point)

按指定的向量转换指定的点并返回结果点。

Add(Vector, Vector)

添加两个 Vector 向量,并将结果作为结构返回。

AngleBetween(Vector, Vector)

检索两个指定向量之间的角度(以度为单位)。

CrossProduct(Vector, Vector)

计算两个向量的交叉乘积。

Determinant(Vector, Vector)

计算两个向量的确定性。

Divide(Vector, Double)

将指定的向量除以指定的标量并返回结果作为一个 Vector

Equals(Object)

确定指定 Object 是否为 Vector 结构,如果是,则是否具有与此向量相同的 X 值和 Y 值。

Equals(Vector, Vector)

比较两个指定向量是否相等。

Equals(Vector)

比较两个相等矢量。

GetHashCode()

返回此矢量的哈希代码。

Multiply(Double, Vector)

将指定的标量乘以指定的向量并返回结果 Vector

Multiply(Vector, Double)

将指定的向量乘以指定的标量并返回结果 Vector

Multiply(Vector, Matrix)

使用指定的向量转换指定 Matrix矢量的坐标空间。

Multiply(Vector, Vector)

计算两个指定向量的点积,并返回结果作为一个 Double

Negate()

否定此向量。 矢量的震级与以前相同,但其方向现在正好相反。

Normalize()

规范化此向量。

Parse(String)

将矢量的字符串表示形式转换为等效 Vector 结构。

Subtract(Vector, Vector)

从另一个指定向量中减去指定的向量。

ToString()

返回此 Vector 结构的字符串表示形式。

ToString(IFormatProvider)

返回具有指定格式信息的此 Vector 结构的字符串表示形式。

运营商

名称 说明
Addition(Vector, Point)

按指定的向量转换点并返回结果点。

Addition(Vector, Vector)

添加两个向量并返回结果作为向量。

Division(Vector, Double)

将指定的向量除以指定的标量并返回生成的向量。

Equality(Vector, Vector)

比较两个相等矢量。

Explicit(Vector to Point)

创建一个 Point 具有 X 此向量的值和 Y 值。

Explicit(Vector to Size)

从此向量偏移量创建一个 Size

Inequality(Vector, Vector)

比较两个不相等的向量。

Multiply(Double, Vector)

将指定的标量乘以指定的向量并返回生成的向量。

Multiply(Vector, Double)

将指定的向量乘以指定的标量并返回生成的向量。

Multiply(Vector, Matrix)

使用指定的向量转换指定 Matrix矢量的坐标空间。

Multiply(Vector, Vector)

计算两个指定向量结构的点积,并返回结果作为一个 Double

Subtraction(Vector, Vector)

从另一个指定向量中减去一个指定向量。

UnaryNegation(Vector)

否定指定的向量。

显式接口实现

名称 说明
IFormattable.ToString(String, IFormatProvider)

此成员支持 Windows Presentation Foundation (WPF) 基础结构,不应直接从代码使用。 有关此成员的说明,请参阅 ToString(String, IFormatProvider)

适用于

另请参阅