Struct Vector
Represents a displacement in 2-D space.
Implements
Inherited Members
Namespace: System.Windows
Assembly: OpenSilver.dll
Syntax
[TypeConverter(typeof(VectorConverter))]
public struct Vector : IFormattable
Constructors
| Improve this Doc View SourceVector(Double, Double)
Initializes a new instance of the Vector structure.
Declaration
public Vector(double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | x | |
| System.Double | y |
Properties
| Improve this Doc View SourceLength
Gets the length of this vector.
Declaration
public readonly double Length { get; }
Property Value
| Type | Description |
|---|---|
| System.Double | The length of this vector. |
LengthSquared
Gets the square of the length of this vector.
Declaration
public readonly double LengthSquared { get; }
Property Value
| Type | Description |
|---|---|
| System.Double | The square of the Length of this vector. |
X
Gets or sets the X component of this vector.
Declaration
public double X { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double | The X component of this vector. The default value is 0. |
Y
Gets or sets the Y component of this vector.
Declaration
public double Y { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double | The Y component of this vector. The default value is 0. |
Methods
| Improve this Doc View SourceAdd(Vector, Point)
Translates the specified point by the specified vector and returns the resulting point.
Declaration
public static Point Add(Vector vector, Point point)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The amount to translate the specified point. |
| Point | point | The point to translate. |
Returns
| Type | Description |
|---|---|
| Point | The result of translating point by vector. |
Add(Vector, Vector)
Adds two vectors and returns the result as a Vector structure.
Declaration
public static Vector Add(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to add. |
| Vector | vector2 | The second vector to add. |
Returns
| Type | Description |
|---|---|
| Vector | The sum of vector1 and vector2. |
AngleBetween(Vector, Vector)
Retrieves the angle, expressed in degrees, between the two specified vectors.
Declaration
public static double AngleBetween(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to evaluate. |
| Vector | vector2 | The second vector to evaluate. |
Returns
| Type | Description |
|---|---|
| System.Double | The angle, in degrees, between vector1 and vector2. |
CrossProduct(Vector, Vector)
Calculates the cross product of two vectors.
Declaration
public static double CrossProduct(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to evaluate. |
| Vector | vector2 | The second vector to evaluate. |
Returns
| Type | Description |
|---|---|
| System.Double | The cross product of vector1 and vector2. The following formula is used to calculate the cross product: (Vector1.X * Vector2.Y) - (Vector1.Y * Vector2.X) |
Determinant(Vector, Vector)
Calculates the determinant of two vectors.
Declaration
public static double Determinant(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to evaluate. |
| Vector | vector2 | The second vector to evaluate. |
Returns
| Type | Description |
|---|---|
| System.Double | The determinant of vector1 and vector2. |
Divide(Vector, Double)
Divides the specified vector by the specified scalar and returns the result as a Vector.
Declaration
public static Vector Divide(Vector vector, double scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector structure to divide. |
| System.Double | scalar | The amount by which vector is divided. |
Returns
| Type | Description |
|---|---|
| Vector | The result of dividing vector by scalar. |
Equals(Object)
Determines whether the specified System.Object is a Vector structure and, if it is, whether it has the same X and Y values as this vector.
Declaration
public override bool Equals(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | o | The vector to compare. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if o is a Vector and has the same X and Y values as this vector; otherwise, false. |
Overrides
Equals(Vector)
Compares two vectors for equality.
Declaration
public bool Equals(Vector value)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | value | The vector to compare with this vector. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if value has the same X and Y values as this vector; otherwise, false. |
Equals(Vector, Vector)
Compares the two specified vectors for equality.
Declaration
public static bool Equals(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to compare. |
| Vector | vector2 | The second vector to compare. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if the X and Y components of vector1 and vector2 are equal; otherwise, false. |
GetHashCode()
Returns the hash code for this vector.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | The hash code for this instance. |
Overrides
Multiply(Double, Vector)
Multiplies the specified scalar by the specified vector and returns the resulting Vector.
Declaration
public static Vector Multiply(double scalar, Vector vector)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | scalar | The scalar to multiply. |
| Vector | vector | The vector to multiply. |
Returns
| Type | Description |
|---|---|
| Vector | The result of multiplying scalar and vector. |
Multiply(Vector, Double)
Multiplies the specified vector by the specified scalar and returns the resulting Vector.
Declaration
public static Vector Multiply(Vector vector, double scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector to multiply. |
| System.Double | scalar | The scalar to multiply. |
Returns
| Type | Description |
|---|---|
| Vector | The result of multiplying vector and scalar. |
Multiply(Vector, Matrix)
Transforms the coordinate space of the specified vector using the specified Matrix.
Declaration
public static Vector Multiply(Vector vector, Matrix matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector structure to transform. |
| Matrix | matrix | The transformation to apply to vector. |
Returns
| Type | Description |
|---|---|
| Vector | The result of transforming vector by matrix. |
Multiply(Vector, Vector)
Calculates the dot product of the two specified vectors and returns the result as a System.Double.
Declaration
public static double Multiply(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to multiply. |
| Vector | vector2 | The second vector structure to multiply. |
Returns
| Type | Description |
|---|---|
| System.Double | A System.Double containing the scalar dot product of vector1 and vector2, which is calculated using the following formula: (vector1.X * vector2.X) + (vector1.Y * vector2.Y) |
Negate()
Negates this vector. The vector has the same magnitude as before, but its direction is now opposite.
Declaration
public void Negate()
Normalize()
Normalizes this vector.
Declaration
public void Normalize()
Parse(String)
Converts a string representation of a vector into the equivalent Vector structure.
Declaration
public static Vector Parse(string source)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The string representation of the vector. |
Returns
| Type | Description |
|---|---|
| Vector | The equivalent Vector structure. |
Subtract(Vector, Vector)
Subtracts the specified vector from another specified vector.
Declaration
public static Vector Subtract(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The vector from which vector2 is subtracted. |
| Vector | vector2 | The vector to subtract from vector1. |
Returns
| Type | Description |
|---|---|
| Vector | The difference between vector1 and vector2. |
ToString()
Returns the string representation of this Vector structure.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String |
Overrides
ToString(IFormatProvider)
Returns the string representation of this Vector structure with the specified formatting information.
Declaration
public string ToString(IFormatProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IFormatProvider | provider | The culture-specific formatting information. |
Returns
| Type | Description |
|---|---|
| System.String |
Operators
| Improve this Doc View SourceAddition(Vector, Point)
Translates a point by the specified vector and returns the resulting point.
Declaration
public static Point operator +(Vector vector, Point point)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | |
| Point | point | The point to translate. |
Returns
| Type | Description |
|---|---|
| Point | The result of translating point by vector. |
Addition(Vector, Vector)
Adds two vectors and returns the result as a vector.
Declaration
public static Vector operator +(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to add. |
| Vector | vector2 | The second vector to add. |
Returns
| Type | Description |
|---|---|
| Vector | The sum of vector1 and vector2. |
Division(Vector, Double)
Divides the specified vector by the specified scalar and returns the resulting vector.
Declaration
public static Vector operator /(Vector vector, double scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector to divide. |
| System.Double | scalar | The scalar by which vector will be divided. |
Returns
| Type | Description |
|---|---|
| Vector | The result of dividing vector by scalar. |
Equality(Vector, Vector)
Compares two vectors for equality.
Declaration
public static bool operator ==(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to compare. |
| Vector | vector2 | The second vector to compare. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if the X and Y components of vector1 and vector2 are equal; otherwise, false. |
Explicit(Vector to Point)
Declaration
public static explicit operator Point(Vector vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector to convert. |
Returns
| Type | Description |
|---|---|
| Point | A point with X and Y coordinate values equal to the X and Y offset values of vector. |
Explicit(Vector to Size)
Creates a Size from the offsets of this vector.
Declaration
public static explicit operator Size(Vector vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector to convert. |
Returns
| Type | Description |
|---|---|
| Size | A Size with a Width equal to the absolute value of this vector's X property and a Height equal to the absolute value of this vector's Y property. |
Inequality(Vector, Vector)
Compares two vectors for inequality.
Declaration
public static bool operator !=(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to compare. |
| Vector | vector2 | The second vector to compare. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if the X and Y components of vector1 and vector2 are different; otherwise, false. |
Multiply(Double, Vector)
Multiplies the specified scalar by the specified vector and returns the resulting vector.
Declaration
public static Vector operator *(double scalar, Vector vector)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | scalar | The scalar to multiply. |
| Vector | vector | The vector to multiply. |
Returns
| Type | Description |
|---|---|
| Vector | The result of multiplying scalar and vector. |
Multiply(Vector, Double)
Multiplies the specified vector by the specified scalar and returns the resulting vector.
Declaration
public static Vector operator *(Vector vector, double scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector to multiply. |
| System.Double | scalar | The scalar to multiply. |
Returns
| Type | Description |
|---|---|
| Vector | The result of multiplying vector and scalar. |
Multiply(Vector, Matrix)
Transforms the coordinate space of the specified vector using the specified Matrix.
Declaration
public static Vector operator *(Vector vector, Matrix matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector to transform. |
| Matrix | matrix | The transformation to apply to vector. |
Returns
| Type | Description |
|---|---|
| Vector | The result of transforming vector by matrix. |
Multiply(Vector, Vector)
Calculates the dot product of the two specified vector structures and returns the result as a System.Double.
Declaration
public static double operator *(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The first vector to multiply. |
| Vector | vector2 | The second vector to multiply. |
Returns
| Type | Description |
|---|---|
| System.Double | Returns a System.Double containing the scalar dot product of vector1 and vector2, which is calculated using the following formula: vector1.X * vector2.X + vector1.Y * vector2.Y |
Subtraction(Vector, Vector)
Subtracts one specified vector from another.
Declaration
public static Vector operator -(Vector vector1, Vector vector2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector1 | The vector from which vector2 is subtracted. |
| Vector | vector2 | The vector to subtract from vector1. |
Returns
| Type | Description |
|---|---|
| Vector | The difference between vector1 and vector2. |
UnaryNegation(Vector)
Negates the specified vector.
Declaration
public static Vector operator -(Vector vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | vector | The vector to negate. |
Returns
| Type | Description |
|---|---|
| Vector | A vector with X and Y values opposite of the X and Y values of vector. |
Explicit Interface Implementations
| Improve this Doc View SourceIFormattable.ToString(String, IFormatProvider)
Creates a string representation of this object based on the format string and IFormatProvider passed in. If the provider is null, the CurrentCulture is used. See the documentation for IFormattable for more information.
Declaration
string IFormattable.ToString(string format, IFormatProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | format | |
| System.IFormatProvider | provider |
Returns
| Type | Description |
|---|---|
| System.String | A string representation of this object. |