Table of Contents

Class Vec2d

Namespace
Hi.Geom
Assembly
HiGeom.dll

Basic 2D point (or vector).

public class Vec2d : IExpandToBox2d, IEquatable<Vec2d>, ICsvRowIo, IEqualityOperators<Vec2d, Vec2d, bool>, IAdditionOperators<Vec2d, Vec2d, Vec2d>, ISubtractionOperators<Vec2d, Vec2d, Vec2d>, IMultiplyOperators<Vec2d, double, Vec2d>, IDivisionOperators<Vec2d, double, Vec2d>, IVec<double>
Inheritance
Vec2d
Implements
Inherited Members
Extension Methods

Constructors

Vec2d()

Default constructor. Creates a vector with coordinates (0,0).

public Vec2d()

Vec2d(Vec2d)

Copy ctor.

public Vec2d(Vec2d src)

Parameters

src Vec2d

src

Vec2d(Vec2i)

Creates a vector from Vec2i by converting integer coordinates to double.

public Vec2d(Vec2i src)

Parameters

src Vec2i

Source Vec2i vector with integer coordinates

Vec2d(vec2d)

ctor.

public Vec2d(vec2d src)

Parameters

src vec2d

src

Vec2d(double, double)

Ctor.

public Vec2d(double x, double y)

Parameters

x double

x

y double

y

Vec2d(Func<int, double>)

Ctor using a function that maps direction index to value.

public Vec2d(Func<int, double> dirToValueFunc)

Parameters

dirToValueFunc Func<int, double>

Function that maps direction index to value

Vec2d(BinaryReader)

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

public Vec2d(BinaryReader reader)

Parameters

reader BinaryReader

reader

Vec2d(int, double, double)

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

public Vec2d(int dir, double a, double b)

Parameters

dir int

direction offset

a double

value at direction (0+dir)%2

b double

value at direction (1+dir)%2

Vec2d(string)

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

public Vec2d(string src)

Parameters

src string

src

Fields

x

Value at x direction.

public double x

Field Value

double

y

Value at y direction.

public double y

Field Value

double

Properties

AbsSum

Sum of abs(x) and abs(y).

public double AbsSum { get; }

Property Value

double

AllOne

Generate vec (1,1).

public static Vec2d AllOne { get; }

Property Value

Vec2d

(1,1)

AmpPhase

Create AmpPhase instance.

public AmpPhase AmpPhase { get; }

Property Value

AmpPhase

Angle_deg

Angle in degree between vec(x,y) and vec(1,0).

public double Angle_deg { get; }

Property Value

double

Angle_rad

Angle in radian between vec(x,y) and vec(1,0).

public double Angle_rad { get; }

Property Value

double

CsvText

Csv text.

public string CsvText { get; set; }

Property Value

string

CsvTitleText

Csv titles text.

public string CsvTitleText { get; }

Property Value

string

IsAllFinite

public bool IsAllFinite { get; }

Property Value

bool

Is x,y,z all finite.

IsAllNaN

public bool IsAllNaN { get; }

Property Value

bool

is x,y all NaN.

IsAllNegativeInfinity

public bool IsAllNegativeInfinity { get; }

Property Value

bool

is x,y all NegativeInfinity.

IsAllPositiveInfinity

public bool IsAllPositiveInfinity { get; }

Property Value

bool

is x,y all PositiveInfinity.

IsAnyFinite

public bool IsAnyFinite { get; }

Property Value

bool

Is at least one of x,y finite.

IsAnyNaN

Is any member nan.

public bool IsAnyNaN { get; }

Property Value

bool

IsZero

public bool IsZero { get; }

Property Value

bool

Is zero vector. Which is x == 0 && y == 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

Length.

public double Length { get; }

Property Value

double

LengthSquare

Length square.

public double LengthSquare { get; }

Property Value

double

MaxAbsDir

Get the direction of the max absolute value.

public int MaxAbsDir { get; }

Property Value

int

MaxDir

Get the direction of the max value.

public int MaxDir { get; }

Property Value

int

MaxValue

Get max value from {x,y}.

public double MaxValue { get; }

Property Value

double

MinDir

Get the direction index with minimum value. If {x,y} is the smallest, return {0,1}.

public int MinDir { get; }

Property Value

int

MinValue

Get min value from {x,y}.

public double MinValue { get; }

Property Value

double

NaN

Generate NAN vec.

public static Vec2d NaN { get; }

Property Value

Vec2d

(nan,nan)

NativeByteSize

public static int NativeByteSize { get; }

Property Value

int

Byte size: sizeof(double) * 2.

NegativeInfinity

Generate negative infinity vec.

public static Vec2d NegativeInfinity { get; }

Property Value

Vec2d

(-inf,-inf)

PositiveInfinity

Generate positive infinity vec.

public static Vec2d PositiveInfinity { get; }

Property Value

Vec2d

(inf,inf)

Rank

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

public int Rank { get; }

Property Value

int

UnitX

Generate vec (1,0).

public static Vec2d UnitX { get; }

Property Value

Vec2d

(1,0)

UnitY

Generate vec (0,1).

public static Vec2d UnitY { get; }

Property Value

Vec2d

(0,1)

X

Gets or sets the X coordinate value.

public double X { get; set; }

Property Value

double

Y

Gets or sets the Y coordinate value.

public double Y { get; set; }

Property Value

double

Zero

Generate vec (0,0).

public static Vec2d Zero { get; }

Property Value

Vec2d

(0,0)

Methods

All(double)

Generate Vec2d with all components set to the given value.

public static Vec2d All(double v)

Parameters

v double

Returns

Vec2d

At(int)

Member at direction.

public ref double At(int dir)

Parameters

dir int

direction

Returns

double

member

Cross(Vec2d)

Cross.

public double Cross(Vec2d src)

Parameters

src Vec2d

src

Returns

double

cross value

Dot(Vec2d)

Dot.

public double Dot(Vec2d src)

Parameters

src Vec2d

src

Returns

double

dotted value

Equals(Vec2d)

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

public bool Equals(Vec2d other)

Parameters

other Vec2d

An object to compare with this object.

Returns

bool

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

Equals(Vec2d, double)

check equals for each component with tolerance.

public bool Equals(Vec2d other, double toleranceForEachComponent)

Parameters

other Vec2d

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(Vec2d)

Find and expand maximum values from src.

public void ExpandMax(Vec2d src)

Parameters

src Vec2d

src

ExpandMin(Vec2d)

Find and expand minimum values from src.

public void ExpandMin(Vec2d src)

Parameters

src Vec2d

src

ExpandToBox2d(Box2d)

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

public void ExpandToBox2d(Box2d dst)

Parameters

dst Box2d

Destination box

GenNaN()

Generate NAN vec.

public static Vec2d GenNaN()

Returns

Vec2d

(nan,nan)

GenNegativeInfinity()

Generate negative infinity vec.

public static Vec2d GenNegativeInfinity()

Returns

Vec2d

(-inf,-inf)

GenOne()

Generate vec (1,1).

public static Vec2d GenOne()

Returns

Vec2d

(1,1)

GenPositiveInfinity()

Generate positive infinity vec.

public static Vec2d GenPositiveInfinity()

Returns

Vec2d

(inf,inf)

GenUnitX()

Generate vec (1,0).

public static Vec2d GenUnitX()

Returns

Vec2d

(1,0)

GenUnitY()

Generate vec (0,1).

public static Vec2d GenUnitY()

Returns

Vec2d

(0,1)

GenZero()

Generate vec (0,0).

public static Vec2d GenZero()

Returns

Vec2d

(0,0)

GetCosSquareWith(Vec2d)

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

public double GetCosSquareWith(Vec2d src)

Parameters

src Vec2d

one of edge vector

Returns

double

Cos(theta)^2

GetCosWith(Vec2d)

Get cos(angle). The angle is between v and this.

public double GetCosWith(Vec2d v)

Parameters

v Vec2d

v

Returns

double

cos(angle)

GetCsvText(string)

Get CSV text with specified format.

public string GetCsvText(string format)

Parameters

format string

Format string for each component

Returns

string

CSV formatted string

GetEachValueAbs()

Get a new vector with each value set to its absolute value.

public Vec2d GetEachValueAbs()

Returns

Vec2d

A new vector with absolute values

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetMulEach(Vec2d)

Get a new vector with each component multiplied with the corresponding component of the given vector.

public Vec2d GetMulEach(Vec2d vec)

Parameters

vec Vec2d

The vector to multiply with

Returns

Vec2d

A new vector with multiplied components

GetNormalized()

Generate normalized vec.

public Vec2d GetNormalized()

Returns

Vec2d

Normalized vec

GetRadian(Vec2d)

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

public double GetRadian(Vec2d v)

Parameters

v Vec2d

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

Returns

double

Angle in radian

GetTransform(Func<double, double>)

Get the new Vec2d by transforming each element by the function.

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

Parameters

transformingFunc Func<double, double>

Returns

Vec2d

Interpolate(Vec2d, Vec2d, double)

Linear interpolate between a and b.

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

Parameters

a Vec2d

a

b Vec2d

b

alpha double

ratio

Returns

Vec2d

interpolation

IsNormalized(double)

Check if this vector is normalized.

public bool IsNormalized(double toleranceSquare = 1E-07)

Parameters

toleranceSquare double

Tolerance for checking if length squared is 1

Returns

bool

True if the vector is normalized

MulEach(Vec2d)

Multiply each component with the corresponding component of the given vector.

public Vec2d MulEach(Vec2d vec)

Parameters

vec Vec2d

The vector to multiply with

Returns

Vec2d

this

Normalize()

Normalize.

public Vec2d Normalize()

Returns

Vec2d

this

Set(Vec2d)

Set values by copy.

public Vec2d Set(Vec2d src)

Parameters

src Vec2d

src

Returns

Vec2d

this

Set(vec2d)

Set values by copy.

public Vec2d Set(vec2d src)

Parameters

src vec2d

src

Returns

Vec2d

this

Set(double, double)

Set values.

public Vec2d Set(double x, double y)

Parameters

x double

x

y double

y

Returns

Vec2d

this

Set(double[])

Set values by array.

public Vec2d Set(double[] xy)

Parameters

xy double[]

double[]{x,y}

Returns

Vec2d

this

Set(Func<int, double, double>)

Set values using a function that maps direction index and current value to new value.

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

Parameters

dirToValueFunc Func<int, double, double>

Function that maps direction index and current value to new value

Returns

Vec2d

this

Set(Func<int, double>)

Set values using a function that maps direction index to value.

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

Parameters

dirToValueFunc Func<int, double>

Function that maps direction index to value

Returns

Vec2d

this

Set(int, double, double)

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

public Vec2d Set(int dir, double a, double b)

Parameters

dir int

direction offset

a double

value at direction (0+dir)%2

b double

value at direction (1+dir)%2

Returns

Vec2d

this

SetEachNanToZero()

Set NaN to 0 for each value.

public Vec2d SetEachNanToZero()

Returns

Vec2d

this

SetEachValueAbs()

Set all member to absolute value.

public Vec2d SetEachValueAbs()

Returns

Vec2d

this

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

ToString(string)

To string with format: (x,y)

public string ToString(string format)

Parameters

format string

Format string for the double values

Returns

string

Formatted string representation of the vector

ToString(string, int)

Format the vector with padding.

public string ToString(string format, int leftPadding)

Parameters

format string

Format string for each component

leftPadding int

Left padding for each component

Returns

string

Formatted string

Transform(Func<double, double>)

Transform each element by the function.

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

Parameters

transformingFunc Func<double, double>

Returns

Vec2d

WriteBin(BinaryWriter)

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

public void WriteBin(BinaryWriter writer)

Parameters

writer BinaryWriter

writer

Operators

operator +(Vec2d, Vec2d)

Plus.

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

Parameters

left Vec2d

a

right Vec2d

b

Returns

Vec2d

a+b

operator /(Vec2d, double)

a/d.

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

Parameters

a Vec2d

a

d double

d

Returns

Vec2d

a/d

operator ==(Vec2d, Vec2d)

Equality operator for comparing two Vec2d objects.

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

Parameters

left Vec2d

Left operand

right Vec2d

Right operand

Returns

bool

True if the vectors are equal, false otherwise

operator !=(Vec2d, Vec2d)

Inequality operator for comparing two Vec2d objects.

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

Parameters

left Vec2d

Left operand

right Vec2d

Right operand

Returns

bool

True if the vectors are not equal, false otherwise

operator *(Vec2d, double)

a*s.

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

Parameters

a Vec2d

a

s double

s

Returns

Vec2d

a*s

operator -(Vec2d, Vec2d)

a-b.

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

Parameters

a Vec2d

a

b Vec2d

b

Returns

Vec2d

a-b

operator -(Vec2d)

Negate.

public static Vec2d operator -(Vec2d src)

Parameters

src Vec2d

src

Returns

Vec2d

Negate