Struct Vector3
Defines a Vector in Euclidean space with coordinates X, Y, and Z. Referenced from https://github.com/mcneel/rhinocommon/blob/master/dotnet/opennurbs/opennurbs_point.cs
public struct Vector3 : IEquatable<Vector3>, IComparable<Vector3>, IComparable
Initializes a new instance of a vector, copying the three components from the three coordinates of a point.
public Vector3(Point3 point)
Type | Name | Description |
---|---|---|
Point3 | point | The point to copy from. |
Initializes a new instance of a vector, copying the three components from a vector.
public Vector3(Vector3 vector)
Type | Name | Description |
---|---|---|
Vector3 | vector | A double-precision vector. |
Initializes a new instance of a vector, using its three components.
public Vector3(double x, double y, double z)
Type | Name | Description |
---|---|---|
System.Double | x | The X (first) component. |
System.Double | y | The Y (second) component. |
System.Double | z | The Z (third) component. |
Gets a value indicating whether or not this is a unit vector. A unit vector has length 1.
public readonly bool IsUnitVector { get; }
Type | Description |
---|---|
System.Boolean |
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 readonly bool IsValid { get; }
Type | Description |
---|---|
System.Boolean |
Gets a value indicating whether the X, Y, and Z values are all equal to 0.0.
public readonly bool IsZero { get; }
Type | Description |
---|---|
System.Boolean |
public double this[int i] { get; set; }
Type | Name | Description |
---|---|---|
System.Int32 | i |
Type | Description |
---|---|
System.Double |
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 readonly double Length { get; }
Type | Description |
---|---|
System.Double |
Dimension of vector.
public readonly int Size { get; }
Type | Description |
---|---|
System.Int32 |
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 readonly double SquareLength { get; }
Type | Description |
---|---|
System.Double |
Gets the value of the vector with each component set to GeoSharkMath.UNSET_VALUE.
public static readonly Vector3 Unset { get; }
Type | Description |
---|---|
Vector3 |
Gets or sets the X (first) component of the vector.
public double X { readonly get; set; }
Type | Description |
---|---|
System.Double |
Gets the value of the vector with components 1,0,0.
public static readonly Vector3 XAxis { get; }
Type | Description |
---|---|
Vector3 |
Gets or sets the Y (second) component of the vector.
public double Y { readonly get; set; }
Type | Description |
---|---|
System.Double |
Gets the value of the vector with components 0,1,0.
public static readonly Vector3 YAxis { get; }
Type | Description |
---|---|
Vector3 |
Gets or sets the Z (third) component of the vector.
public double Z { readonly get; set; }
Type | Description |
---|---|
System.Double |
Gets the value of the vector with components 0,0,1.
public static readonly Vector3 ZAxis { get; }
Type | Description |
---|---|
Vector3 |
Gets the value of the vector with components 0,0,0.
public static readonly Vector3 Zero { get; }
Type | Description |
---|---|
Vector3 |
Gets a new amplified vector by unitizing and uniformly scaling this vector by the amplitude value.
public Vector3 Amplify(double amplitude)
Type | Name | Description |
---|---|---|
System.Double | amplitude | The scalar value to amplify the vector. |
Type | Description |
---|---|
Vector3 | The amplified vector. |
Compares this Vector3 with another Vector3.
Component evaluation priority is first X, then Y, then Z.
public int CompareTo(Vector3 other)
Type | Name | Description |
---|---|---|
Vector3 | other | The other Vector3 to use in comparison. |
Type | Description |
---|---|
System.Int32 | 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. |
Computes the cross product (or vector product, or exterior product) of two vectors.
This operation is not commutative.
public static Vector3 CrossProduct(Vector3 a, Vector3 b)
Type | Name | Description |
---|---|---|
Vector3 | a | First vector. |
Vector3 | b | Second vector. |
Type | Description |
---|---|
Vector3 | A new vector that is perpendicular to both a and b, has Length == a.Length * b.Length and with a result that is oriented following the right hand rule. |
Computes the dot product between two vectors.
public static double DotProduct(Vector3 vector1, Vector3 vector2)
Type | Name | Description |
---|---|---|
Vector3 | vector1 | The first vector. |
Vector3 | vector2 | The second vector with which compute the dot product. |
Type | Description |
---|---|
System.Double | The dot product. |
public bool EpsilonEquals(Vector3 vector, double epsilon)
Type | Name | Description |
---|---|---|
Vector3 | vector | |
System.Double | epsilon |
Type | Description |
---|---|
System.Boolean |
Determines whether the specified vector has the same value as the present vector.
public bool Equals(Vector3 vector)
Type | Name | Description |
---|---|---|
Vector3 | vector | The specified vector. |
Type | Description |
---|---|
System.Boolean | true if vector has the same coordinates as this; otherwise false. |
Determines whether the specified System.Object is a Vector3d and has the same values as the present vector.
public override bool Equals(object obj)
Type | Name | Description |
---|---|---|
System.Object | obj | The specified object. |
Type | Description |
---|---|
System.Boolean | true if obj is a Vector3d and has the same coordinates as this; otherwise false. |
Computes the hash code for the current vector.
public override int GetHashCode()
Type | Description |
---|---|
System.Int32 | A non-unique number that represents the components of this vector. |
Determines whether this vector is parallel to another vector, within a provided tolerance.
public int IsParallelTo(Vector3 other, double angleTolerance = 0.0174532925199433)
Type | Name | Description |
---|---|---|
Vector3 | other | Vector to use for comparison. |
System.Double | angleTolerance | Angle tolerance (in radians). |
Type | Description |
---|---|
System.Int32 | 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. |
Determines whether this vector is perpendicular to another vector, within a provided angle tolerance.
public bool IsPerpendicularTo(Vector3 other, double angleTolerance = 0.0174532925199433)
Type | Name | Description |
---|---|---|
Vector3 | other | Vector to use for comparison. |
System.Double | angleTolerance | Angle tolerance (in radians). |
Type | Description |
---|---|
System.Boolean | true if vectors form Pi-radians (90-degree) angles with each other; otherwise false. |
Computes the perpendicular of a vector given three points.
Result is not unitized.
public Vector3 PerpendicularTo(Point3 pt1, Point3 pt2, Point3 pt3)
Type | Name | Description |
---|---|---|
Point3 | pt1 | First point. |
Point3 | pt2 | Second point. |
Point3 | pt3 | Third point. |
Type | Description |
---|---|
Vector3 | The perpendicular vector. |
Computes the perpendicular to another vector.
https://stackoverflow.com/questions/11132681/what-is-a-formula-to-get-a-vector-perpendicular-to-another-vector
Result is not unitized.
public static Vector3 PerpendicularTo(Vector3 vector)
Type | Name | Description |
---|---|---|
Vector3 | vector | The other vector. |
Type | Description |
---|---|
Vector3 | The perpendicular vector. |
Reverses (inverts) this vector in place.
If this vector is Invalid, no changes will occur and false will be returned.
public Vector3 Reverse()
Type | Description |
---|---|
Vector3 | Returns a reversed vector on success or Vector3d.Unset if the vector is invalid. |
Rotates this vector around a given axis.
The rotation is computed using Rodrigues Rotation formula.
https://handwiki.org/wiki/Rodrigues%27_rotation_formula
public Vector3 Rotate(Vector3 axis, double radiansAngle)
Type | Name | Description |
---|---|---|
Vector3 | axis | Axis of rotation. |
System.Double | radiansAngle | Angle of rotation (in radians). |
Type | Description |
---|---|
Vector3 | Rotated vector. |
Returns the string representation of the current vector, in the form X,Y,Z.
public override string ToString()
Type | Description |
---|---|
System.String | A string with the current location of the point. |
The triple product of this vector and the two specified vectors.
public double TripleProduct(Vector3 middle, Vector3 right)
Type | Name | Description |
---|---|---|
Vector3 | middle | The second vector. |
Vector3 | right | The third vector. |
Type | Description |
---|---|
System.Double | The real number equal to the triple product. |
The scalar triple product is defined as the dot product of one of the vectors with the cross product of the other two. Geometrically, this product is the (signed) volume of the parallelepiped formed by the three vectors given.
Unitizes the vector. A unit vector has length 1 unit.
public Vector3 Unitize()
Type | Description |
---|---|
Vector3 | A new vector unitized. |
Compute the angle in radians between two vectors.
This operation is commutative.
public static double VectorAngle(Vector3 a, Vector3 b)
Type | Name | Description |
---|---|---|
Vector3 | a | First vector for angle. |
Vector3 | b | Second vector for angle. |
Type | Description |
---|---|
System.Double | If the input is valid, the angle in radians between a and b; GeoSharkMath.UNSET_VALUE otherwise. |
Computes the angle in radians on a plane between two vectors.
public static double VectorAngleOnPlane(Vector3 a, Vector3 b, Plane plane, out double reflexAngle)
Type | Name | Description |
---|---|---|
Vector3 | a | First vector. |
Vector3 | b | Second vector. |
Plane | plane | Two-dimensional plane on which to perform the angle measurement. |
System.Double | reflexAngle |
Type | Description |
---|---|
System.Double | On success, the angle (in radians) between a and b as projected onto the plane; GeoSharkMath.UNSET_VALUE on failure. |
Sums up two vectors.
public static Vector3 operator +(Vector3 vector1, Vector3 vector2)
Type | Name | Description |
---|---|---|
Vector3 | vector1 | A vector. |
Vector3 | vector2 | A second vector. |
Type | Description |
---|---|
Vector3 | A new vector that results from the componentwise addition of the two vectors. |
Divides a Vector3 by a number, having the effect of shrinking it.
public static Vector3 operator /(Vector3 vector, double t)
Type | Name | Description |
---|---|---|
Vector3 | vector | A vector. |
System.Double | t | A number. |
Type | Description |
---|---|
Vector3 | A new vector that is componentwise divided by t. |
Determines whether two vectors have the same value.
public static bool operator ==(Vector3 a, Vector3 b)
Type | Name | Description |
---|---|---|
Vector3 | a | A vector. |
Vector3 | b | Another vector. |
Type | Description |
---|---|
System.Boolean | true if all coordinates are pairwise equal; false otherwise. |
Determines 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.
public static bool operator>(Vector3 a, Vector3 b)
Type | Name | Description |
---|---|---|
Vector3 | a | The first vector. |
Vector3 | b | The second vector. |
Type | Description |
---|---|
System.Boolean | true if a.X is larger than b.X, or a.X == b.X and a.Y is larger than b.Y, or a.X == b.X and a.Y == b.Y and a.Z is larger than b.Z; otherwise, false. |
Determines 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.
public static bool operator >=(Vector3 a, Vector3 b)
Type | Name | Description |
---|---|---|
Vector3 | a | The first vector. |
Vector3 | b | The second vector. |
Type | Description |
---|---|
System.Boolean | true if a.X is larger than b.X, or a.X == b.X and a.Y is larger than b.Y, or a.X == b.X and a.Y == b.Y and a.Z >= b.Z; otherwise, false. |
Converts a vector3d in a point3d, without needing casting.
public static implicit operator Point3(Vector3 vector3d)
Type | Name | Description |
---|---|---|
Vector3 | vector3d | A Vector3d. |
Type | Description |
---|---|
Point3 | The resulting Point3d. |
Converts a vector3d in a vector3, without needing casting.
public static implicit operator Vector(Vector3 vector3d)
Type | Name | Description |
---|---|---|
Vector3 | vector3d | A Vector3d. |
Type | Description |
---|---|
Vector | The resulting Vector3. |
Determines whether two vectors have different values.
public static bool operator !=(Vector3 a, Vector3 b)
Type | Name | Description |
---|---|---|
Vector3 | a | A vector. |
Vector3 | b | Another vector. |
Type | Description |
---|---|
System.Boolean | true if any coordinate pair is different; false otherwise. |
Determines 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.
public static bool operator <(Vector3 a, Vector3 b)
Type | Name | Description |
---|---|---|
Vector3 | a | The first vector. |
Vector3 | b | The second vector. |
Type | Description |
---|---|
System.Boolean | true if a.X is smaller than b.X, or a.X == b.X and a.Y is smaller than b.Y, or a.X == b.X and a.Y == b.Y and a.Z is smaller than b.Z; otherwise, false. |
Determines 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.
public static bool operator <=(Vector3 a, Vector3 b)
Type | Name | Description |
---|---|---|
Vector3 | a | The first vector. |
Vector3 | b | The second vector. |
Type | Description |
---|---|
System.Boolean | true if a.X is smaller than b.X, or a.X == b.X and a.Y is smaller than b.Y, or a.X == b.X and a.Y == b.Y and a.Z <= b.Z; otherwise, false. |
Multiplies two vectors together, returning the dot product (or inner product). This differs from the cross product.
public static double operator *(Vector3 vector1, Vector3 vector2)
Type | Name | Description |
---|---|---|
Vector3 | vector1 | A vector. |
Vector3 | vector2 | A second vector. |
Type | Description |
---|---|
System.Double | A value that results from the evaluation of v1.Xv2.X + v1.Yv2.Y + v1.Z*v2.Z. This value equals v1.Length * v2.Length * cos(alpha), where alpha is the angle between vectors. |
Multiplies a vector by a number, having the effect of scaling it.
public static Vector3 operator *(Vector3 vector, double t)
Type | Name | Description |
---|---|---|
Vector3 | vector | A vector. |
System.Double | t | A number. |
Type | Description |
---|---|
Vector3 | A new vector that is the original vector coordinatewise multiplied by t. |
Multiplies a vector by a number, having the effect of scaling it.
public static Vector3 operator *(double t, Vector3 vector)
Type | Name | Description |
---|---|---|
System.Double | t | A number. |
Vector3 | vector | A vector. |
Type | Description |
---|---|
Vector3 | A new vector that is the original vector coordinatewise multiplied by t. |
Subtracts the second vector from the first one.
public static Vector3 operator -(Vector3 vector1, Vector3 vector2)
Type | Name | Description |
---|---|---|
Vector3 | vector1 | A vector. |
Vector3 | vector2 | A second vector. |
Type | Description |
---|---|
Vector3 | A new vector that results from the componentwise difference of vector1 - vector2. |
Computes the reversed vector.
public static Vector3 operator -(Vector3 vector)
Type | Name | Description |
---|---|---|
Vector3 | vector | A vector to negate. |
Type | Description |
---|---|
Vector3 | A new vector where all components were multiplied by -1. |
int IComparable.CompareTo(object obj)
Type | Name | Description |
---|---|---|
System.Object | obj |
Type | Description |
---|---|
System.Int32 |