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
| Improve this Doc 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
| Improve this Doc View SourceItem[Int32]
Gets the ordinate values by index
Declaration
public double this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | 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
| Improve this Doc 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 |
---|---|
Boolean | true if |
Overrides
| Improve this Doc View SourceGetHashCode()
Gets a hashcode for this vector.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hashcode for this vector |
Overrides
| Improve this Doc View SourceIsParallel(Vector2D)
Declaration
public bool IsParallel(Vector2D v)
Parameters
Type | Name | Description |
---|---|---|
Vector2D | v |
Returns
Type | Description |
---|---|
Boolean |
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(Int32)
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 |
---|---|---|
Int32 | 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
| Improve this Doc 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
| Improve this Doc View SourceAddition(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. |
Division(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. |
Division(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. |
Equality(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 |
---|---|
Boolean |
|
Inequality(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 |
---|---|
Boolean |
|
Multiply(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. |
Multiply(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. |
Multiply(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. |
Subtraction(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. |
UnaryNegation(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. |