Documentation
¶
Overview ¶
Package vec3 contains a 3D float64 vector type T and functions.
Index ¶
- Variables
- func Angle(a, b *T) float64
- func Cosine(a, b *T) float64
- func Distance(a, b *T) float64
- func Dot(a, b *T) float64
- func PracticallyEquals(v1, v2, allowedDelta float64) bool
- func Sinus(a, b *T) float64
- func SquareDistance(a, b *T) float64
- type Box
- type T
- func (vec *T) Abs() *T
- func (vec *T) Absed() T
- func (vec *T) Add(v *T) *T
- func (vec *T) Added(v *T) T
- func (vec *T) Clamp(min, max *T) *T
- func (vec *T) Clamp01() *T
- func (vec *T) Clamped(min, max *T) T
- func (vec *T) Clamped01() T
- func (vec *T) Cols() int
- func (vec *T) Get(col, row int) float64
- func (vec *T) Invert() *T
- func (vec *T) Inverted() T
- func (vec *T) IsZero() bool
- func (vec *T) IsZeroEps(epsilon float64) bool
- func (vec *T) Length() float64
- func (vec *T) LengthSqr() float64
- func (vec *T) Mul(v *T) *T
- func (vec *T) Muled(v *T) T
- func (vec *T) Normal() T
- func (vec *T) Normalize() *T
- func (vec *T) Normalized() T
- func (vec *T) PracticallyEquals(compareVector *T, allowedDelta float64) bool
- func (vec *T) Rows() int
- func (vec *T) Scale(f float64) *T
- func (vec *T) Scaled(f float64) T
- func (vec *T) Size() int
- func (vec *T) Slice() []float64
- func (vec *T) String() string
- func (vec *T) Sub(v *T) *T
- func (vec *T) Subed(v *T) T
Constants ¶
This section is empty.
Variables ¶
var ( // Zero holds a zero vector. Zero = T{} // UnitX holds a vector with X set to one. UnitX = T{1, 0, 0} // UnitY holds a vector with Y set to one. UnitY = T{0, 1, 0} // UnitZ holds a vector with Z set to one. UnitZ = T{0, 0, 1} // UnitXYZ holds a vector with X, Y, Z set to one. UnitXYZ = T{1, 1, 1} // Red holds the color red. Red = T{1, 0, 0} // Green holds the color green. Green = T{0, 1, 0} // Blue holds the color blue. Blue = T{0, 0, 1} // Black holds the color black. Black = T{0, 0, 0} // White holds the color white. White = T{1, 1, 1} // MinVal holds a vector with the smallest possible component values. MinVal = T{-math.MaxFloat64, -math.MaxFloat64, -math.MaxFloat64} // MaxVal holds a vector with the highest possible component values. MaxVal = T{+math.MaxFloat64, +math.MaxFloat64, +math.MaxFloat64} )
var Epsilon float64 = 1e-14
Epsilon is the tolerance used for numerical stability in floating-point comparisons. It is used by Normalize(), Normal(), and other methods to determine if a vector is effectively zero or already normalized. Can be adjusted for specific use cases. Default: 1e-14 for float64 precision.
var ( // MaxBox holds a box that contains the entire R3 space that can be represented as vec3 MaxBox = Box{MinVal, MaxVal} )
Functions ¶
func Angle ¶
Angle returns the angle value of the (shortest/smallest) angle between the two vectors a and b. The returned value is in the range 0 ≤ angle ≤ Pi radians.
func Cosine ¶
Cosine returns the cosine value of the angle between the two vectors. The returned cosine value is in the range -1.0 ≤ value ≤ 1.0.
func PracticallyEquals ¶
PracticallyEquals compares two values if they are equal with each other within a delta tolerance.
func Sinus ¶
Sinus returns the sinus value of the (shortest/smallest) angle between the two vectors a and b. The returned sine value is in the range 0.0 ≤ value ≤ 1.0. The angle is always considered to be in the range 0 to Pi radians and thus the sine value returned is always positive.
func SquareDistance ¶
SquareDistance the distance between two vectors squared (= distance*distance)
Types ¶
type Box ¶
Box is a coordinate system aligned 3D box defined by a Min and Max vector.
func (*Box) ContainsPoint ¶
ContainsPoint returns if a point is contained within the box.
func (*Box) Intersects ¶
Intersects returns true if this and the given box intersect. For an explanation of the algorithm, see http://rbrundritt.wordpress.com/2009/10/03/determining-if-two-bounding-boxes-overlap/
type T ¶
type T [3]float64
T represents a 3D vector.
func Add ¶
Add adds the composants of the two vectors and returns a new vector with the sum of the two vectors.
func Interpolate ¶
Interpolate interpolates between a and b at t (0,1).
func (*T) Clamped ¶
Clamped returns a copy of the vector with the components clamped to be in the range of min to max.
func (*T) Clamped01 ¶
Clamped01 returns a copy of the vector with the components clamped to be in the range of 0 to 1.
func (*T) IsZero ¶
IsZero checks if all elements of the vector are exactly zero. Uses exact equality comparison, which may not be suitable for floating-point math results. For tolerance-based comparison, use IsZeroEps instead.
func (*T) IsZeroEps ¶
IsZeroEps checks if all elements of the vector are zero within the given epsilon tolerance. This is the recommended method for comparing floating-point vectors that result from calculations. For exact zero comparison, use IsZero instead.
func (*T) LengthSqr ¶
LengthSqr returns the squared length of the vector. See also Length and Normalize.
func (*T) Muled ¶
Muled multiplies the components of the vector with the respective components of v and returns a copy of the result
func (*T) Normal ¶
Normal returns an orthogonal vector. Uses the package Epsilon variable when checking if the cross product is zero, which provides numerical stability when the input vector is parallel to UnitZ. Falls back to UnitX when the cross product is effectively zero.
func (*T) Normalize ¶
Normalize normalizes the vector to unit length. Uses the package Epsilon variable for numerical stability: - Vectors with squared length < Epsilon are considered zero and left unchanged - Vectors with squared length within Epsilon of 1.0 are considered already normalized
func (*T) Normalized ¶
Normalized returns a unit length normalized copy of the vector. Uses the package Epsilon variable for numerical stability. See Normalize() for details.
func (*T) PracticallyEquals ¶
PracticallyEquals compares two vectors if they are equal with each other within a delta tolerance.