Table of Contents

Struct GeoVector

Namespace
CADability
Assembly
CADability.dll

A 3-dimensional vector with double x,y and z components. The vector is not necessary normalized. Keep in mind that this is a value type. Passing a value type as a (non ref) parameter and changing it's value inside the invoked method leaves the original unchanged.

[JsonVersion(serializeAsStruct = true, version = 1)]
public struct GeoVector : ISerializable, IJsonSerialize, IExportStep
Implements
Inherited Members

Constructors

GeoVector(Angle, Angle)

Constructs a new GeoVector with the given angles a longitude and latitude. The resulting GeoVector is normed.

public GeoVector(Angle longitude, Angle latitude)

Parameters

longitude Angle
latitude Angle

GeoVector(GeoPoint, GeoPoint)

Constructs a new GeoVector which points from the StartPoint to the EndPoint.

public GeoVector(GeoPoint StartPoint, GeoPoint EndPoint)

Parameters

StartPoint GeoPoint

from here

EndPoint GeoPoint

to here

GeoVector(GeoVector, GeoVector, double)

Constructs a new GeoVector by linear interpolation between two vectors: (1 - ratio) * v1 + ratio * v2. A ratio of 0.0 yields v1, 1.0 yields v2. The result is not normalized.

public GeoVector(GeoVector v1, GeoVector v2, double ratio)

Parameters

v1 GeoVector

first vector

v2 GeoVector

second vector

ratio double

position between the two vectors

GeoVector(GeoVector2D)

Constructs a new GeoVector from a 2d vector assumed in the xy plane

public GeoVector(GeoVector2D v)

Parameters

v GeoVector2D

GeoVector(params GeoVector[])

Constructs a new GeoVector as the arithmetic mean of the given vectors (their sum divided by their number). The result is not normalized; an empty list yields NaN components.

public GeoVector(params GeoVector[] v)

Parameters

v GeoVector[]

the vectors to average

GeoVector(IJsonReadStruct)

Constructor for the JSON deserialization (IJsonSerialize): reads the three components in the order GetObjectData(IJsonWriteData) wrote them. It is found by reflection, there is no need to call it directly.

public GeoVector(IJsonReadStruct data)

Parameters

data IJsonReadStruct

supplies the values

GeoVector(double, double, double)

Constructs a new GeoVector with the given components

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

Parameters

x double

x-component

y double

y-component

z double

z-component

GeoVector(SerializationInfo, StreamingContext)

Constructor required by deserialization

