r3 package - github.com/golang/geo/r3 - Go Packages (original) (raw)

Package r3 implements types and functions for working with geometry in ℝ³.

See ../s2 for a more detailed overview.

View Source

const (

MaxPrec = 64 << 20 


MaxExp = 200 * 1000 * 1000 


MinExp = -[MaxExp](#MaxExp) 

)

This section is empty.

This section is empty.

Axis enumerates the 3 axes of ℝ³.

const ( XAxis Axis = iota YAxis ZAxis )

The three axes of ℝ³.

type PreciseVector struct { X, Y, Z *big.Float }

PreciseVector represents a point in ℝ³ using high-precision values. Note that this is NOT a complete implementation because there are some operations that Vector supports that are not feasible with arbitrary precision math. (e.g., methods that need division like Normalize, or methods needing a square root operation such as Norm)

NewPreciseVector creates a high precision vector from the given floating point values.

func PreciseVectorFromVector(v Vector) PreciseVector

PreciseVectorFromVector creates a high precision vector from the given Vector.

func (v PreciseVector) Abs() PreciseVector

Abs returns the vector with nonnegative components.

Add returns the standard vector sum of v and ov.

func (v PreciseVector) Cross(ov PreciseVector) PreciseVector

Cross returns the standard cross product of v and ov.

Dot returns the standard dot product of v and ov.

Equal reports whether v and ov are equal.

IsUnit reports whether this vector is of unit length.

IsZero reports if this vector is exactly 0 efficiently.

func (v PreciseVector) LargestComponent() Axis

LargestComponent returns the axis that represents the largest component in this vector.

Mul returns the standard scalar product of v and f.

MulByFloat64 returns the standard scalar product of v and f.

Norm2 returns the square of the norm.

func (v PreciseVector) SmallestComponent() Axis

SmallestComponent returns the axis that represents the smallest component in this vector.

Sub returns the standard vector difference of v and ov.

func (v PreciseVector) Vector() Vector

Vector returns this precise vector converted to a Vector.

type Vector struct { X, Y, Z float64 }

Vector represents a point in ℝ³.

func (v Vector) Abs() Vector

Abs returns the vector with nonnegative components.

func (v Vector) Add(ov Vector) Vector

Add returns the standard vector sum of v and ov.

Angle returns the angle between v and ov.

func (v Vector) ApproxEqual(ov Vector) bool

ApproxEqual reports whether v and ov are equal within a small epsilon.

func (v Vector) Cmp(ov Vector) int

Cmp compares v and ov lexicographically and returns:

-1 if v < ov 0 if v == ov +1 if v > ov

This method is based on C++'s std::lexicographical_compare. Two entities are compared element by element with the given operator. The first mismatch defines which is less (or greater) than the other. If both have equivalent values they are lexicographically equal.

func (v Vector) Cross(ov Vector) Vector

Cross returns the standard cross product of v and ov.

Distance returns the Euclidean distance between v and ov.

Dot returns the standard dot product of v and ov.

func (v Vector) IsUnit() bool

IsUnit returns whether this vector is of approximately unit length.

func (v Vector) LargestComponent() Axis

LargestComponent returns the axis that represents the largest component in this vector.

Mul returns the standard scalar product of v and m.

Norm returns the vector's norm.

Norm2 returns the square of the norm.

func (v Vector) Normalize() Vector

Normalize returns a unit vector in the same direction as v.

func (v Vector) Ortho() Vector

Ortho returns a unit vector that is orthogonal to v. Ortho(-v) = -Ortho(v) for all v.

func (v Vector) SmallestComponent() Axis

SmallestComponent returns the axis that represents the smallest component in this vector.

func (v Vector) Sub(ov Vector) Vector

Sub returns the standard vector difference of v and ov.