Documentation ¶
Overview ¶
Package geom implements matrix math for 3D vectors and matrices.
Index ¶
- Variables
- func DefineZeroish(z float64)
- func RefZero() float64
- func Zeroish(a float64) bool
- type Angle
- type Matrix
- func (m Matrix) Add(n Matrix) Matrix
- func (m Matrix) AddS(n Matrix, s float64) Matrix
- func (m Matrix) Det() float64
- func (m Matrix) Eigen() (s float64, v Vector, a Angle, err error)
- func (m Matrix) Equals(n Matrix) bool
- func (m Matrix) Inv() (Matrix, error)
- func (m Matrix) Scale(s float64) Matrix
- func (m Matrix) Sub(n Matrix) Matrix
- func (m Matrix) Transpose() Matrix
- func (m Matrix) X() Vector
- func (m Matrix) XM(n Matrix) Matrix
- func (m Matrix) XV(v Vector) Vector
- func (m Matrix) Y() Vector
- func (m Matrix) Z() Vector
- type Vector
- func (v Vector) Add(u Vector) Vector
- func (v Vector) AddS(u Vector, s float64) Vector
- func (v Vector) Cross(u Vector) Vector
- func (v Vector) Dot(u Vector) float64
- func (v Vector) Equals(u Vector) bool
- func (v Vector) NonCollinear() (u Vector, err error)
- func (v Vector) Normalize() (u Vector, err error)
- func (v Vector) R() float64
- func (v Vector) RV(a Angle) (m Matrix, err error)
- func (v Vector) Scale(s float64) Vector
- func (v Vector) Sub(u Vector) Vector
Constants ¶
This section is empty.
Variables ¶
var ( ErrNormalNotPossible = errors.New("normal not possible") ErrNotValidMatrix = errors.New("not a 3x3 matrix") ErrSingular = errors.New("too close to singular") ErrNoNormalForZeroVector = errors.New("no non-collinear of zero vector") ErrIsIdentity = errors.New("too close to identity") )
ErrNormalNotPossible etc are errors returned by this package.
var I = M(1)
I is the identity matrix.
var ZeroM = M()
ZeroM is the zero matrix.
var ZeroV = V()
ZeroV is a zero vector.
Functions ¶
func DefineZeroish ¶
func DefineZeroish(z float64)
DefineZeroish sets the zeroEnough scale. It should be called with a positive value to have any effect. If called with zero or a negative number, it prevents the Zeroish() funcion from recognizing near zero. Zeroish defaults to treating 10^-7 as close enough to zero.
Types ¶
type Angle ¶
type Angle float64
Angle represents an angle.
func (Angle) LikeTan ¶
LikeTan returns an angle that is 180 degrees opposed to a. If a is non-positive, we add 180 deg, otherwise, we subtract 180 deg.
type Matrix ¶
type Matrix []float64
Matrix is a square 3x3 matrix type.
func M ¶
M defines a matrix. It takes a variable number of arguments, if the number of arguments is:
1 - create a matrix with this value used by the elements on the trace. 3 - create a matrix with these values used to fill the trace elements. 9 - each element is specified, left to right, top to bottom. other - start filling at [0][0], walking rows left to right until out of elements.
func (Matrix) Eigen ¶
Eigen decomposes a matrix into its determinant (s), its eigenvector (v) and an angle (a) which is the positive angle or rotation around v that the matrix represents.
func (Matrix) Inv ¶
Inv returns the inverse of a matrix. We use the Gauss-Jordan method to find the inverse.
type Vector ¶
type Vector []float64
Vector is a column vector with 3 elements.
func (Vector) Cross ¶
Cross returns the cross-product of two vectors. It returns a vector perpendicular to both u and v. It returns v x u using right hand rule.
func (Vector) NonCollinear ¶
NonCollinear returns a vector that is not a scalar multiple of the input.
func (Vector) RV ¶
RV returns a rotation matrix for an angle (a) around vector axis (v). The axis vector (v) need not be of unit length. This function uses the Rodrigues rotation formula.