Struct vec3d_t
Basic 3D point (or vector): a sequential-layout value type with mutable fields (the mirror of
the C++ geom::vec3<double>, 24 bytes). It has no in-place mutating method: write a
component through x/y/z, X/Y/Z
or the indexer on a variable, field or array element (never on a property, which hands out a copy),
or build a new value with WithAt(int, double) and the Get* family.
public struct vec3d_t : IEquatable<vec3d_t>, IExpandToBox3d, IWriteBin, ICsvRowIo, IEqualityOperators<vec3d_t, vec3d_t, bool>, IAdditionOperators<vec3d_t, vec3d_t, vec3d_t>, ISubtractionOperators<vec3d_t, vec3d_t, vec3d_t>, IMultiplyOperators<vec3d_t, double, vec3d_t>, IMultiplyOperators<vec3d_t, Mat4d, vec3d_t>, IDivisionOperators<vec3d_t, double, vec3d_t>, IVec<double>, IFormattable, IToPresentDto
- Implements
- Inherited Members
- Extension Methods
Constructors
vec3d_t(Polar3d)
Ctor.
public vec3d_t(Polar3d src)
Parameters
srcPolar3dsrc
vec3d_t(vec2d_t, double)
Initializes a new instance of the vec3d_t class from a 2D vector and z coordinate.
public vec3d_t(vec2d_t xy, double z)
Parameters
vec3d_t(vec3d_t)
Copy ctor.
public vec3d_t(vec3d_t src)
Parameters
srcvec3d_tsrc
vec3d_t(vec3f_t)
ctor.
public vec3d_t(vec3f_t src)
Parameters
srcvec3f_tsrc
vec3d_t(IEnumerable<double>)
Creates a vector from an enumerable collection of three double values.
public vec3d_t(IEnumerable<double> src)
Parameters
srcIEnumerable<double>Source collection containing three double values
vec3d_t(double, double, double)
Ctor.
public vec3d_t(double x, double y, double z)
Parameters
vec3d_t(Func<int, double>)
Creates a vector using a function that maps direction index to value.
public vec3d_t(Func<int, double> dirToValueFunc)
Parameters
dirToValueFuncFunc<int, double>Function that takes direction index (0=X, 1=Y, 2=Z) and returns the corresponding value
vec3d_t(BinaryReader)
Ctor by bytes: x = reader.ReadDouble(); y = reader.ReadDouble(); z = reader.ReadDouble();
public vec3d_t(BinaryReader reader)
Parameters
readerBinaryReaderreader
vec3d_t(int, double, double, double)
Ctor by direction offset. Direction 0,1,2 indicate x,y,z respectively.
public vec3d_t(int dir, double a, double b, double c)
Parameters
dirintdirection offset
adoublevalue at direction (0+dir)%3
bdoublevalue at direction (1+dir)%3
cdoublevalue at direction (2+dir)%3
vec3d_t(string)
Ctor by string. The format is (x,y,z).
public vec3d_t(string src)
Parameters
srcstringsrc
vec3d_t((double, double, double))
Ctor.
public vec3d_t((double, double, double) src)
Parameters
Fields
x
Value at x direction.
public double x
Field Value
y
Value at y direction.
public double y
Field Value
z
Value at z direction.
public double z
Field Value
Properties
AbsSum
public readonly double AbsSum { get; }
Property Value
- double
Sum of the abs {x,y,z}. Which is Math.Abs(x) + Math.Abs(y) + Math.Abs(z).
AllOne
public static vec3d_t AllOne { get; }
Property Value
CsvText
Csv text.
public readonly string CsvText { get; }
Property Value
CsvTitleText
Csv titles text.
public readonly string CsvTitleText { get; }
Property Value
ElementNum
Element number: 3 for (x,y,z).
public static int ElementNum { get; }
Property Value
IsAllFinite
public readonly bool IsAllFinite { get; }
Property Value
- bool
Is x,y,z all finite.
IsAllNaN
public readonly bool IsAllNaN { get; }
Property Value
IsAllNegativeInfinity
public readonly bool IsAllNegativeInfinity { get; }
Property Value
- bool
is x,y,z all NegativeInfinity.
IsAllPositiveInfinity
public readonly bool IsAllPositiveInfinity { get; }
Property Value
- bool
is x,y,z all PositiveInfinity.
IsAnyFinite
public readonly bool IsAnyFinite { get; }
Property Value
- bool
Is at least one of x,y,z finite.
IsAnyNaN
public readonly bool IsAnyNaN { get; }
Property Value
IsZero
public readonly bool IsZero { get; }
Property Value
- bool
Is zero vector. Which is
x == 0 && y == 0 && z == 0.
this[int]
Gets the element at the specified index. Writing goes through the concrete type's indexer or fields, never through this interface: a struct behind an interface is a boxed copy.
public double this[int dir] { readonly get; set; }
Parameters
dirint
Property Value
- double
The element at the specified index.
Length
public readonly double Length { get; }
Property Value
- double
Geometry length of this.
LengthSquare
public readonly double LengthSquare { get; }
Property Value
- double
Geometry length ^ 2. Which is
x * x + y * y + z * z.
MaxAbsDir
public readonly int MaxAbsDir { get; }
Property Value
- int
Get the direction index with maximum absolute value. If the absolute of {x,y,z} is the biggest, return {0,1,2}.
MaxDir
public readonly int MaxDir { get; }
Property Value
- int
Get the direction index with maximum value. If {x,y,z} is the biggest, return {0,1,2}.
MaxValue
public readonly double MaxValue { get; }
Property Value
- double
The max value selected from {x,y,z}. Which is
Math.Max(Math.Max(x, y), z).
MinDir
public readonly int MinDir { get; }
Property Value
- int
Get the direction index with maximum value. If {x,y,z} is the biggest, return {0,1,2}.
MinValue
public readonly double MinValue { get; }
Property Value
- double
The min value selected from {x,y,z}. Which is
Math.Min(Math.Min(x, y), z).
NaN
public static vec3d_t NaN { get; }
Property Value
NativeByteSize
public static int NativeByteSize { get; }
Property Value
- int
Byte size of the struct as core.dll sees it:
sizeof(vec3d_t), three doubles.
NegativeInfinity
public static vec3d_t NegativeInfinity { get; }
Property Value
PositiveInfinity
public static vec3d_t PositiveInfinity { get; }
Property Value
Rank
Dimension (i.e. Size) of the Vector.
public readonly int Rank { get; }
Property Value
UnitX
public static vec3d_t UnitX { get; }
Property Value
UnitY
public static vec3d_t UnitY { get; }
Property Value
UnitZ
public static vec3d_t UnitZ { get; }
Property Value
X
Value at x direction.
public double X { readonly get; set; }
Property Value
XY
public vec2d_t XY { readonly get; set; }
Property Value
Y
Value at y direction.
public double Y { readonly get; set; }
Property Value
Z
Value at z direction.
public double Z { readonly get; set; }
Property Value
Zero
public static vec3d_t Zero { get; }
Property Value
Methods
All(double)
Creates a vector with all components set to the specified value.
public static vec3d_t All(double v)
Parameters
vdoubleValue to set for all components
Returns
- vec3d_t
A new vector with all components set to the specified value
At(int)
Get the value at the dirction. Direction 0,1,2 are x,y,z. If direction index is larger than 2, the return value is at z direction.
public readonly double At(int dir)
Parameters
dirintdirection index
Returns
- double
value at the direction
BilinearInterpolate(vec3d_t, vec3d_t, vec3d_t, vec3d_t, double, double)
Performs bilinear interpolation between four points.
public static vec3d_t BilinearInterpolate(vec3d_t p00, vec3d_t p01, vec3d_t p10, vec3d_t p11, double u, double v)
Parameters
p00vec3d_tPoint at (0,0)
p01vec3d_tPoint at (0,1)
p10vec3d_tPoint at (1,0)
p11vec3d_tPoint at (1,1)
udoubleInterpolation parameter in first dimension (0.0 to 1.0)
vdoubleInterpolation parameter in second dimension (0.0 to 1.0)
Returns
- vec3d_t
The interpolated point
Cross(vec3d_t, vec3d_t)
Get a cross b.
public static vec3d_t Cross(vec3d_t a, vec3d_t b)
Parameters
Returns
- vec3d_t
a x b
Dot(vec3d_t)
this dot src.
public readonly double Dot(vec3d_t src)
Parameters
srcvec3d_tsrc
Returns
- double
dotted value
Enumerate()
Enumerates the components of the vector.
public readonly IEnumerable<double> Enumerate()
Returns
- IEnumerable<double>
An enumerable sequence of the vector's components (X, Y, Z)
Equals(vec3d_t)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(vec3d_t other)
Parameters
othervec3d_tAn object to compare with this object.
Returns
Equals(vec3d_t, double)
check equals for each component with tolerance.
public readonly bool Equals(vec3d_t other, double toleranceForEachComponent)
Parameters
Returns
- bool
check equals for each component with tolerance.
Equals(object)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
ExpandToBox3d(ref box3d_t)
Expands the destination box.
This function is usually used to compute the bounding box of elements.
box3d_t is a value type, so the destination is passed by reference
(the C++ expand_to_box3d(box3&) shape); an implementation writes
dst = dst.Expanded(...) or forwards ref dst to its parts.
public readonly void ExpandToBox3d(ref box3d_t dst)
Parameters
dstbox3d_tDestination box, expanded in place
GetCosSquareWith(vec3d_t)
Get Cos(theta)^2. theta is the angle between this and src.
This function is faster than GetCosWith(vec3d_t) since it lacks one square root operation.
public readonly double GetCosSquareWith(vec3d_t src)
Parameters
srcvec3d_tone of edge vector
Returns
- double
Cos(theta)^2
GetCosWith(vec3d_t)
Get Cos(theta). theta is the angle between this and v.
public readonly double GetCosWith(vec3d_t v)
Parameters
vvec3d_ta vector
Returns
- double
Cos(theta)
GetCross(vec3d_t)
Get this cross src.
public readonly vec3d_t GetCross(vec3d_t src)
Parameters
srcvec3d_tsrc
Returns
GetCsvText(string)
Gets the CSV text representation of this vector with the specified format.
public readonly string GetCsvText(string format)
Parameters
formatstringFormat string for the double values
Returns
- string
CSV formatted string
GetEachNanToZero()
Creates a new vector with each NaN component replaced by 0.
public readonly vec3d_t GetEachNanToZero()
Returns
- vec3d_t
A new vector with NaN components set to 0
GetEachValueAbs()
Creates a new vector with the absolute value of each component.
public readonly vec3d_t GetEachValueAbs()
Returns
- vec3d_t
A new vector with absolute values of each component
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetMulEach(vec3d_t)
Creates a new vector by multiplying each component of this vector with the corresponding component of another vector.
public readonly vec3d_t GetMulEach(vec3d_t vec)
Parameters
vecvec3d_tThe vector to multiply with
Returns
- vec3d_t
A new vector with component-wise multiplication results
GetMulWithoutTrans(Mat4d)
Get a new object by this*mat without translation part.
public readonly vec3d_t GetMulWithoutTrans(Mat4d mat)
Parameters
matMat4dtransform matrix
Returns
- vec3d_t
new vec3d_t(x * mat.At(0, 0) + y * mat.At(1, 0) + z * mat.At(2, 0) , x* mat.At(0, 1) + y* mat.At(1, 1) + z* mat.At(2, 1) , x* mat.At(0, 2) + y* mat.At(1, 2) + z* mat.At(2, 2))
GetNormalized()
Generate normalized vec.
public readonly vec3d_t GetNormalized()
Returns
- vec3d_t
Normalized vec
GetRadian(vec3d_t)
Get angle between this and v.
The angle has no sign.
This vector is not required to be an unit vector.
public readonly double GetRadian(vec3d_t v)
Parameters
vvec3d_tone of the edge vector. Not required to be an unit vector.
Returns
- double
Angle in radian
GetRadian(vec3d_t, vec3d_t)
Get angle between this and v.
This function applies normal vector to determine the sign of angle.
This vector is not required to be an unit vector.
public readonly double GetRadian(vec3d_t v, vec3d_t n)
Parameters
vvec3d_tvector of ending edge. Not required to be an unit vector.
nvec3d_tnormal vector. Not required to be an unit vector.
Returns
- double
angle in radian
GetRadianByUnitVector(vec3d_t)
Get angle between this and v.
The angle has no sign.
This vector is not required to be an unit vector.
Both this and v should be unit vector.
Much efficient than GetRadian(vec3d_t).
public readonly double GetRadianByUnitVector(vec3d_t v)
Parameters
vvec3d_tone of the edge vector. Not required to be an unit vector.
Returns
- double
Angle in radian
GetTransform(Func<double, double>)
Get the new vec3d_t by transforming each element by the function.
public readonly vec3d_t GetTransform(Func<double, double> transformingFunc)
Parameters
Returns
GetVec2dByPlaneDir(int)
Gets a 2D vector by projecting the 3D vector onto a plane.
public readonly vec2d_t GetVec2dByPlaneDir(int dir)
Parameters
dirintDirection index: 0 for YZ plane, 1 for ZX plane, 2 for XY plane
Returns
- vec2d_t
A 2D vector representing the projection
GetXRotation(double)
public readonly vec3d_t GetXRotation(double rad)
Parameters
raddoublerotation radian
Returns
GetYRotation(double)
public readonly vec3d_t GetYRotation(double rad)
Parameters
raddoublerotation radian
Returns
GetZRotation(double)
public readonly vec3d_t GetZRotation(double rad)
Parameters
raddoublerotation radian
Returns
Interpolate(vec3d_t, vec3d_t, double)
Interpolate from a to b with ratio alpha:(1-alpha).
public static vec3d_t Interpolate(vec3d_t a, vec3d_t b, double alpha)
Parameters
Returns
- vec3d_t
a * (1 - alpha) + b * alpha
IsNormalized(double)
Checks if the vector is normalized (has a length of approximately 1).
public readonly bool IsNormalized(double toleranceSquare = 1E-07)
Parameters
toleranceSquaredoubleSquare of the tolerance value for comparing with 1 (default: 1e-7)
Returns
- bool
True if the vector is normalized within the specified tolerance
Parse(string)
Parses the “(x,y,z)” form through vec3d_t(string); a string that does not carry three components throws FormatException. There is no null answer: use TryParse(string, out vec3d_t) for a non-throwing form (NaN on failure).
public static vec3d_t Parse(string src)
Parameters
srcstringsrc
Returns
ParseByCsv(string)
Parses a vector from a CSV text string.
public static vec3d_t ParseByCsv(string csvText)
Parameters
csvTextstringCSV formatted string containing vector components
Returns
- vec3d_t
A new vector parsed from the CSV text
ReadBin(BinaryReader)
Reads a vector written by WriteBin(BinaryWriter): three doubles x, y, z.
public static vec3d_t ReadBin(BinaryReader reader)
Parameters
readerBinaryReaderreader
Returns
- vec3d_t
the vector read
ToArray()
return new double[] { x, y, z }
public readonly double[] ToArray()
Returns
- double[]
{ x, y, z }
ToBuf(double[])
Set x,y,z to the dst array.
public readonly void ToBuf(double[] dst)
Parameters
dstdouble[]dst
ToBuf(double[], ref int)
Set x,y,z to the dst array from postion p and increase p by the pushed number.
public readonly int ToBuf(double[] dst, ref int p)
Parameters
Returns
- int
- Which is pushed number of double
ToPresentDto()
Convert vec3d_t to presentation DTO (Data Transfer Object) for JSON serialization. The returned object includes type metadata for web API presentation.
public readonly object ToPresentDto()
Returns
- object
DTO dictionary with Type, x, y, z keys
ToString()
To representative string with format:(x,y,z).
public override readonly string ToString()
Returns
- string
Representative string
ToString(string)
To string with format: (x,y,z)
public readonly string ToString(string format)
Parameters
formatstringformat of ToString(string)
Returns
- string
Representative string
ToString(string, IFormatProvider)
Returns a string representation of the vector formatted according to the specified format.
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
formatstringThe format to use for each component
formatProviderIFormatProviderThe format provider to use
Returns
- string
A formatted string representation of the vector
ToString(string, int)
Converts the vector to a string with the specified format and left padding.
public readonly string ToString(string format, int leftPadding)
Parameters
formatstringFormat string for the double values
leftPaddingintNumber of characters to pad on the left of each value
Returns
- string
Formatted string representation of the vector
TryParse(string, out vec3d_t)
Attempts to parse a string into a vec3d_t.
public static bool TryParse(string src, out vec3d_t dst)
Parameters
srcstringThe string to parse in format “(x,y,z)”
dstvec3d_tWhen this method returns, contains the vec3d_t value if parsing succeeded, or NaN if parsing failed (as TryParseLoose(string, out vec3d_t) does)
Returns
- bool
true if parsing succeeded; otherwise, false
TryParseLoose(string, out vec3d_t)
Attempts to parse a string into a vec3d_t using a loose format. Accepts various delimiters (comma, semicolon, space) and removes brackets/parentheses.
public static bool TryParseLoose(string text, out vec3d_t dst)
Parameters
textstringThe string to parse. Can contain brackets, parentheses, or other delimiters.
dstvec3d_tWhen this method returns, contains the parsed vec3d_t if successful, or vec3d_t.NaN if parsing failed.
Returns
- bool
True if parsing was successful; otherwise, false.
WithAt(int, double)
Creates a copy of this vector with the component at dir replaced by value.
Direction 0,1,2 are x,y,z; a larger index addresses z, as At(int) does.
public readonly vec3d_t WithAt(int dir, double value)
Parameters
Returns
- vec3d_t
the modified copy
WriteBin(BinaryWriter)
Output to bytes: writer.Write(x); writer.Write(y); writer.Write(z);
public readonly void WriteBin(BinaryWriter writer)
Parameters
writerBinaryWriterwriter
Operators
operator +(vec3d_t, vec3d_t)
Plus.
public static vec3d_t operator +(vec3d_t left, vec3d_t right)
Parameters
Returns
- vec3d_t
new vec3d_t(a.x + b.x, a.y + b.y, a.z + b.z)
operator /(vec3d_t, double)
Get a new object from a scaled by 1/d.
public static vec3d_t operator /(vec3d_t a, double d)
Parameters
Returns
operator ==(vec3d_t, vec3d_t)
Equality operator for comparing two vec3d_t objects.
public static bool operator ==(vec3d_t left, vec3d_t right)
Parameters
Returns
- bool
True if the vectors are equal, false otherwise
operator !=(vec3d_t, vec3d_t)
Inequality operator for comparing two vec3d_t objects.
public static bool operator !=(vec3d_t left, vec3d_t right)
Parameters
Returns
- bool
True if the vectors are not equal, false otherwise
operator *(vec3d_t, Mat4d)
Get p*src.
public static vec3d_t operator *(vec3d_t p, Mat4d src)
Parameters
Returns
- vec3d_t
new vec3d_t(p.x * src.At(0, 0) + p.y * src.At(1, 0) + p.z * src.At(2, 0) + src.At(3, 0) , p.x* src.At(0, 1) + p.y* src.At(1, 1) + p.z* src.At(2, 1) + src.At(3, 1) , p.x* src.At(0, 2) + p.y* src.At(1, 2) + p.z* src.At(2, 2) + src.At(3, 2))
operator *(vec3d_t, double)
Scale a by s.
public static vec3d_t operator *(vec3d_t a, double s)
Parameters
Returns
- vec3d_t
new vec3d_t(a.x * s, a.y * s, a.z * s)
operator -(vec3d_t, vec3d_t)
Minus.
public static vec3d_t operator -(vec3d_t a, vec3d_t b)
Parameters
Returns
- vec3d_t
new vec3d_t(a.x - b.x, a.y - b.y, a.z - b.z)
operator -(vec3d_t)
Get negate vector.
public static vec3d_t operator -(vec3d_t src)
Parameters
srcvec3d_tsrc
Returns
- vec3d_t
new vec3d_t(-src.x, -src.y, -src.z)