Vector3d

References
Represents the three components of a vector in three-dimensional space, using double-precision floating point numbers.

Constructors

Vector3d

#Since v5.0
Initializes a new instance of a vector, using its three components.
public Vector3d(
x,
The X (first) component.
y,
The Y (second) component.
z
The Z (third) component.
)

Vector3d

#Since v5.0
Initializes a new instance of a vector, copying the three components from the three coordinates of a point.
public Vector3d(
point
The point to copy from.
)

Vector3d

#Since v5.0
Initializes a new instance of a vector, copying the three components from a vector.
public Vector3d(
Vector3d
vector
A double-precision vector.
)

Vector3d

#Since v5.0
Initializes a new instance of a vector, copying the three components from a single-precision vector.
public Vector3d(
vector
A single-precision vector.
)

Properties

IsUnitVector

#Since v5.0
Gets a value indicating whether or not this is a unit vector. A unit vector has length 1.
public bool IsUnitVector { get; }

IsValid

#Since v5.0
Gets a value indicating whether this vector is valid. A valid vector must be formed of valid component values for x, y and z.
public bool IsValid { get; }

IsZero

#Since v5.0
Gets a value indicating whether the X, Y, and Z values are all equal to 0.0.
public bool IsZero { get; }

Length

#Since v5.0
Computes the length (or magnitude, or size) of this vector. This is an application of Pythagoras' theorem. If this vector is invalid, its length is considered 0.
public double Length { get; }

MaximumCoordinate

#Since v5.0
Gets the largest (both positive and negative) component value in this vector, as an absolute value.
public double MaximumCoordinate { get; }

MinimumCoordinate

#Since v5.0
Gets the smallest (both positive and negative) component value in this vector.
public double MinimumCoordinate { get; }

SquareLength

#Since v5.0
Computes the squared length (or magnitude, or size) of this vector. This is an application of Pythagoras' theorem. While the Length property checks for input validity, this property does not. You should check validity in advance, if this vector can be invalid.
public double SquareLength { get; }

Unset

#Since v5.0
Gets the value of the vector with each component set to RhinoMath.UnsetValue.
public static Vector3d Unset { get; }

X

#Since v5.0
Gets or sets the X (first) component of the vector.
public double X { get; set; }

XAxis

#Since v5.0
Gets the value of the vector with components 1,0,0.
public static Vector3d XAxis { get; }

Y

#Since v5.0
Gets or sets the Y (second) component of the vector.
public double Y { get; set; }

YAxis

#Since v5.0
Gets the value of the vector with components 0,1,0.
public static Vector3d YAxis { get; }

Z

#Since v5.0
Gets or sets the Z (third) component of the vector.
public double Z { get; set; }

ZAxis

#Since v5.0
Gets the value of the vector with components 0,0,1.
public static Vector3d ZAxis { get; }

Zero

#Since v5.0
Gets the value of the vector with components 0,0,0.
public static Vector3d Zero { get; }

Indexers

this[]

#
Gets or sets a vector component at the given index.
public double this[
index
Index of vector component. Valid values are:

0 = X-component

1 = Y-component

2 = Z-component

.
] { get; set; }

Methods

Add

#Since v5.0
Sums up two vectors.

(Provided for languages that do not support operator overloading. You can use the + operator otherwise)

public static Vector3d Add(
vector1,
A vector.
vector2
A second vector.
)
A new vector that results from the component-wise addition of the two vectors.

AreOrthogonal

#Since v6.7
Test whether three vectors describe an orthogonal axis system. All vectors must be mutually perpendicular this to be the case.
public static bool AreOrthogonal(
x,
X axis vector.
y,
Y axis vector.
z
Z axis vector.
)
True if all vectors are non-zero and mutually perpendicular.

AreOrthonormal

#Since v6.7
Test whether three vectors describe an orthogonal, unit axis system. All vectors must be mutually perpendicular and have unit length for this to be the case.
public static bool AreOrthonormal(
x,
X axis vector.
y,
Y axis vector.
z
Z axis vector.
)
True if all vectors are non-zero and mutually perpendicular.

AreRighthanded

#Since v6.7
Test whether three vectors describe a right-handed, orthogonal, unit axis system. The vectors must be orthonormal and follow the right-hand ordering; index-finger=x, middle-finger=y, thumb=z.
public static bool AreRighthanded(
x,
X axis vector.
y,
Y axis vector.
z
Z axis vector.
)
True if all vectors are non-zero and mutually perpendicular.

CompareTo

#Since v5.0
Compares this Vector3d with another Vector3d.

Component evaluation priority is first X, then Y, then Z.

[ConstOperation] public int CompareTo(
other
The other Vector3d to use in comparison.
)

0: if this is identical to other

-1: if this.X < other.X

-1: if this.X == other.X and this.Y < other.Y

-1: if this.X == other.X and this.Y == other.Y and this.Z < other.Z

+1: otherwise.

