Class Vector2D
A 2-dimensional mathematical vector represented by double-precision X and Y components.
Implements
Inherited Members
Namespace: NetTopologySuite.Mathematics
Assembly: NetTopologySuite.dll
Syntax
public class Vector2D : ICloneable
Constructors
| Edit this page View SourceVector2D()
Creates an new vector instance
Declaration
public Vector2D()
Vector2D(Coordinate)
Creates a vector from a Coordinate.
Declaration
public Vector2D(Coordinate v)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | v | The coordinate |
Vector2D(Coordinate, Coordinate)
Creates a new vector with the direction and magnitude
of the difference between the
to and from Coordinates.
Declaration
public Vector2D(Coordinate from, Coordinate to)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | from | The origin coordinate |
| Coordinate | to | The destination coordinate |
Vector2D(Vector2D)
Creates a new vector instance based on v.
Declaration
public Vector2D(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v | The vector |
Vector2D(double, double)
Creates a new vector instance using the provided x and y ordinates
Declaration
public Vector2D(double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | The x-ordinate value |
| double | y | The y-ordinate value |
Properties
| Edit this page View Sourcethis[int]
Gets the ordinate values by index
Declaration
public double this[int index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The index |
Property Value
| Type | Description |
|---|---|
| double |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if index < 0 or > 1 |
X
Gets the x-ordinate value
Declaration
public double X { get; }
Property Value
| Type | Description |
|---|---|
| double |
Y
Gets the y-ordinate value
Declaration
public double Y { get; }
Property Value
| Type | Description |
|---|---|
| double |
Zero
Creates a new vector with all components set to Zero
Declaration
public static Vector2D Zero { get; }
Property Value
| Type | Description |
|---|---|
| Vector2D |
Methods
| Edit this page View SourceAdd(Vector2D)
Adds v to this vector instance.
Declaration
public Vector2D Add(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v | The vector to add |
Returns
| Type | Description |
|---|---|
| Vector2D | The result vector |
Angle()
Computes the angle this vector describes to the horizontal axis
Declaration
public double Angle()
Returns
| Type | Description |
|---|---|
| double | The angle |
Angle(Vector2D)
Declaration
public double Angle(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v |
Returns
| Type | Description |
|---|---|
| double |
AngleTo(Vector2D)
Declaration
public double AngleTo(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v |
Returns
| Type | Description |
|---|---|
| double |
Average(Vector2D)
Declaration
public Vector2D Average(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v |
Returns
| Type | Description |
|---|---|
| Vector2D |
Clone()
Creates a copy of this vector
Declaration
public object Clone()
Returns
| Type | Description |
|---|---|
| object | A copy of this vector |
Create(Coordinate)
Creates a vector from a Coordinate.
Declaration
public static Vector2D Create(Coordinate coord)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | coord | The coordinate to copy |
Returns
| Type | Description |
|---|---|
| Vector2D | A new vector |
Create(Coordinate, Coordinate)
Creates a vector with the direction and magnitude
of the difference between the
to and from Coordinates.
Declaration
public static Vector2D Create(Coordinate from, Coordinate to)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | from | The origin coordinate |
| Coordinate | to | The destination coordinate |
Returns
| Type | Description |
|---|---|
| Vector2D | A new vector |
Create(Vector2D)
Creates a new vector from an existing one.
Declaration
public static Vector2D Create(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v | The vector to copy |
Returns
| Type | Description |
|---|---|
| Vector2D | A new vector |
Create(double, double)
Creates a new vector with given X and Y components.
Declaration
public static Vector2D Create(double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | The x component |
| double | y | The y component |
Returns
| Type | Description |
|---|---|
| Vector2D | A new vector |
Distance(Vector2D)
Computes the distance between this vector and another one.
Declaration
public double Distance(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v | A vector |
Returns
| Type | Description |
|---|---|
| double | The distance between the vectors |
Divide(double)
Divides the vector by a scalar value.
Declaration
public Vector2D Divide(double d)
Parameters
| Type | Name | Description |
|---|---|---|
| double | d | The value to divide by |
Returns
| Type | Description |
|---|---|
| Vector2D | A new vector with the value v / d |
Dot(Vector2D)
Computes the dot-product of two vectors
Declaration
public double Dot(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v | A vector |
Returns
| Type | Description |
|---|---|
| double | The dot product of the vectors |
Equals(object)
Tests if a vector o has the same values for the x and y components.
Declaration
public override bool Equals(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o | A Vector2D with which to do the comparison. |
Returns
| Type | Description |
|---|---|
| bool | true if |
Overrides
| Edit this page View SourceGetHashCode()
Gets a hashcode for this vector.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hashcode for this vector |
Overrides
| Edit this page View SourceIsParallel(Vector2D)
Declaration
public bool IsParallel(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v |
Returns
| Type | Description |
|---|---|
| bool |
Length()
Declaration
public double Length()
Returns
| Type | Description |
|---|---|
| double |
LengthSquared()
Declaration
public double LengthSquared()
Returns
| Type | Description |
|---|---|
| double |
Multiply(double)
Multiplies the vector by a scalar value.
Declaration
public Vector2D Multiply(double d)
Parameters
| Type | Name | Description |
|---|---|---|
| double | d | The value to multiply by |
Returns
| Type | Description |
|---|---|
| Vector2D | A new vector with the value v * d |
Negate()
Negates this vector
Declaration
public Vector2D Negate()
Returns
| Type | Description |
|---|---|
| Vector2D | A new vector with [-_x, -_y] |
Normalize()
Normalizes the vector
Declaration
public Vector2D Normalize()
Returns
| Type | Description |
|---|---|
| Vector2D | A new normalized vector |
Rotate(double)
Rotates this vector by angle
Declaration
public Vector2D Rotate(double angle)
Parameters
| Type | Name | Description |
|---|---|---|
| double | angle | The angle |
Returns
| Type | Description |
|---|---|
| Vector2D | The rotated vector |
RotateByQuarterCircle(int)
Rotates a vector by a given number of quarter-circles (i.e. multiples of 90 degrees or Pi/2 radians). A positive number rotates counter-clockwise, a negative number rotates clockwise. Under this operation the magnitude of the vector and the absolute values of the ordinates do not change, only their sign and ordinate index.
Declaration
public Vector2D RotateByQuarterCircle(int numQuarters)
Parameters
| Type | Name | Description |
|---|---|---|
| int | numQuarters | The number of quarter-circles to rotate by |
Returns
| Type | Description |
|---|---|
| Vector2D | The rotated vector. |
Subtract(Vector2D)
Subtracts v from this vector instance
Declaration
public Vector2D Subtract(Vector2D v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v | The vector to subtract |
Returns
| Type | Description |
|---|---|
| Vector2D | The result vector |
ToCoordinate()
Gets a Coordinate from this vector
Declaration
public Coordinate ToCoordinate()
Returns
| Type | Description |
|---|---|
| Coordinate | A coordinate |
ToString()
Gets a string representation of this vector
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string representing this vector |
Overrides
| Edit this page View SourceTranslate(Coordinate)
Gets a Coordinate made of this vector translated by coord.
Declaration
public Coordinate Translate(Coordinate coord)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate | coord | The translation coordinate |
Returns
| Type | Description |
|---|---|
| Coordinate | A coordinate |
WeightedSum(Vector2D, double)
Computes the weighted sum of this vector with another vector, with this vector contributing a fraction of frac to the total.
In other words,sum = frac * this + (1 - frac) * v
Declaration
public Vector2D WeightedSum(Vector2D v, double frac)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | v | The vector to sum |
| double | frac | The fraction of the total contributed by this vector |
Returns
| Type | Description |
|---|---|
| Vector2D | The weighted sum of the two vectors |
Operators
| Edit this page View Sourceoperator +(Vector2D, Vector2D)
Adds two vectors.
Declaration
public static Vector2D operator +(Vector2D left, Vector2D right)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | left | The first vector to add. |
| Vector2D | right | The second vector to add. |
Returns
| Type | Description |
|---|---|
| Vector2D | The sum of the two vectors. |
operator /(Vector2D, Vector2D)
Scales a vector by the given value.
Declaration
public static Vector2D operator /(Vector2D value, Vector2D scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | value | The vector to scale. |
| Vector2D | scale | The amount by which to scale the vector. |
Returns
| Type | Description |
|---|---|
| Vector2D | The scaled vector. |
operator /(Vector2D, double)
Scales a vector by the given value.
Declaration
public static Vector2D operator /(Vector2D value, double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | value | The vector to scale. |
| double | scale | The amount by which to scale the vector. |
Returns
| Type | Description |
|---|---|
| Vector2D | The scaled vector. |
operator ==(Vector2D, Vector2D)
Tests for equality between two objects.
Declaration
public static bool operator ==(Vector2D left, Vector2D right)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | left | The first value to compare. |
| Vector2D | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(Vector2D, Vector2D)
Tests for inequality between two objects.
Declaration
public static bool operator !=(Vector2D left, Vector2D right)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | left | The first value to compare. |
| Vector2D | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator *(Vector2D, Vector2D)
Modulates a vector with another by performing component-wise multiplication"/>.
Declaration
public static Vector2D operator *(Vector2D left, Vector2D right)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | left | The first vector to multiply. |
| Vector2D | right | The second vector to multiply. |
Returns
| Type | Description |
|---|---|
| Vector2D | The multiplication of the two vectors. |
operator *(Vector2D, double)
Scales a vector by the given value.
Declaration
public static Vector2D operator *(Vector2D value, double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | value | The vector to scale. |
| double | scale | The amount by which to scale the vector. |
Returns
| Type | Description |
|---|---|
| Vector2D | The scaled vector. |
operator *(double, Vector2D)
Scales a vector by the given value.
Declaration
public static Vector2D operator *(double scale, Vector2D value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | scale | The amount by which to scale the vector. |
| Vector2D | value | The vector to scale. |
Returns
| Type | Description |
|---|---|
| Vector2D | The scaled vector. |
operator -(Vector2D, Vector2D)
Subtracts two vectors.
Declaration
public static Vector2D operator -(Vector2D left, Vector2D right)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | left | The first vector to subtract. |
| Vector2D | right | The second vector to subtract. |
Returns
| Type | Description |
|---|---|
| Vector2D | The difference of the two vectors. |
operator -(Vector2D)
Reverses the direction of a given vector.
Declaration
public static Vector2D operator -(Vector2D value)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2D | value | The vector to negate. |
Returns
| Type | Description |
|---|---|
| Vector2D | A vector facing in the opposite direction. |