Vector 結構

定義

表示 2D 空間中的移動。

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

備註

Point表示固定位置,但 Vector 代表方向和大小 (,例如速度或加速) 。 因此,線段的端點是點,但其差異是向量;也就是說,該線段的方向和長度。

在 XAML 中,的 XYVector 之間的分隔符號可以是逗號或空格。

某些文化特性可能會使用逗號字元做為小數分隔符號,而不是句號字元。 在大部分 XAML 處理器實作中,非變異文化特性的 XAML 處理預設為 en-US,而且預期期間為小數分隔符號。 在 XAML 中指定 Vector 時,您應該避免使用逗號字元做為十進位分隔符號,因為這會與將屬性值轉換成 VectorXY 元件的字串類型發生衝突。

XAML Attribute Usage

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

XAML 值

x
向量的 X 元件。 如需詳細資訊,請參閱 X 屬性 (Property)。

y
向量的 Y 元件。 如需詳細資訊,請參閱 Y 屬性 (Property)。

建構函式

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 結構,如果是,則它的 XY 值是否與這個向量相同。

Equals(Vector)

比較兩個向量是否相等。

Equals(Vector, 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)

使用這個向量的 PointX 值建立 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)

適用於

另請參閱