Vector Vector Vector Vector Struct

定義

表示 2D 空間中的移動。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 中, XY的值Vector之間的分隔符號可以是逗號或空格。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 Attribute UsageXAML Attribute Usage

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

XAML 值XAML Values

xx
向量的 X 元件。The vector's X component. 如需詳細資訊,請參閱 X 屬性 (Property)。For more information, see the X property.

yy
向量的 Y 元件。The vector's Y component. 如需詳細資訊,請參閱 Y 屬性 (Property)。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)

將指定的向量除以指定的純量,並傳回結果做為 VectorDivides 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)

計算兩個所指定向量的點積,並傳回結果做為 DoubleCalculates 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)

計算兩個所指定向量結構的點積,並傳回結果做為 DoubleCalculates 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).

適用於

另請參閱