Struct GeoVector
- Namespace
- CADability
- Assembly
- CADability.dll
A 3-dimensional vector with double x,y and z components. The vector is not necessary normalized.
[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
GeoVector(GeoPoint, GeoPoint)
Constructs a new GeoVector which points from the StartPoint to the EndPoint.
public GeoVector(GeoPoint StartPoint, GeoPoint EndPoint)
Parameters
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
GeoVector(GeoVector2D)
Constructs a new GeoVector from a 2d vector assumed in the xy plane
public GeoVector(GeoVector2D v)
Parameters
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
vGeoVector[]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
dataIJsonReadStructsupplies the values
GeoVector(double, double, double)
Constructs a new GeoVector with the given components
public GeoVector(double x, double y, double z)
Parameters
GeoVector(SerializationInfo, StreamingContext)
Constructor required by deserialization
public GeoVector(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
NullVector
The nullvector, same as new GeoVector(0.0,0.0,0.0);
public static readonly GeoVector NullVector
Field Value
XAxis
The x-axis, same as new GeoVector(1.0,0.0,0.0);
public static readonly GeoVector XAxis
Field Value
YAxis
The y-axis, same as new GeoVector(0.0,1.0,0.0);
public static readonly GeoVector YAxis
Field Value
ZAxis
The z-axis, same as new GeoVector(0.0,0.0,1.0);
public static readonly GeoVector ZAxis
Field Value
x
x-component
public double x
Field Value
y
y-component
public double y
Field Value
z
z-component
public double z
Field Value
Properties
Invalid
An invalid GeoVector (NaN,NaN,NaN)
public static GeoVector Invalid { get; }
Property Value
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
indexint0, 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
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
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
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
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
dirxGeoVectorfirst perpendicular unit vector
diryGeoVectorsecond 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
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
Returns
- double
Cosine of the inner angle
Equals(object)
Overrides object.Equals.
public override bool Equals(object obj)
Parameters
objobjectobject 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
dataIJsonWriteDatareceives 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
infoSerializationInforeceives the data
contextStreamingContextthe 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
otherGeoVectorother 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
dataIJsonReadDatanot 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
Operators
operator +(GeoVector, GeoVector)
Adds the two vectors.
public static GeoVector operator +(GeoVector v1, GeoVector v2)
Parameters
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
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
Returns
- bool
true if equal
operator ^(GeoVector, GeoVector)
Cross product of the to vectors.
public static GeoVector operator ^(GeoVector left, GeoVector right)
Parameters
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
vGeoVectorthe 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
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
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
mMatrixthe 3x3 matrix
vGeoVectorthe 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
Returns
- GeoVector
scaled vector
operator -(GeoVector, GeoVector)
Subtracts the second vector from the first vector
public static GeoVector operator -(GeoVector v1, GeoVector v2)
Parameters
Returns
- GeoVector
difference
operator -(GeoVector)
Reverses the driection of the given vector
public static GeoVector operator -(GeoVector v)
Parameters
vGeoVectorvector to reverse
Returns
- GeoVector
reversed vector