public GeoVector(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Fields

NullVector

The nullvector, same as new GeoVector(0.0,0.0,0.0);

public static readonly GeoVector NullVector

Field Value

GeoVector

XAxis

The x-axis, same as new GeoVector(1.0,0.0,0.0);

public static readonly GeoVector XAxis

Field Value

GeoVector

YAxis

The y-axis, same as new GeoVector(0.0,1.0,0.0);

public static readonly GeoVector YAxis

Field Value

GeoVector

ZAxis

The z-axis, same as new GeoVector(0.0,0.0,1.0);

public static readonly GeoVector ZAxis

Field Value

GeoVector

x

x-component

public double x

Field Value

double

y

y-component

public double y

Field Value

double

z

z-component

public double z

Field Value

double

Properties

Invalid

An invalid GeoVector (NaN,NaN,NaN)

public static GeoVector Invalid { get; }

Property Value

GeoVector

this[int]

Gives access to the components by index: 0 is x, 1 is y, 2 is z. Any other index throws an IndexOutOfRangeException. Convenient for loops over the coordinates.

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

Parameters

index int

0, 1 or 2

Property Value

double

the component with that index

Length

Returns the length of this vector.

public double Length { get; set; }

Property Value

double

LengthSqared

The squared length of this vector (xx + yy + z*z). Cheaper than Length because no square root is taken; use it when lengths are only compared.

public double LengthSqared { get; }

Property Value

double

Normalized

A copy of this vector scaled to Length 1.0; this vector itself remains unchanged (see Norm() to normalize in place). Throws a GeoVectorException if this vector is the nullvector.

public GeoVector Normalized { get; }

Property Value

GeoVector

TaxicabLength

The taxicab (Manhattan) length of this vector, i.e. the sum of the absolute values of the components. A cheap estimate of the size of the vector for tolerance checks, not the euclidean Length.

public double TaxicabLength { get; }

Property Value

double

Methods

ArbitraryNormals(out GeoVector, out GeoVector)

Computes two unit vectors that are perpendicular to this vector and to each other, e.g. to span a plane perpendicular to an axis. dirx, diry and this vector form a right handed system. The choice of dirx is arbitrary but deterministic, it depends on which component of this vector is the largest. Throws a GeoVectorException if this vector is the nullvector.

public void ArbitraryNormals(out GeoVector dirx, out GeoVector diry)

Parameters

dirx GeoVector

first perpendicular unit vector

diry GeoVector

second perpendicular unit vector, the normalized cross product of this vector and dirx

Bisector(GeoVector, GeoVector)

Returns the bisector vector of the two provided vectors. The result will be normalized (length = 1)

public static GeoVector Bisector(GeoVector v1, GeoVector v2)

Parameters

v1 GeoVector

First vector

v2 GeoVector

Second vector

Returns

GeoVector

The bisector

Cos(GeoVector, GeoVector)

Returns the cosine of the angle between the two vectors. Throws an arithmetic exception if any of the vectors is the nullvector.

public static double Cos(GeoVector v1, GeoVector v2)

Parameters

v1 GeoVector

First vector

v2 GeoVector

Second vector

Returns

double

Cosine of the inner angle

Equals(object)

Overrides object.Equals.

public override bool Equals(object obj)

Parameters

obj object

object to compare with

Returns

bool

true if exactly equal

GetHashCode()

Overrides object.GetHashCode

public override int GetHashCode()

Returns

int

the hashcode

GetObjectData(IJsonWriteData)

Writes the three components for the JSON serialization (IJsonSerialize). The struct is serialized inline as a plain list of values and read back by the constructor taking an IJsonReadStruct.

public void GetObjectData(IJsonWriteData data)

Parameters

data IJsonWriteData

receives the values

GetObjectData(SerializationInfo, StreamingContext)

Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.

public void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

receives the data

context StreamingContext

the destination of the serialization

IsNullVector()

Returns true, if this vector is exactly the nullvector. Use IsNullVector(GeoVector) if you need more control over precision.

public bool IsNullVector()

Returns

bool

true if nullvector

IsPerpendicular(GeoVector)

Determines whether this vector and the othe vector are perpendicular. Use IsPerpendicular(GeoVector, GeoVector, bool) if you need more control over precision.

public bool IsPerpendicular(GeoVector other)

Parameters

other GeoVector

other vector

Returns

bool

true if perpendicular

IsValid()

Returns true, when the vector is an ordinary number, false when it is Invalid or the result of a failed computation. Only the x-component is tested for NaN.

public bool IsValid()

Returns

bool

true if valid

Norm()

Normalizes this vector. After this operation the vector will have the Length 1.0 Throws a GeoVectorException if the vector is the nullvector.

public void Norm()

NormIfNotNull()

Normalizes this vector to Length 1.0 like Norm(), but leaves the nullvector unchanged instead of throwing an exception.

public void NormIfNotNull()

Reverse()

Reverses this vector.

public void Reverse()

SetObjectData(IJsonReadData)

Does nothing. Value types serialized inline are restored by the constructor taking an IJsonReadStruct; this method only exists to satisfy IJsonSerialize.

public void SetObjectData(IJsonReadData data)

Parameters

data IJsonReadData

not used

To2D()

Returns the coresponding 2d vector by omitting the z coordinate

public GeoVector2D To2D()

Returns

GeoVector2D

the coresponding 2d vector

ToString()

public override string ToString()

Returns

string

Operators

operator +(GeoVector, GeoVector)

Adds the two vectors.

public static GeoVector operator +(GeoVector v1, GeoVector v2)

Parameters

v1 GeoVector

first vector

v2 GeoVector

second vector

Returns

GeoVector

sum

operator /(GeoVector, double)

Divides the given GeoVector v by the given scalar value v.

public static GeoVector operator /(GeoVector v, double d)

Parameters

v GeoVector

vector

d double

divider

Returns

GeoVector

scaled vector

operator ==(GeoVector, GeoVector)

Determins whether the given vectors are exactly equal. Use SameDirection(GeoVector, GeoVector, bool) if you need more control over precision.

public static bool operator ==(GeoVector v1, GeoVector v2)

Parameters

v1 GeoVector

first operand

v2 GeoVector

second operand

Returns

bool

true if equal

operator ^(GeoVector, GeoVector)

Cross product of the to vectors.

public static GeoVector operator ^(GeoVector left, GeoVector right)

Parameters

left GeoVector

left operand

right GeoVector

right operand

Returns

GeoVector

Cross product

implicit operator double[](GeoVector)

Converts the vector to an array of its components, e.g. to pass it to numerical routines.

public static implicit operator double[](GeoVector v)

Parameters

v GeoVector

the vector

Returns

double[]

the array {x, y, z}

operator !=(GeoVector, GeoVector)

Determins whether the given vectors are not exactly equal. Use SameDirection(GeoVector, GeoVector, bool) if you need more control over precision.

public static bool operator !=(GeoVector v1, GeoVector v2)

Parameters

v1 GeoVector

first operand

v2 GeoVector

second operand

Returns

bool

true if not equal

operator *(GeoVector, GeoVector)

Calculates the scalar product (dot product, inner product) of the two given vectors

public static double operator *(GeoVector v1, GeoVector v2)

Parameters

v1 GeoVector

first vector

v2 GeoVector

second vector

Returns

double

the scalar product

operator *(Matrix, GeoVector)

Applies a 3x3 MathNet.Numerics matrix to the vector, i.e. a linear transformation without translation. The matrix must have three rows and three columns, which is only checked in debug builds. For affine transformations use ModOp.

public static GeoVector operator *(Matrix m, GeoVector v)

Parameters

m Matrix

the 3x3 matrix

v GeoVector

the vector

Returns

GeoVector

the transformed vector

operator *(double, GeoVector)

Scales the given vector by the given double

public static GeoVector operator *(double d, GeoVector v)

Parameters

d double

factor

v GeoVector

vector

Returns

GeoVector

scaled vector

operator -(GeoVector, GeoVector)

Subtracts the second vector from the first vector

public static GeoVector operator -(GeoVector v1, GeoVector v2)

Parameters

v1 GeoVector

first vector

v2 GeoVector

second vector

Returns

GeoVector

difference

operator -(GeoVector)

Reverses the driection of the given vector

public static GeoVector operator -(GeoVector v)

Parameters

v GeoVector

vector to reverse

Returns

GeoVector

reversed vector