Show / Hide Table of Contents

    Class Vector2D

    The Vector2D class represents a vector in 2D space.

    Inheritance
    object
    Vector2D
    Inherited Members
    object.GetType()
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    Namespace: DesignData.SDS2.Primitives
    Assembly: DesignData.SDS2.Primitives.dll
    Syntax
    public sealed class Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Constructors

    Vector2D()

    Instantiates a vector with X and Y set to zero

    Declaration
    public Vector2D()
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Vector2D(Point2D)

    Instantiates a vector with the same X and Y values as the given point

    Declaration
    public Vector2D(Point2D point)
    Parameters
    Type Name Description
    Point2D point

    The point whose value to copy

    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Vector2D(Vector2D)

    Instantiates a vector equal to the given vector

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

    The vector whose value to copy

    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Vector2D(double, double)

    Instantiates a vector with the given X and Y values

    Declaration
    public Vector2D(double x, double y)
    Parameters
    Type Name Description
    double x

    The X value for the new vector

    double y

    The Y value for the new vector

    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Properties

    Length

    The length (magnitude) of this vector, or the distance from the origin to this vector

    Declaration
    public double Length { get; }
    Property Value
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    X

    The X-coordinate of the vector

    Declaration
    public double X { get; }
    Property Value
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Y

    The Y-coordinate of the vector

    Declaration
    public double Y { get; }
    Property Value
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Methods

    Angle(Vector2D)

    Return the angle in radians from this vector to a given vector. The returned value is always within the range [0,pi].

    Declaration
    public double Angle(Vector2D pt)
    Parameters
    Type Name Description
    Vector2D pt

    The other vector

    Returns
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    BinEquals(Vector2D, double)

    Returns true if this vector and the given vector fall within the same "bin". A "bin" is a cubic region of vector space approximately binSize on a side.

    Declaration
    public bool BinEquals(Vector2D other, double binSize)
    Parameters
    Type Name Description
    Vector2D other

    The other vector

    double binSize

    The size of a bin.

    Returns
    Type Description
    bool
    Remarks

    Unlike EpsilonEquals, BinEquals maintains the transitive rule of equality, but some vectors which are arbitrarily close together in distance are unequal accorind got EpsilonEquals, because they fall into different bins.

    Bisector(Vector2D)

    Return a unit vector that bisects the two given vectors

    Declaration
    public Vector2D Bisector(Vector2D other)
    Parameters
    Type Name Description
    Vector2D other

    The other vector

    Returns
    Type Description
    Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Dot(Vector2D)

    Compute the dot product between this vector and another given vector,

    Declaration
    public double Dot(Vector2D pt)
    Parameters
    Type Name Description
    Vector2D pt

    The other vector

    Returns
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    EpsilonEquals(Vector2D, double)

    Returns true if the squared difference between this vector and the given vector is less than difference_squared.

    Declaration
    public bool EpsilonEquals(Vector2D other, double differenceSquared)
    Parameters
    Type Name Description
    Vector2D other

    The other vector

    double differenceSquared

    The square of the smallest difference value that should be considered different

    Returns
    Type Description
    bool
    Remarks

    Note that EpsilonEquals can violate the transitivity rule of equality comparison, because there are many groups of points (p, q, r) where p.EpsilonEquals(q) and p.EpsilonEquals(r) but not q.EpsilonEquals(r).

    Equals(object)

    Checks if each element of the points are equal using Double.Equals on each component. Note that this is an "exact" comparison method, and only appropriate in special circumstances.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    The point to compare to

    Returns
    Type Description
    bool
    Overrides
    object.Equals(object)
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    ~Vector2D()

    The Vector2D class represents a vector in 2D space.

    Declaration
    protected ~Vector2D()
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    GetHashCode()

    Returns the hash code for this instance. True for instances which are Equals(), otherwise False with high probability. Specific hash values are implementation-dependent.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int
    Overrides
    object.GetHashCode()
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    GetLength()

    The length (magnitude) of this vector, or the distance from the origin to this vector

    Declaration
    public double GetLength()
    Returns
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    GetX()

    The X-coordinate of the vector

    Declaration
    public double GetX()
    Returns
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    GetY()

    The Y-coordinate of the vector

    Declaration
    public double GetY()
    Returns
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    IsNearlyParallel(Vector2D, double)

    Return true when the absolute value of the tangent of the angle between the two vectors is less than tan_tol. For instance, if tan_tol is 0.01745, it tests that the vectors are within approximately 1 degree of parallel.

    Declaration
    public bool IsNearlyParallel(Vector2D other, double tan_tol)
    Parameters
    Type Name Description
    Vector2D other

    The other vector

    double tan_tol

    The tangent of the angle that specifies the desired tolerance. Note that for small angles x, tan x ~= x, so you can also think of this nearly a tolerance in radians.

    Returns
    Type Description
    bool
    Remarks

    Note that vectors in the exact opposite direction are considered "parallel" for the purposes of this test.

    IsNearlyPerpendicular(Vector2D, double)

    Return true when the tangent of the difference between the vectors' angles and a right angle is within less than tan_tol. For instance, if tan_tol is 0.01745, it tests that the vectors are within approximately 1 degree of perpendicular.

    Declaration
    public bool IsNearlyPerpendicular(Vector2D other, double tan_tol)
    Parameters
    Type Name Description
    Vector2D other

    The other vector

    double tan_tol

    The tangent of the angle that specifies the desired tolerance. Note that for small angles x, tan x ~= x, so you can also think of this nearly a tolerance in radians.

    Returns
    Type Description
    bool
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Normalize()

    Return a vector with the same direction as this vector, but with length 1.0.

    Declaration
    public Vector2D Normalize()
    Returns
    Type Description
    Vector2D
    Remarks

    Note: If the vector is a zero-vector or any element is not a finite value, the result is undefined.

    ScalarProjection(Vector2D)

    Returns the scalar projection of this vector onto other

    Declaration
    public double ScalarProjection(Vector2D other)
    Parameters
    Type Name Description
    Vector2D other

    The other vector

    Returns
    Type Description
    double
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    ToString()

    Formats the point into a string. Note that because the values are rounded for display, parsing them to retrieve the X and Y values will not necessarily yield the same point.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    object.ToString()
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    VectorProjection(Vector2D)

    Returns the vector projection of this vector onto other

    Declaration
    public Vector2D VectorProjection(Vector2D other)
    Parameters
    Type Name Description
    Vector2D other

    The other vector

    Returns
    Type Description
    Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Operators

    operator +(Point2D, Vector2D)

    Return a point which is the sum of the given point and given vector

    Declaration
    public static Point2D operator +(Point2D arg0, Vector2D arg1)
    Parameters
    Type Name Description
    Point2D arg0
    Vector2D arg1
    Returns
    Type Description
    Point2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator +(Vector2D, Point2D)

    Return a point which is the sum of the given point and given vector

    Declaration
    public static Point2D operator +(Vector2D arg0, Point2D arg1)
    Parameters
    Type Name Description
    Vector2D arg0
    Point2D arg1
    Returns
    Type Description
    Point2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator +(Vector2D, Vector2D)

    Return a vector which is the sum of the two given vectors

    Declaration
    public static Vector2D operator +(Vector2D arg0, Vector2D arg1)
    Parameters
    Type Name Description
    Vector2D arg0
    Vector2D arg1
    Returns
    Type Description
    Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator /(Vector2D, double)

    Return a vector with each element divided by the given scalar

    Declaration
    public static Vector2D operator /(Vector2D arg0, double arg1)
    Parameters
    Type Name Description
    Vector2D arg0
    double arg1
    Returns
    Type Description
    Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator ==(Vector2D, Vector2D)

    Checks if each element of the points are equal using == on each component. Note that this is an "exact" comparison method, and only appropriate in special circumstances.

    Declaration
    public static bool operator ==(Vector2D p, Vector2D q)
    Parameters
    Type Name Description
    Vector2D p

    The point to compare

    Vector2D q

    The point to compare to

    Returns
    Type Description
    bool
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator !=(Vector2D, Vector2D)

    Checks if any element of the points are unequal using != on each component. Note that this is an "exact" comparison method, and only appropriate in special circumstances.

    Declaration
    public static bool operator !=(Vector2D p, Vector2D q)
    Parameters
    Type Name Description
    Vector2D p

    The point to compare

    Vector2D q

    The point to compare to

    Returns
    Type Description
    bool
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator *(Vector2D, double)

    Return a vector with each element multiplied by the given scalar

    Declaration
    public static Vector2D operator *(Vector2D arg0, double arg1)
    Parameters
    Type Name Description
    Vector2D arg0
    double arg1
    Returns
    Type Description
    Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator *(double, Vector2D)

    Return a vector with each element multiplied by the given scalar

    Declaration
    public static Vector2D operator *(double lhs, Vector2D rhs)
    Parameters
    Type Name Description
    double lhs
    Vector2D rhs
    Returns
    Type Description
    Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator -(Point2D, Vector2D)

    Return a point which is the difference of the given point and given vector

    Declaration
    public static Point2D operator -(Point2D arg0, Vector2D arg1)
    Parameters
    Type Name Description
    Point2D arg0
    Vector2D arg1
    Returns
    Type Description
    Point2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator -(Vector2D, Vector2D)

    Return a vector which is the difference of the two given vectors

    Declaration
    public static Vector2D operator -(Vector2D arg0, Vector2D arg1)
    Parameters
    Type Name Description
    Vector2D arg0
    Vector2D arg1
    Returns
    Type Description
    Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    operator -(Vector2D)

    Return the element-wise negation of the vector

    Declaration
    public static Vector2D operator -(Vector2D p)
    Parameters
    Type Name Description
    Vector2D p
    Returns
    Type Description
    Vector2D
    Remarks

    Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.

    Back to top