Table of Contents

Class Vec3d

Namespace
Hi.Geom
Assembly
HiGeom.dll

Basic 3D point (or vector).

[BsonIgnoreExtraElements]
public class Vec3d : IEquatable<Vec3d>, IExpandToBox3d, IBinaryIo, IWriteBin, ICsvRowIo, IEqualityOperators<Vec3d, Vec3d, bool>, IAdditionOperators<Vec3d, Vec3d, Vec3d>, ISubtractionOperators<Vec3d, Vec3d, Vec3d>, IMultiplyOperators<Vec3d, double, Vec3d>, IMultiplyOperators<Vec3d, Mat4d, Vec3d>, IDivisionOperators<Vec3d, double, Vec3d>, IVec<double>, IFormattable
Inheritance
Vec3d
Implements
Inherited Members
Extension Methods

Constructors

Vec3d()

Ctor.

public Vec3d()

Vec3d(Polar3d)

Ctor.

public Vec3d(Polar3d src)

Parameters

src Polar3d

src

Vec3d(Vec3d)

Copy ctor.

public Vec3d(Vec3d src)

Parameters

src Vec3d

src

Vec3d(vec3d)

ctor.

public Vec3d(vec3d src)

Parameters

src vec3d

src

Vec3d(vec3f)

ctor.

public Vec3d(vec3f src)

Parameters

src vec3f

src

Vec3d(IEnumerable<double>)

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

public Vec3d(IEnumerable<double> src)

Parameters

src IEnumerable<double>

Source collection containing three double values

Vec3d(double, double, double)

Ctor.

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

Parameters

x double

x

y double

y

z double

z

Vec3d(Func<int, double>)

Creates a vector using a function that maps direction index to value.

public Vec3d(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(BinaryReader)

Ctor by bytes: x = reader.ReadDouble(); y = reader.ReadDouble(); z = reader.ReadDouble();

public Vec3d(BinaryReader reader)

Parameters

reader BinaryReader

reader

Vec3d(int, double, double, double)

Ctor by direction offset. Direction 0,1,2 indicate x,y,z respectively.

public Vec3d(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(string)

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

public Vec3d(string src)

Parameters

src string

src

Vec3d((double, double, double))

Ctor.

public Vec3d((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

[BsonIgnore]
public 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 AllOne { get; }

Property Value

Vec3d

Generate Vec3d(1, 1, 1).

CsvText

Csv text.

[BsonIgnore]
public string CsvText { get; set; }

Property Value

string

CsvTitleText

Csv titles text.

[BsonIgnore]
public string CsvTitleText { get; }

Property Value

string

ElementNum

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

public static int ElementNum { get; }

Property Value

int

IsAllFinite

[BsonIgnore]
public bool IsAllFinite { get; }

Property Value

bool

Is x,y,z all finite.

IsAllNaN

[BsonIgnore]
public bool IsAllNaN { get; }

Property Value

bool

is x,y,z all NaN.

IsAllNegativeInfinity

[BsonIgnore]
public bool IsAllNegativeInfinity { get; }

Property Value

bool

is x,y,z all NegativeInfinity.

IsAllPositiveInfinity

[BsonIgnore]
public bool IsAllPositiveInfinity { get; }

Property Value

bool

is x,y,z all PositiveInfinity.

IsAnyFinite

[BsonIgnore]
public bool IsAnyFinite { get; }

Property Value

bool

Is at least one of x,y,z finite.

IsAnyNaN

[BsonIgnore]
public bool IsAnyNaN { get; }

Property Value

bool

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

IsZero

[BsonIgnore]
public bool IsZero { get; }

Property Value

bool

Is zero vector. Which is x == 0 && y == 0 && z == 0.

this[int]

Gets or sets the element at the specified index.

public double this[int dir] { get; set; }

Parameters

dir int

Property Value

double

The element at the specified index.

Length

[BsonIgnore]
public double Length { get; }

Property Value

double

Geometry length of this.

LengthSquare

[BsonIgnore]
public double LengthSquare { get; }

Property Value

double

Geometry length ^ 2. Which is x * x + y * y + z * z.

MaxAbsDir

[BsonIgnore]
public 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

[BsonIgnore]
public 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

[BsonIgnore]
public double MaxValue { get; }

Property Value

double

The max value selected from {x,y,z}. Which is Math.Max(Math.Max(x, y), z).

MinDir

[BsonIgnore]
public 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

[BsonIgnore]
public 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 NaN { get; }

Property Value

Vec3d

Generate Vec3d(double.NaN, double.NaN, double.NaN).

NativeByteSize

public static int NativeByteSize { get; }

Property Value

int

Byte size: sizeof(double) * 3.

NegativeInfinity

public static Vec3d NegativeInfinity { get; }

Property Value

Vec3d

Generate Vec3d(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity)

PositiveInfinity

public static Vec3d PositiveInfinity { get; }

Property Value

Vec3d

Generate Vec3d(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)

Rank

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

public int Rank { get; }

Property Value

int

Text

Gets or sets the vector as a string representation.

[BsonIgnore]
public string Text { get; set; }

Property Value

string

UnitX

public static Vec3d UnitX { get; }

Property Value

Vec3d

Generate Vec3d(1, 0, 0).

UnitY

public static Vec3d UnitY { get; }

Property Value

Vec3d

Generate Vec3d(0, 1, 0).

UnitZ

public static Vec3d UnitZ { get; }

Property Value

Vec3d

Generate Vec3d(0, 0, 1).

X

Value at x direction.

[BsonElement]
public double X { get; set; }

Property Value

double

XY

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

[BsonIgnore]
public Vec2d XY { get; set; }

Property Value

Vec2d

Y

Value at y direction.

[BsonElement]
public double Y { get; set; }

Property Value

double

Z

Value at z direction.

[BsonElement]
public double Z { get; set; }

Property Value

double

Zero

public static Vec3d Zero { get; }

Property Value

Vec3d

Generate Vec3d(0, 0, 0).

Methods

All(double)

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

public static Vec3d All(double v)

Parameters

v double

Value to set for all components

Returns

Vec3d

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 ref double At(int dir)

Parameters

dir int

direction index

Returns

double

value at the direction

BilinearInterpolate(Vec3d, Vec3d, Vec3d, Vec3d, double, double)

Performs bilinear interpolation between four points.

public static Vec3d BilinearInterpolate(Vec3d p00, Vec3d p01, Vec3d p10, Vec3d p11, double u, double v)

Parameters

p00 Vec3d

Point at (0,0)

p01 Vec3d

Point at (0,1)

p10 Vec3d

Point at (1,0)

p11 Vec3d

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

The interpolated point

Cross(Vec3d, Vec3d)

Get a cross b.

public static Vec3d Cross(Vec3d a, Vec3d b)

Parameters

a Vec3d

a

b Vec3d

b

Returns

Vec3d

a x b

Dot(Vec3d)

this dot src.

public double Dot(Vec3d src)

Parameters

src Vec3d

src

Returns

double

dotted value

Enumerate()

Enumerates the components of the vector.

public IEnumerable<double> Enumerate()

Returns

IEnumerable<double>

An enumerable sequence of the vector's components (X, Y, Z)

Equals(Vec3d)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Vec3d other)

Parameters

other Vec3d

An object to compare with this object.

Returns

bool

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

Equals(Vec3d, double)

check equals for each component with tolerance.

public bool Equals(Vec3d other, double toleranceForEachComponent)

Parameters

other Vec3d

other vec

toleranceForEachComponent double

tolerance for each component

Returns

bool

check equals for each component with tolerance.

Equals(object)

Determines whether the specified object is equal to the current object.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

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

ExpandMax(Vec3d)

Find and expand maximum values from src.

public void ExpandMax(Vec3d src)

Parameters

src Vec3d

src

ExpandMin(Vec3d)

Find and expand minimum values from src.

public void ExpandMin(Vec3d src)

Parameters

src Vec3d

src

ExpandToBox3d(Box3d)

Expands the destination box. This function is usually used to compute the bounding box of elements.

public void ExpandToBox3d(Box3d dst)

Parameters

dst Box3d

Destination box

GetCosSquareWith(Vec3d)

Get Cos(theta)^2. theta is the angle between this and src. This function is faster than GetCosWith(Vec3d) since it lacks one square root operation.

public double GetCosSquareWith(Vec3d src)

Parameters

src Vec3d

one of edge vector

Returns

double

Cos(theta)^2

GetCosWith(Vec3d)

Get Cos(theta). theta is the angle between this and v.

public double GetCosWith(Vec3d v)

Parameters

v Vec3d

a vector

Returns

double

Cos(theta)

GetCross(Vec3d)

Get this cross src.

public Vec3d GetCross(Vec3d src)

Parameters

src Vec3d

src

Returns

Vec3d

GetCsvText(string)

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

public string GetCsvText(string format)

Parameters

format string

Format string for the double values

Returns

string

CSV formatted string

GetEachValueAbs()

Creates a new vector with the absolute value of each component.

public Vec3d GetEachValueAbs()

Returns

Vec3d

A new vector with absolute values of each component

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetMulEach(Vec3d)

Creates a new vector by multiplying each component of this vector with the corresponding component of another vector.

public Vec3d GetMulEach(Vec3d vec)

Parameters

vec Vec3d

The vector to multiply with

Returns

Vec3d

A new vector with component-wise multiplication results

GetMulWithoutTrans(Mat4d)

Get a new object by this*mat without translation part.

public Vec3d GetMulWithoutTrans(Mat4d mat)

Parameters

mat Mat4d

transform matrix

Returns

Vec3d

new Vec3d(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 Vec3d GetNormalized()

Returns

Vec3d

Normalized vec

GetRadian(Vec3d)

Get angle between this and v. The angle has no sign. This vector is not required to be an unit vector.

public double GetRadian(Vec3d v)

Parameters

v Vec3d

one of the edge vector. Not required to be an unit vector.

Returns

double

Angle in radian

GetRadian(Vec3d, Vec3d)

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 double GetRadian(Vec3d v, Vec3d n)

Parameters

v Vec3d

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

n Vec3d

normal vector. Not required to be an unit vector.

Returns

double

angle in radian

GetRadianByUnitVector(Vec3d)

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).

public double GetRadianByUnitVector(Vec3d v)

Parameters

v Vec3d

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 by transforming each element by the function.

public Vec3d GetTransform(Func<double, double> transformingFunc)

Parameters

transformingFunc Func<double, double>

Returns

Vec3d

GetVec2dByPlaneDir(int)

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

public Vec2d GetVec2dByPlaneDir(int dir)

Parameters

dir int

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

Returns

Vec2d

A 2D vector representing the projection

GetXRotation(double)

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

public Vec3d GetXRotation(double rad)

Parameters

rad double

rotation radian

Returns

Vec3d

rotated Vec3d

GetYRotation(double)

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

public Vec3d GetYRotation(double rad)

Parameters

rad double

rotation radian

Returns

Vec3d

rotated Vec3d

GetZRotation(double)

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

public Vec3d GetZRotation(double rad)

Parameters

rad double

rotation radian

Returns

Vec3d

rotated Vec3d

Interpolate(Vec3d, Vec3d, double)

Interpolate from a to b with ratio alpha:(1-alpha).

public static Vec3d Interpolate(Vec3d a, Vec3d b, double alpha)

Parameters

a Vec3d

a

b Vec3d

b

alpha double

ratio

Returns

Vec3d

a * (1 - alpha) + b * alpha

IsNormalized(double)

Checks if the vector is normalized (has a length of approximately 1).

public 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

MulEach(Vec3d)

Multiplies each component of this vector with the corresponding component of another vector.

public Vec3d MulEach(Vec3d vec)

Parameters

vec Vec3d

The vector to multiply with

Returns

Vec3d

This vector after multiplication

MulWithoutTrans(Mat4d)

this*=mat without translation part.

public Vec3d MulWithoutTrans(Mat4d mat)

Parameters

mat Mat4d

transformation matrix

Returns

Vec3d

this

See Also

Normalize()

Normalize this.

public Vec3d Normalize()

Returns

Vec3d

this

Parse(string)

If src is not null and not empty string, return Vec3d(string); otherwise return null.

public static Vec3d Parse(string src)

Parameters

src string

src

Returns

Vec3d

parsed Vec3d

ParseByCsv(string)

Parses a vector from a CSV text string.

public static Vec3d ParseByCsv(string csvText)

Parameters

csvText string

CSV formatted string containing vector components

Returns

Vec3d

A new vector parsed from the CSV text

ReadBin(BinaryReader)

Reads binary data to initialize the object.

public void ReadBin(BinaryReader reader)

Parameters

reader BinaryReader

The binary reader to read from

Set(Vec3d)

Set values by copy.

public Vec3d Set(Vec3d src)

Parameters

src Vec3d

src

Returns

Vec3d

this

Set(vec3d)

Set values by copy.

public Vec3d Set(vec3d src)

Parameters

src vec3d

src

Returns

Vec3d

this

Set(double, double, double)

Set values.

public Vec3d Set(double x, double y, double z)

Parameters

x double

x

y double

y

z double

z

Returns

Vec3d

this

Set(double[])

Set values by array.

public Vec3d Set(double[] xyz)

Parameters

xyz double[]

double[]{x,y,z}

Returns

Vec3d

this

Set(Func<int, double, double>)

Sets vector components using a function that maps direction index and current value to new value.

public Vec3d Set(Func<int, double, double> dirToValueFunc)

Parameters

dirToValueFunc Func<int, double, double>

Function that takes direction index (0=X, 1=Y, 2=Z) and current value, and returns the new value

Returns

Vec3d

This vector after modification

Set(Func<int, double>)

Sets vector components using a function that maps direction index to value.

public Vec3d Set(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

Returns

Vec3d

This vector after modification

Set(int, double, double, double)

Set values by direction offset. Direction 0,1,2 indicate x,y,z respectively.

public Vec3d Set(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

Returns

Vec3d

this

SetEachNanToZero()

Set NaN to 0 for each value.

public Vec3d SetEachNanToZero()

Returns

Vec3d

this

SetEachValueAbs()

Set each value to absolute.

public Vec3d SetEachValueAbs()

Returns

Vec3d

this

ToArray()

return new double[] { x, y, z }

public double[] ToArray()

Returns

double[]

{ x, y, z }

ToBuf(double[])

Set x,y,z to the dst array.

public 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 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

ToString()

To representative string with format:(x,y,z).

public override string ToString()

Returns

string

Representative string

ToString(string)

To string with format: (x,y,z)

public 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 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 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

Transform(Func<double, double>)

Transform each element by the function.

public Vec3d Transform(Func<double, double> transformingFunc)

Parameters

transformingFunc Func<double, double>

Returns

Vec3d

TryParse(string, out Vec3d)

Attempts to parse a string into a Vec3d.

public static bool TryParse(string src, out Vec3d dst)

Parameters

src string

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

dst Vec3d

When this method returns, contains the Vec3d value if parsing succeeded, or null if parsing failed

Returns

bool

true if parsing succeeded; otherwise, false

WriteBin(BinaryWriter)

Output to bytes: writer.Write(x); writer.Write(y); writer.Write(z);

public void WriteBin(BinaryWriter writer)

Parameters

writer BinaryWriter

writer

Operators

operator +(Vec3d, Vec3d)

Plus.

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

Parameters

left Vec3d

a

right Vec3d

b

Returns

Vec3d

new Vec3d(a.x + b.x, a.y + b.y, a.z + b.z)

operator /(Vec3d, double)

Get a new object from a scaled by 1/d.

public static Vec3d operator /(Vec3d a, double d)

Parameters

a Vec3d
d double

Returns

Vec3d

operator ==(Vec3d, Vec3d)

Equality operator for comparing two Vec3d objects.

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

Parameters

left Vec3d

Left operand

right Vec3d

Right operand

Returns

bool

True if the vectors are equal, false otherwise

operator !=(Vec3d, Vec3d)

Inequality operator for comparing two Vec3d objects.

public static bool operator !=(Vec3d left, Vec3d right)

Parameters

left Vec3d

Left operand

right Vec3d

Right operand

Returns

bool

True if the vectors are not equal, false otherwise

operator *(Vec3d, Mat4d)

Get p*src.

public static Vec3d operator *(Vec3d p, Mat4d src)

Parameters

p Vec3d

point

src Mat4d

transmform matrix

Returns

Vec3d

new Vec3d(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, double)

Scale a by s.

public static Vec3d operator *(Vec3d a, double s)

Parameters

a Vec3d

vector

s double

scale

Returns

Vec3d

new Vec3d(a.x * s, a.y * s, a.z * s)

operator -(Vec3d, Vec3d)

Minus.

public static Vec3d operator -(Vec3d a, Vec3d b)

Parameters

a Vec3d

a

b Vec3d

b

Returns

Vec3d

new Vec3d(a.x - b.x, a.y - b.y, a.z - b.z)

operator -(Vec3d)

Get negate vector.

public static Vec3d operator -(Vec3d src)

Parameters

src Vec3d

src

Returns

Vec3d

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