Class Vector3D
The Vector3D class represents a vector in 3D space.
Inheritance
Inherited Members
Namespace: DesignData.SDS2.Primitives
Assembly: DesignData.SDS2.Primitives.dll
Syntax
public sealed class Vector3D
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
Vector3D()
Instantiates a vector with X, Y, and Z all zero
Declaration
public Vector3D()
Vector3D(Point3D)
Instantiates a vector with the same X, Y, Z values as the given point
Declaration
public Vector3D(Point3D point)
Parameters
Type | Name | Description |
---|---|---|
Point3D | point | The point whose value to copy |
Vector3D(Vector3D)
Instantiates a vector equal to the given vector
Declaration
public Vector3D(Vector3D vector)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | vector | The vector whose value to copy |
Vector3D(Double, Double, Double)
Instantiates a vector with the given X, Y, and Z values
Declaration
public Vector3D(double x, double y, double z)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x | The X value for the new vector |
System.Double | y | The Y value for the new vector |
System.Double | z | The Z 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 |
Z
The Z-coordinate of the vector
Declaration
public double Z { get; }
Property Value
Type | Description |
---|---|
System.Double |
Methods
Angle(Vector3D)
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(Vector3D pt)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | pt | The other vector |
Returns
Type | Description |
---|---|
System.Double |
BinEquals(Vector3D, 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(Vector3D other, double binSize)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | 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(Vector3D)
Return a unit vector that bisects the two given vectors
Declaration
public Vector3D Bisector(Vector3D other)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | other | The other vector |
Returns
Type | Description |
---|---|
Vector3D |
Cross(Vector3D)
Compute the cross product between this vector and another given vector,
Declaration
public Vector3D Cross(Vector3D pt)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | pt | The other vector |
Returns
Type | Description |
---|---|
Vector3D |
Dot(Vector3D)
Compute the dot product between this vector and another given vector,
Declaration
public double Dot(Vector3D pt)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | pt | The other vector |
Returns
Type | Description |
---|---|
System.Double |
EpsilonEquals(Vector3D, Double)
Returns true if the squared difference between this vector and the given vector is less than difference_squared.
Declaration
public bool EpsilonEquals(Vector3D other, double differenceSquared)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | 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
Interpolate(Vector3D, Double)
Performs linear interpolation between this vector and the other
Declaration
public Vector3D Interpolate(Vector3D other, double t)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | other | The other vector |
System.Double | t | Controls the mixing between the two vectors. This function is defined
for all values of |
Returns
Type | Description |
---|---|
Vector3D |
Remarks
This is equal to this + (other - this) * t
.
Note that due to floating vector arithmetic, p.project(q, 1.0)
may not be exactly equal to q
.
IsNearlyParallel(Vector3D, 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(Vector3D other, double tan_tol)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | 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(Vector3D, 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(Vector3D other, double tan_tol)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | 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 Vector3D Normalize()
Returns
Type | Description |
---|---|
Vector3D |
Remarks
Note: If the vector is a zero-vector or any element is not a finite value, the result is undefined.
ScalarProjection(Vector3D)
Returns the scalar projection of this vector onto other
Declaration
public double ScalarProjection(Vector3D other)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | 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, Y, and Z values will not necessarily yield the same point.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
VectorProjection(Vector3D)
Returns the vector projection of this vector onto other
Declaration
public Vector3D VectorProjection(Vector3D other)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | other | The other vector |
Returns
Type | Description |
---|---|
Vector3D |
Operators
Addition(Point3D, Vector3D)
Return a point which is the sum of the given point and given vector
Declaration
public static Point3D operator +(Point3D arg0, Vector3D arg1)
Parameters
Type | Name | Description |
---|---|---|
Point3D | arg0 | |
Vector3D | arg1 |
Returns
Type | Description |
---|---|
Point3D |
Addition(Vector3D, Point3D)
Return a point which is the sum of the given point and given vector
Declaration
public static Point3D operator +(Vector3D arg0, Point3D arg1)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | arg0 | |
Point3D | arg1 |
Returns
Type | Description |
---|---|
Point3D |
Addition(Vector3D, Vector3D)
Return a vector which is the sum of the two given vectors
Declaration
public static Vector3D operator +(Vector3D arg0, Vector3D arg1)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | arg0 | |
Vector3D | arg1 |
Returns
Type | Description |
---|---|
Vector3D |
Division(Vector3D, Double)
Return a vector with each element divided by the given scalar
Declaration
public static Vector3D operator /(Vector3D arg0, double arg1)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | arg0 | |
System.Double | arg1 |
Returns
Type | Description |
---|---|
Vector3D |
Equality(Vector3D, Vector3D)
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 ==(Vector3D p, Vector3D q)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | p | The point to compare |
Vector3D | q | The point to compare to |
Returns
Type | Description |
---|---|
System.Boolean |
Inequality(Vector3D, Vector3D)
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 !=(Vector3D p, Vector3D q)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | p | The point to compare |
Vector3D | q | The point to compare to |
Returns
Type | Description |
---|---|
System.Boolean |
Multiply(Vector3D, Double)
Return a vector with each element multiplied by the given scalar
Declaration
public static Vector3D operator *(Vector3D arg0, double arg1)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | arg0 | |
System.Double | arg1 |
Returns
Type | Description |
---|---|
Vector3D |
Multiply(Double, Vector3D)
Return a vector with each element multiplied by the given scalar
Declaration
public static Vector3D operator *(double lhs, Vector3D rhs)
Parameters
Type | Name | Description |
---|---|---|
System.Double | lhs | |
Vector3D | rhs |
Returns
Type | Description |
---|---|
Vector3D |
Subtraction(Point3D, Vector3D)
Return a point which is the difference of the given point and given vector
Declaration
public static Point3D operator -(Point3D arg0, Vector3D arg1)
Parameters
Type | Name | Description |
---|---|---|
Point3D | arg0 | |
Vector3D | arg1 |
Returns
Type | Description |
---|---|
Point3D |
Subtraction(Vector3D, Vector3D)
Return a vector which is the difference of the two given vectors
Declaration
public static Vector3D operator -(Vector3D arg0, Vector3D arg1)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | arg0 | |
Vector3D | arg1 |
Returns
Type | Description |
---|---|
Vector3D |
UnaryNegation(Vector3D)
Return the element-wise negation of the vector
Declaration
public static Vector3D operator -(Vector3D p)
Parameters
Type | Name | Description |
---|---|---|
Vector3D | p |
Returns
Type | Description |
---|---|
Vector3D |