Class Vector2D
- Namespace
- NetTopologySuite.Mathematics
- Assembly
- NetTopologySuite.dll
A 2-dimensional mathematical vector represented by double-precision X and Y components.
public class Vector2D : ICloneable
- Inheritance
-
Vector2D
- Implements
- Inherited Members
Constructors
Vector2D()
Creates an new vector instance
public Vector2D()
Vector2D(Coordinate)
Creates a vector from a Coordinate.
public Vector2D(Coordinate v)
Parameters
v
CoordinateThe coordinate
Vector2D(Coordinate, Coordinate)
Creates a new vector with the direction and magnitude
of the difference between the
to
and from
Coordinates.
public Vector2D(Coordinate from, Coordinate to)
Parameters
from
CoordinateThe origin coordinate
to
CoordinateThe destination coordinate
Vector2D(Vector2D)
Creates a new vector instance based on v
.
public Vector2D(Vector2D v)
Parameters
v
Vector2DThe vector
Vector2D(double, double)
Creates a new vector instance using the provided x
and y
ordinates
public Vector2D(double x, double y)
Parameters
Properties
this[int]
Gets the ordinate values by index
public double this[int index] { get; }
Parameters
index
intThe index
Property Value
Exceptions
- ArgumentOutOfRangeException
Thrown if index < 0 or > 1
X
Gets the x-ordinate value
public double X { get; }
Property Value
Y
Gets the y-ordinate value
public double Y { get; }
Property Value
Zero
Creates a new vector with all components set to Zero
public static Vector2D Zero { get; }
Property Value
Methods
Add(Vector2D)
Adds v
to this vector instance.
public Vector2D Add(Vector2D v)
Parameters
v
Vector2DThe vector to add
Returns
- Vector2D
The result vector
Angle()
Computes the angle this vector describes to the horizontal axis
public double Angle()
Returns
- double
The angle
Angle(Vector2D)
public double Angle(Vector2D v)
Parameters
v
Vector2D
Returns
AngleTo(Vector2D)
public double AngleTo(Vector2D v)
Parameters
v
Vector2D
Returns
Average(Vector2D)
public Vector2D Average(Vector2D v)
Parameters
v
Vector2D
Returns
Clone()
Creates a copy of this vector
public object Clone()
Returns
- object
A copy of this vector
Create(Coordinate)
Creates a vector from a Coordinate.
public static Vector2D Create(Coordinate coord)
Parameters
coord
CoordinateThe coordinate to copy
Returns
- Vector2D
A new vector
Create(Coordinate, Coordinate)
Creates a vector with the direction and magnitude
of the difference between the
to
and from
Coordinates.
public static Vector2D Create(Coordinate from, Coordinate to)
Parameters
from
CoordinateThe origin coordinate
to
CoordinateThe destination coordinate
Returns
- Vector2D
A new vector
Create(Vector2D)
Creates a new vector from an existing one.
public static Vector2D Create(Vector2D v)
Parameters
v
Vector2DThe vector to copy
Returns
- Vector2D
A new vector
Create(double, double)
Creates a new vector with given X and Y components.
public static Vector2D Create(double x, double y)
Parameters
Returns
- Vector2D
A new vector
Distance(Vector2D)
Computes the distance between this vector and another one.
public double Distance(Vector2D v)
Parameters
v
Vector2DA vector
Returns
- double
The distance between the vectors
Divide(double)
Divides the vector by a scalar value.
public Vector2D Divide(double d)
Parameters
d
doubleThe value to divide by
Returns
- Vector2D
A new vector with the value v / d
Dot(Vector2D)
Computes the dot-product of two vectors
public double Dot(Vector2D v)
Parameters
v
Vector2DA vector
Returns
- double
The dot product of the vectors
Equals(object)
Tests if a vector o
has the same values for the x and y components.
public override bool Equals(object o)
Parameters
Returns
GetHashCode()
Gets a hashcode for this vector.
public override int GetHashCode()
Returns
- int
A hashcode for this vector
IsParallel(Vector2D)
public bool IsParallel(Vector2D v)
Parameters
v
Vector2D
Returns
Length()
public double Length()
Returns
LengthSquared()
public double LengthSquared()
Returns
Multiply(double)
Multiplies the vector by a scalar value.
public Vector2D Multiply(double d)
Parameters
d
doubleThe value to multiply by
Returns
- Vector2D
A new vector with the value v * d
Negate()
Negates this vector
public Vector2D Negate()
Returns
- Vector2D
A new vector with [-_x, -_y]
Normalize()
Normalizes the vector
public Vector2D Normalize()
Returns
- Vector2D
A new normalized vector
Rotate(double)
Rotates this vector by angle
public Vector2D Rotate(double angle)
Parameters
angle
doubleThe angle
Returns
- 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.
public Vector2D RotateByQuarterCircle(int numQuarters)
Parameters
numQuarters
intThe number of quarter-circles to rotate by
Returns
- Vector2D
The rotated vector.
Subtract(Vector2D)
Subtracts v
from this vector instance
public Vector2D Subtract(Vector2D v)
Parameters
v
Vector2DThe vector to subtract
Returns
- Vector2D
The result vector
ToCoordinate()
Gets a Coordinate from this vector
public Coordinate ToCoordinate()
Returns
- Coordinate
A coordinate
ToString()
Gets a string representation of this vector
public override string ToString()
Returns
- string
A string representing this vector
Translate(Coordinate)
Gets a Coordinate made of this vector translated by coord
.
public Coordinate Translate(Coordinate coord)
Parameters
coord
CoordinateThe translation coordinate
Returns
- 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
public Vector2D WeightedSum(Vector2D v, double frac)
Parameters
Returns
- Vector2D
The weighted sum of the two vectors
Operators
operator +(Vector2D, Vector2D)
Adds two vectors.
public static Vector2D operator +(Vector2D left, Vector2D right)
Parameters
Returns
- Vector2D
The sum of the two vectors.
operator /(Vector2D, Vector2D)
Scales a vector by the given value.
public static Vector2D operator /(Vector2D value, Vector2D scale)
Parameters
Returns
- Vector2D
The scaled vector.
operator /(Vector2D, double)
Scales a vector by the given value.
public static Vector2D operator /(Vector2D value, double scale)
Parameters
Returns
- Vector2D
The scaled vector.
operator ==(Vector2D, Vector2D)
Tests for equality between two objects.
public static bool operator ==(Vector2D left, Vector2D right)
Parameters
Returns
- bool
true
ifleft
has the same value asright
; otherwise,false
.
operator !=(Vector2D, Vector2D)
Tests for inequality between two objects.
public static bool operator !=(Vector2D left, Vector2D right)
Parameters
Returns
- bool
true
ifleft
has a different value thanright
; otherwise,false
.
operator *(Vector2D, Vector2D)
Modulates a vector with another by performing component-wise multiplication"/>.
public static Vector2D operator *(Vector2D left, Vector2D right)
Parameters
Returns
- Vector2D
The multiplication of the two vectors.
operator *(Vector2D, double)
Scales a vector by the given value.
public static Vector2D operator *(Vector2D value, double scale)
Parameters
Returns
- Vector2D
The scaled vector.
operator *(double, Vector2D)
Scales a vector by the given value.
public static Vector2D operator *(double scale, Vector2D value)
Parameters
Returns
- Vector2D
The scaled vector.
operator -(Vector2D, Vector2D)
Subtracts two vectors.
public static Vector2D operator -(Vector2D left, Vector2D right)
Parameters
Returns
- Vector2D
The difference of the two vectors.
operator -(Vector2D)
Reverses the direction of a given vector.
public static Vector2D operator -(Vector2D value)
Parameters
value
Vector2DThe vector to negate.
Returns
- Vector2D
A vector facing in the opposite direction.