Class Vector2D
The Vector2D class represents a vector in 2D space.
Inheritance
Inherited Members
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()
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 |
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 |
Vector2D(Double, Double)
Instantiates a vector with the given X and Y values
Declaration
public Vector2D(double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | x | The X value for the new vector |
| System.Double | y | The Y value for the new vector |
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 |
|---|---|
| System.Double |
X
The X-coordinate of the vector
Declaration
public double X { get; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Y
The Y-coordinate of the vector
Declaration
public double Y { get; }
Property Value
| Type | Description |
|---|---|
| System.Double |
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 |
|---|---|
| System.Double |
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 |
| System.Double | binSize | The size of a bin. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
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 |
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 |
|---|---|
| System.Double |
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 |
| System.Double | differenceSquared | The square of the smallest difference value that should be considered different |
Returns
| Type | Description |
|---|---|
| System.Boolean |
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 |
|---|---|---|
| System.Object | obj | The point to compare to |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Overrides
Finalize()
Declaration
protected void Finalize()
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 |
|---|---|
| System.Int32 |
Overrides
GetLength()
The length (magnitude) of this vector, or the distance from the origin to this vector
Declaration
public double GetLength()
Returns
| Type | Description |
|---|---|
| System.Double |
GetX()
The X-coordinate of the vector
Declaration
public double GetX()
Returns
| Type | Description |
|---|---|
| System.Double |
GetY()
The Y-coordinate of the vector
Declaration
public double GetY()
Returns
| Type | Description |
|---|---|
| System.Double |
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 |
| System.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 |
|---|---|
| System.Boolean |
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 |
| System.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 |
|---|---|
| System.Boolean |
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 |
|---|---|
| System.Double |
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 |
|---|---|
| System.String |
Overrides
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 |
Operators
Addition(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 |
Addition(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 |
Addition(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 |
Division(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 | |
| System.Double | arg1 |
Returns
| Type | Description |
|---|---|
| Vector2D |
Equality(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 |
|---|---|
| System.Boolean |
Inequality(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 |
|---|---|
| System.Boolean |
Multiply(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 | |
| System.Double | arg1 |
Returns
| Type | Description |
|---|---|
| Vector2D |
Multiply(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 |
|---|---|---|
| System.Double | lhs | |
| Vector2D | rhs |
Returns
| Type | Description |
|---|---|
| Vector2D |
Subtraction(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 |
Subtraction(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 |
UnaryNegation(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 |