Search Results for

    Show / Hide Table of Contents

    Class Vector2D

    A 2-dimensional mathematical vector represented by double-precision X and Y components.

    Inheritance
    object
    Vector2D
    Implements
    ICloneable
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: NetTopologySuite.Mathematics
    Assembly: NetTopologySuite.dll
    Syntax
    public class Vector2D : ICloneable

    Constructors

    | Edit this page View Source

    Vector2D()

    Creates an new vector instance

    Declaration
    public Vector2D()
    | Edit this page View Source

    Vector2D(Coordinate)

    Creates a vector from a Coordinate.

    Declaration
    public Vector2D(Coordinate v)
    Parameters
    Type Name Description
    Coordinate v

    The coordinate

    | Edit this page View Source

    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

    | Edit this page View Source

    Vector2D(Vector2D)

    Creates a new vector instance based on v.

    Declaration
    public Vector2D(Vector2D v)
    Parameters
    Type Name Description
    Vector2D v

    The vector

    | Edit this page View Source

    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 Source

    this[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

    | Edit this page View Source

    X

    Gets the x-ordinate value

    Declaration
    public double X { get; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    Y

    Gets the y-ordinate value

    Declaration
    public double Y { get; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    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 Source

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

    | Edit this page View Source

    Angle()

    Computes the angle this vector describes to the horizontal axis

    Declaration
    public double Angle()
    Returns
    Type Description
    double

    The angle

    | Edit this page View Source

    Angle(Vector2D)

    Declaration
    public double Angle(Vector2D v)
    Parameters
    Type Name Description
    Vector2D v
    Returns
    Type Description
    double
    | Edit this page View Source

    AngleTo(Vector2D)

    Declaration
    public double AngleTo(Vector2D v)
    Parameters
    Type Name Description
    Vector2D v
    Returns
    Type Description
    double
    | Edit this page View Source

    Average(Vector2D)

    Declaration
    public Vector2D Average(Vector2D v)
    Parameters
    Type Name Description
    Vector2D v
    Returns
    Type Description
    Vector2D
    | Edit this page View Source

    Clone()

    Creates a copy of this vector

    Declaration
    public object Clone()
    Returns
    Type Description
    object

    A copy of this vector

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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 o is a Vector2Dwith the same values for the X and Y components.

    Overrides
    object.Equals(object)
    | Edit this page View Source

    GetHashCode()

    Gets a hashcode for this vector.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    A hashcode for this vector

    Overrides
    object.GetHashCode()
    | Edit this page View Source

    IsParallel(Vector2D)

    Declaration
    public bool IsParallel(Vector2D v)
    Parameters
    Type Name Description
    Vector2D v
    Returns
    Type Description
    bool
    | Edit this page View Source

    Length()

    Declaration
    public double Length()
    Returns
    Type Description
    double
    | Edit this page View Source

    LengthSquared()

    Declaration
    public double LengthSquared()
    Returns
    Type Description
    double
    | Edit this page View Source

    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

    | Edit this page View Source

    Negate()

    Negates this vector

    Declaration
    public Vector2D Negate()
    Returns
    Type Description
    Vector2D

    A new vector with [-_x, -_y]

    | Edit this page View Source

    Normalize()

    Normalizes the vector

    Declaration
    public Vector2D Normalize()
    Returns
    Type Description
    Vector2D

    A new normalized vector

    | Edit this page View Source

    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

    | Edit this page View Source

    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.

    | Edit this page View Source

    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

    | Edit this page View Source

    ToCoordinate()

    Gets a Coordinate from this vector

    Declaration
    public Coordinate ToCoordinate()
    Returns
    Type Description
    Coordinate

    A coordinate

    | Edit this page View Source

    ToString()

    Gets a string representation of this vector

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string representing this vector

    Overrides
    object.ToString()
    | Edit this page View Source

    Translate(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

    | Edit this page View Source

    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 Source

    operator +(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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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

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

    | Edit this page View Source

    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

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

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    Implements

    ICloneable
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX