共用方式為


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 代表固定位置,而 a Vector 代表方向和大小(例如速度或加速度)。 因此,線段的端點是點,但它們的差是向量;也就是該線段的方向與長度。

在 XAML 中,a Vector 與 值之間的XY分隔符可以是逗號或空格。

有些文化可能會用逗號作為小數分隔符,而不是時代字元。 大多數 XAML 處理器實作中,不變文化的 XAML 處理預設為 en-US,且預期週期為十進位分隔符。 如果在 XAML 中指定 a Vector ,應該避免用逗號作為十進位分隔符,因為這會和屬性 Vector 值轉換成 X and Y components 的字串類型產生衝突。

XAML 屬性使用方式

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

XAML 值

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

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

建構函式

名稱 Description
Vector(Double, Double)

初始化結構的新實例 Vector

屬性

名稱 Description
Length

得到這個向量的長度。

LengthSquared

得到這個向量長度的平方。

X

取得或設定 X 該向量的分量。

Y

取得或設定 Y 該向量的分量。

方法

名稱 Description
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, 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 結構的字串表示及指定的格式資訊。

操作員

名稱 Description
Addition(Vector, Point)

將一個點平移到指定的向量,並返回所得點。

Addition(Vector, Vector)

相加兩個向量,並以向量形式回傳結果。

Division(Vector, Double)

將指定向量除以指定的標量,並回傳所得向量。

Equality(Vector, Vector)

比較兩個向量以求相等。

Explicit(Vector to Point)

建立 Point 一個,且該向量的值為 XY

Explicit(Vector to Size)

從該向量的偏移量產生 a Size

Inequality(Vector, Vector)

比較兩個不平等向量。

Multiply(Double, Vector)

將指定的標量乘以指定的向量,然後返回所得向量。

Multiply(Vector, Double)

將指定的向量乘以指定的標量,然後返回所得向量。

Multiply(Vector, Matrix)

利用指定的 Matrix變換指定向量的座標空間。

Multiply(Vector, Vector)

計算兩個指定向量結構的點積,並以 回傳結果為 Double

Subtraction(Vector, Vector)

從一個指定向量中減去另一個。

UnaryNegation(Vector)

否定指定的向量。

明確介面實作

名稱 Description
IFormattable.ToString(String, IFormatProvider)

此成員支援 Windows Presentation Foundation(WPF)基礎架構,並非直接從您的程式碼中使用。 關於此成員的描述,請參見 ToString(String, IFormatProvider)

適用於

另請參閱