Table of Contents

Struct vec3d_t

Namespace
Hi.Geom
Assembly
HiGeom.dll

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

src Polar3d

src

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

xy vec2d_t

The 2D vector providing x and y coordinates.

z double

The z coordinate.

vec3d_t(vec3d_t)

Copy ctor.

public vec3d_t(vec3d_t src)

Parameters

src vec3d_t

src

vec3d_t(vec3f_t)

ctor.

public vec3d_t(vec3f_t src)

Parameters

src vec3f_t

src

vec3d_t(IEnumerable<double>)

Creates a vector from an enumerable collection of three double values.

public vec3d_t(IEnumerable<double> src)

Parameters

src IEnumerable<double>

Source collection containing three double values

vec3d_t(double, double, double)

Ctor.

public vec3d_t(double x, double y, double z)

Parameters

x double

x

y double

y

z double

z

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

dirToValueFunc Func<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

reader BinaryReader

reader

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

dir int

direction offset

a double

value at direction (0+dir)%3

b double

value at direction (1+dir)%3

c double

value at direction (2+dir)%3

vec3d_t(string)

Ctor by string. The format is (x,y,z).

public vec3d_t(string src)

Parameters

src string

src

vec3d_t((double, double, double))

Ctor.

public vec3d_t((double, double, double) src)

Parameters

src (double, double, double)

src

Fields

x

Value at x direction.

public double x

Field Value

double

y

Value at y direction.

public double y

Field Value

double

z

Value at z direction.

public double z

Field Value

double

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

vec3d_t

Generate vec3d_t(1, 1, 1).

CsvText

Csv text.

public readonly string CsvText { get; }

Property Value

string

CsvTitleText

Csv titles text.

public readonly string CsvTitleText { get; }

Property Value

string

ElementNum

Element number: 3 for (x,y,z).

public static int ElementNum { get; }

Property Value

int

IsAllFinite

public readonly bool IsAllFinite { get; }

Property Value

bool

Is x,y,z all finite.

IsAllNaN

public readonly bool IsAllNaN { get; }

Property Value

bool

is x,y,z all NaN.

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

bool

Is any of {x,y,z} NaN.

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

dir int

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

vec3d_t

Generate vec3d_t(double.NaN, double.NaN, double.NaN).

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

vec3d_t

Generate vec3d_t(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity)

PositiveInfinity

public static vec3d_t PositiveInfinity { get; }

Property Value

vec3d_t

Generate vec3d_t(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)

Rank

Dimension (i.e. Size) of the Vector.

public readonly int Rank { get; }

Property Value

int

UnitX

public static vec3d_t UnitX { get; }

Property Value

vec3d_t

Generate vec3d_t(1, 0, 0).

UnitY

public static vec3d_t UnitY { get; }

Property Value

vec3d_t

Generate vec3d_t(0, 1, 0).

UnitZ

public static vec3d_t UnitZ { get; }

Property Value

vec3d_t

Generate vec3d_t(0, 0, 1).

X

Value at x direction.

public double X { readonly get; set; }

Property Value

double

XY

vec2d_t of X and Y. The getter gets a copied object.

public vec2d_t XY { readonly get; set; }

Property Value

vec2d_t

Y

Value at y direction.

public double Y { readonly get; set; }

Property Value

double

Z

Value at z direction.

public double Z { readonly get; set; }

Property Value

double

Zero

public static vec3d_t Zero { get; }

Property Value

vec3d_t

Generate vec3d_t(0, 0, 0).

Methods

All(double)

Creates a vector with all components set to the specified value.

public static vec3d_t All(double v)

Parameters

v double

Value 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

dir int

direction 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

p00 vec3d_t

Point at (0,0)

p01 vec3d_t

Point at (0,1)

p10 vec3d_t

Point at (1,0)

p11 vec3d_t

Point at (1,1)

u double

Interpolation parameter in first dimension (0.0 to 1.0)

v double

Interpolation 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

a vec3d_t

a

b vec3d_t

b

Returns

vec3d_t

a x b

Dot(vec3d_t)