CrossProduct

#Since v5.0
Computes the cross product (or vector product, or exterior product) of two vectors.

This operation is not commutative.

public static Vector3d CrossProduct(
a,
First vector.
b
Second vector.
)
A new vector that is perpendicular to both a and b,

has Length == a.Length * b.Length * sin(theta) where theta is the angle between a and b.

The resulting vector is oriented according to the right hand rule.

Decompose

#Since v9.0
Find scalars x and y so that the component of v in the plane of a and b is x*a + y*b
public static bool Decompose(
v,
a,
non-zero and not parallel to b
b,
non-zero and not parallel to a
out double
x,
out double
y
)
true if the decomposition is successful.

Divide

#Since v5.0
Divides a Vector3d by a number, having the effect of shrinking it.

(Provided for languages that do not support operator overloading. You can use the / operator otherwise)

public static Vector3d Divide(
vector,
A vector.
t
A number.
)
A new vector that is component-wise divided by t.

EpsilonEquals

#Since v5.4
Check that all values in other are within epsilon of the values in this
[ConstOperation] public bool EpsilonEquals(
other,
epsilon
)
EpsilonEquals

Equals

#
Determines whether the specified System.Object is a Vector3d and has the same values as the present vector.
[ConstOperation] public override bool Equals(
obj
The specified object.
)
true if obj is a Vector3d and has the same coordinates as this; otherwise false.
ValueType.Equals

Equals

#Since v5.0
Determines whether the specified vector has the same value as the present vector.
[ConstOperation] public bool Equals(
vector
The specified vector.
)
true if vector has the same coordinates as this; otherwise false.

GetHashCode

#
Computes the hash code for the current vector.
[ConstOperation] public override int GetHashCode()
A non-unique number that represents the components of this vector.

IsParallelTo

#Since v5.0
Determines whether this vector is parallel to another vector, within a provided tolerance.
[ConstOperation] public int IsParallelTo(
other,
Vector to use for comparison.
angleTolerance
Angle tolerance (in radians).
)
Parallel indicator:

+1 = both vectors are parallel.

0 = vectors are not parallel or at least one of the vectors is zero.

-1 = vectors are anti-parallel.

IsParallelTo

#ExampleSince v5.0
Determines whether this vector is parallel to another vector, within one degree (within Pi / 180).
[ConstOperation] public int IsParallelTo(
other
Vector to use for comparison.
)
Parallel indicator:

+1 = both vectors are parallel

0 = vectors are not parallel, or at least one of the vectors is zero

-1 = vectors are anti-parallel.

IsPerpendicularTo

#Since v5.0
Determines whether this vector is perpendicular to another vector, within a provided angle tolerance.
[ConstOperation] public bool IsPerpendicularTo(
other,
Vector to use for comparison.
angleTolerance
Angle tolerance (in radians).
)
true if vectors form Pi-radians (90-degree) angles with each other; otherwise false.

IsPerpendicularTo

#Since v5.0
Test to see whether this vector is perpendicular to within one degree of another one.
[ConstOperation] public bool IsPerpendicularTo(
other
Vector to compare to.
)
true if both vectors are perpendicular, false if otherwise.

IsTiny

#Since v5.0
Uses RhinoMath.ZeroTolerance for IsTiny calculation.
public bool IsTiny()
true if vector is very small, otherwise false.

IsTiny

#ExampleSince v5.0
Determines whether a vector is very short.
public bool IsTiny(
tolerance
A nonzero value used as the coordinate zero tolerance. .
)
(Math.Abs(X) <= tiny_tol) AND (Math.Abs(Y) <= tiny_tol) AND (Math.Abs(Z) <= tiny_tol).

Multiply

#Since v5.0
Multiplies two vectors together, returning the dot product (or inner product). This differs from the cross product.

(Provided for languages that do not support operator overloading. You can use the * operator otherwise)

public static double Multiply(
vector1,
A vector.
vector2
A second vector.
)
A value that results from the evaluation of v1.X*v2.X + v1.Y*v2.Y + v1.Z*v2.Z.

This value equals v1.Length * v2.Length * cos(alpha), where alpha is the angle between vectors.

Multiply

#Since v5.0
Multiplies a vector by a number, having the effect of scaling it.

(Provided for languages that do not support operator overloading. You can use the * operator otherwise)

public static Vector3d Multiply(
t,
A number.
vector
A vector.
)
A new vector that is the original vector coordinate-wise multiplied by t.

Multiply

#Since v5.0
Multiplies a vector by a number, having the effect of scaling it.

(Provided for languages that do not support operator overloading. You can use the * operator otherwise)

public static Vector3d Multiply(
vector,
A vector.
t
A number.
)
A new vector that is the original vector coordinate-wise multiplied by t.

Negate

#Since v5.0
Computes the reversed vector.

(Provided for languages that do not support operator overloading. You can use the - unary operator otherwise)

