Table of Contents

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 Coordinate

The 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 Coordinate

The origin coordinate

to Coordinate

The destination coordinate

Vector2D(Vector2D)

Creates a new vector instance based on v.

public Vector2D(Vector2D v)

Parameters

v Vector2D

The vector

Vector2D(double, double)

Creates a new vector instance using the provided x and y ordinates

public Vector2D(double x, double y)

Parameters

x double

The x-ordinate value

y double

The y-ordinate value

Properties

this[int]

Gets the ordinate values by index

public double this[int index] { get; }

Parameters

index int

The index

Property Value

double

Exceptions

ArgumentOutOfRangeException

Thrown if index < 0 or > 1

X

Gets the x-ordinate value

public double X { get; }

Property Value

double

Y

Gets the y-ordinate value

public double Y { get; }

Property Value

double

Zero

Creates a new vector with all components set to Zero

public static Vector2D Zero { get; }

Property Value

Vector2D

Methods

Add(Vector2D)

Adds v to this vector instance.

public Vector2D Add(Vector2D v)

Parameters

v Vector2D

The 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

double

AngleTo(Vector2D)

public double AngleTo(Vector2D v)

Parameters

v Vector2D

Returns

double

Average(Vector2D)

public Vector2D Average(Vector2D v)

Parameters

v Vector2D

Returns

Vector2D

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 Coordinate

The 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 Coordinate

The origin coordinate

to Coordinate

The 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 Vector2D

The 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

x double

The x component

y double

The y component

Returns

Vector2D

A new vector

Distance(Vector2D)

Computes the distance between this vector and another one.

public double Distance(Vector2D v)

Parameters

v Vector2D

A vector

Returns

double

The distance between the vectors

Divide(double)

Divides the vector by a scalar value.

public Vector2D Divide(double d)

Parameters

d double

The 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 Vector2D

A 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

o object

A Vector2D with which to do the comparison.

Returns

bool

true if o is a Vector2Dwith the same values for the X and Y components.

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

bool

Length()

public double Length()

Returns

double

LengthSquared()

public double LengthSquared()

Returns

double

Multiply(double)

Multiplies the vector by a scalar value.

public Vector2D Multiply(double d)

Parameters

d double

The 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 double

The 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 int

The 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 Vector2D

The 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 Coordinate

The 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

v Vector2D

The vector to sum

frac double

The fraction of the total contributed by this vector

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

left Vector2D

The first vector to add.

right Vector2D

The second vector to add.

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

value Vector2D

The vector to scale.

scale Vector2D

The amount by which to scale the vector.

Returns

Vector2D

The scaled vector.

operator /(Vector2D, double)

Scales a vector by the given value.

public static Vector2D operator /(Vector2D value, double scale)

Parameters

value Vector2D

The vector to scale.

scale double

The amount by which to scale the vector.

Returns

Vector2D

The scaled vector.

operator ==(Vector2D, Vector2D)

Tests for equality between two objects.

public static bool operator ==(Vector2D left, Vector2D right)

Parameters

left Vector2D

The first value to compare.

right Vector2D

The second value to compare.

Returns

bool

true if left has the same value as right; otherwise, false.

operator !=(Vector2D, Vector2D)

Tests for inequality between two objects.

public static bool operator !=(Vector2D left, Vector2D right)

Parameters

left Vector2D

The first value to compare.

right Vector2D

The second value to compare.

Returns

bool

true if left has a different value than right; otherwise, false.

operator *(Vector2D, Vector2D)

Modulates a vector with another by performing component-wise multiplication"/>.

public static Vector2D operator *(Vector2D left, Vector2D right)

Parameters

left Vector2D

The first vector to multiply.

right Vector2D

The second vector to multiply.

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

value Vector2D

The vector to scale.

scale double

The amount by which to scale the vector.

Returns

Vector2D

The scaled vector.

operator *(double, Vector2D)

Scales a vector by the given value.

public static Vector2D operator *(double scale, Vector2D value)

Parameters

scale double

The amount by which to scale the vector.

value Vector2D

The vector to scale.

Returns

Vector2D

The scaled vector.

operator -(Vector2D, Vector2D)

Subtracts two vectors.

public static Vector2D operator -(Vector2D left, Vector2D right)

Parameters

left Vector2D

The first vector to subtract.

right Vector2D

The second vector to subtract.

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 Vector2D

The vector to negate.

Returns

Vector2D

A vector facing in the opposite direction.