this dot src.

public readonly double Dot(vec3d_t src)

Parameters

src vec3d_t

src

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

other vec3d_t

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(vec3d_t, double)

check equals for each component with tolerance.

public readonly bool Equals(vec3d_t other, double toleranceForEachComponent)

Parameters

other vec3d_t

other vec

toleranceForEachComponent double

tolerance for each component

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

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

dst box3d_t

Destination 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

src vec3d_t

one 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

v vec3d_t

a vector

Returns

double

Cos(theta)

GetCross(vec3d_t)

Get this cross src.

public readonly vec3d_t GetCross(vec3d_t src)

Parameters

src vec3d_t

src

Returns

vec3d_t

GetCsvText(string)

Gets the CSV text representation of this vector with the specified format.

public readonly string GetCsvText(string format)

Parameters

format string

Format 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

vec vec3d_t

The 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

mat Mat4d

transform 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

v vec3d_t

one 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

v vec3d_t

vector of ending edge. Not required to be an unit vector.

n vec3d_t

normal 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

v vec3d_t

one 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

transformingFunc Func<double, double>

Returns

vec3d_t

GetVec2dByPlaneDir(int)

Gets a 2D vector by projecting the 3D vector onto a plane.

public readonly vec2d_t GetVec2dByPlaneDir(int dir)

Parameters

dir int

Direction index: 0 for YZ plane, 1 for ZX plane, 2 for XY plane

Returns

vec2d_t

A 2D vector representing the projection

GetXRotation(double)

Get rotated vec3d_t along x direction. CCW. Much efficient than using Mat4d multiplication.

public readonly vec3d_t GetXRotation(double rad)

Parameters

rad double

rotation radian

Returns

vec3d_t

rotated vec3d_t

GetYRotation(double)

Get rotated vec3d_t along y direction. CCW. Much efficient than using Mat4d multiplication.

public readonly vec3d_t GetYRotation(double rad)

Parameters

rad double

rotation radian

Returns

vec3d_t

rotated vec3d_t

GetZRotation(double)

Get rotated vec3d_t along z direction. CCW. Much efficient than using Mat4d multiplication.

public readonly vec3d_t GetZRotation(double rad)

Parameters

rad double

rotation radian

Returns

vec3d_t

rotated vec3d_t

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

a vec3d_t

a

b vec3d_t

b

alpha double

ratio

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

toleranceSquare double

Square 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

src string

src

Returns

vec3d_t

parsed vec3d_t

ParseByCsv(string)

Parses a vector from a CSV text string.

public static vec3d_t ParseByCsv(string csvText)

Parameters

csvText string

CSV 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

reader BinaryReader

reader

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

dst double[]

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

dst double[]

dst

p int

position from dst

Returns

int
  1. 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

format string

format 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

format string

The format to use for each component

formatProvider IFormatProvider

The 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

format string

Format string for the double values

leftPadding int

Number 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

src string

The string to parse in format “(x,y,z)”

dst vec3d_t

When 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

text string

The string to parse. Can contain brackets, parentheses, or other delimiters.

dst vec3d_t

When 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

dir int

direction index

value double

new component value

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

writer BinaryWriter

writer

Operators

operator +(vec3d_t, vec3d_t)

Plus.

public static vec3d_t operator +(vec3d_t left, vec3d_t right)

Parameters

left vec3d_t

a

right vec3d_t

b

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

a vec3d_t
d double

Returns

vec3d_t

operator ==(vec3d_t, vec3d_t)

Equality operator for comparing two vec3d_t objects.

public static bool operator ==(vec3d_t left, vec3d_t right)

Parameters

left vec3d_t

Left operand

right vec3d_t

Right operand

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

left vec3d_t

Left operand

right vec3d_t

Right operand

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

p vec3d_t

point

src Mat4d

transmform matrix

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

a vec3d_t

vector

s double

scale

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

a vec3d_t

a

b vec3d_t

b

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

src vec3d_t

src

Returns

vec3d_t

new vec3d_t(-src.x, -src.y, -src.z)