public static Vector3d Negate(
vector
A vector to negate.
)
Remarks: Similar to Reverse(), but static for CLR compliance.
A new vector where all components were multiplied by -1.

PerpendicularTo

#Since v8.0
Set this vector to be perpendicular to a plane defined by 3 points.
public bool PerpendicularTo(
point0,
The first point.
point1,
The second point.
point2
The third point.
)

PerpendicularTo

#Since v5.0
Sets this vector to be perpendicular to another vector. Result is not unitized.
public bool PerpendicularTo(
other
Vector to use as guide.
)
true on success, false if input vector is zero or invalid.

Reverse

#Since v5.0
Reverses this vector in place (reverses the direction).

If this vector is Invalid, no changes will occur and false will be returned.

public bool Reverse()
Remarks: Similar to Negate, that is only provided for CLR language compliance.
true on success or false if the vector is invalid.

Rotate

#Since v5.0
Rotates this vector around a given axis.
public bool Rotate(
angleRadians,
Angle of rotation (in radians).
rotationAxis
Axis of rotation.
)
true on success, false on failure.

Subtract

#Since v5.0
Subtracts the second vector from the first one.

(Provided for languages that do not support operator overloading. You can use the - operator otherwise)

public static Vector3d Subtract(
vector1,
A vector.
vector2
A second vector.
)
A new vector that results from the component-wise difference of vector1 - vector2.
Explicit

ICloneable.Clone

#
Explicit

IComparable.CompareTo

#
[ConstOperation] int IComparable.CompareTo(
obj
)
Explicit

ISerializable.GetObjectData

#
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] void ISerializable.GetObjectData()

ToString

#
Returns the string representation of the current vector, in the form X,Y,Z.
[ConstOperation] public override string ToString()
A string with the current location of the point.

ToString

#Since v7.0
Formats the value of the current instance using the specified format.
[ConstOperation] public string ToString(
format,
The format to use. -or- A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.
formatProvider
The provider to use to format the value. -or- A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
)
The value of the current instance in the specified format.

Transform

#Since v5.0
Transforms the vector in place.

The transformation matrix acts on the left of the vector; i.e.,

result = transformation*vector

public void Transform(
Transform
transformation
Transformation matrix to apply.
)

Unitize

#Since v5.0
Unitizes the vector in place. A unit vector has length 1 unit.

An invalid or zero length vector cannot be unitized.

public bool Unitize()
true on success or false on failure.

VectorAngle

#Since v5.0
Computes the angle on a plane between two vectors.
public static double VectorAngle(
a,
First vector.
b,
Second vector.
plane
Two-dimensional plane on which to perform the angle measurement.
)
On success, the angle (in radians) between a and b as projected onto the plane; RhinoMath.UnsetValue on failure.

VectorAngle

#Since v5.0
Compute the angle between two vectors.

This operation is commutative.

public static double VectorAngle(
a,
First vector for angle.
b
Second vector for angle.
)
If the input is valid, the angle (in radians) between a and b; RhinoMath.UnsetValue otherwise.

VectorAngle

#Since v6.0
Computes the angle of v1, v2 with a normal vector.
public static double VectorAngle(
v1,
First vector.
v2,
Second vector.
vNormal
Normal vector.
)
On success, the angle (in radians) between a and b with respect of normal vector; RhinoMath.UnsetValue on failure.

Operators

OperationResultDescription
Vector3d+Vector3dVector3dSums up two vectors.
Vector3d/doubleVector3dDivides a Vector3d by a number, having the effect of shrinking it.
Vector3d==Vector3dboolDetermines whether two vectors have the same value.
Vector3d>Vector3dboolDetermines whether the first specified vector comes after (has superior sorting value than) the second vector.

Components evaluation priority is first X, then Y, then Z.

Vector3d>=Vector3dboolDetermines whether the first specified vector comes after (has superior sorting value than) the second vector, or it is equal to it.

Components evaluation priority is first X, then Y, then Z.

Vector3d!=Vector3dboolDetermines whether two vectors have different values.
Vector3d<Vector3dboolDetermines whether the first specified vector comes before (has inferior sorting value than) the second vector.

Components evaluation priority is first X, then Y, then Z.

Vector3d<=Vector3dboolDetermines whether the first specified vector comes before (has inferior sorting value than) the second vector, or it is equal to it.

Components evaluation priority is first X, then Y, then Z.

Vector3d*Vector3ddoubleMultiplies two vectors together, returning the dot product (or inner product). This differs from the cross product.
double*Vector3dVector3dMultiplies a vector by a number, having the effect of scaling it.
Vector3d*doubleVector3dMultiplies a vector by a number, having the effect of scaling it.
Vector3d-Vector3dVector3dSubtracts the second vector from the first one.
-Vector3dVector3dComputes the opposite vector.

Convertors

OperationResultDescription
implicitVector3fVector3dConverts a single-precision (float) vector in a double-precision vector, without needing casting.