Show / Hide Table of Contents

Struct Vector

Represents a displacement in 2-D space.

Implements
System.IFormattable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: System.Windows
Assembly: OpenSilver.dll
Syntax
[TypeConverter(typeof(VectorConverter))]
public struct Vector : IFormattable

Constructors

| Improve this Doc View Source

Vector(Double, Double)

Initializes a new instance of the Vector structure.

Declaration
public Vector(double x, double y)
Parameters
Type Name Description
System.Double x

The X offset of the new Vector.

System.Double y

The Y offset of the new Vector.

Properties

| Improve this Doc View Source

Length

Gets the length of this vector.

Declaration
public readonly double Length { get; }
Property Value
Type Description
System.Double

The length of this vector.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 Source

Add(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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)

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
System.ValueType.Equals(System.Object)
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
System.ValueType.GetHashCode()
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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)

| Improve this Doc View Source

Negate()

Negates this vector. The vector has the same magnitude as before, but its direction is now opposite.

Declaration
public void Negate()
| Improve this Doc View Source

Normalize()

Normalizes this vector.

Declaration
public void Normalize()
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

ToString()

Returns the string representation of this Vector structure.

Declaration
public override string ToString()
Returns
Type Description
System.String

A string that represents the X and Y values of this Vector.

Overrides
System.ValueType.ToString()
| Improve this Doc View Source

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

A string that represents the X and Y values of this Vector.

Operators

| Improve this Doc View Source

Addition(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Explicit(Vector to Point)

Creates a Point with the X and Y values of this vector.

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 Source

IFormattable.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.

Implements

System.IFormattable
  • Improve this Doc
  • View Source