Documentation ¶
Overview ¶
Package lmath implements a 3D linear math library.
Index ¶
- Constants
- Variables
- func AlmostEqual(x, y, absTol float64) bool
- func Clamp(v, min, max float64) float64
- func Degrees(radians float64) (degrees float64)
- func Equal(a, b float64) bool
- func Lerp(a, b, t float64) float64
- func Radians(degrees float64) (radians float64)
- func Rounded(v float64) float64
- type CoordSys
- func (c CoordSys) Back() Vec3
- func (c CoordSys) ConvertMat3(to CoordSys) Mat3
- func (c CoordSys) ConvertMat4(to CoordSys) Mat4
- func (c CoordSys) Down() Vec3
- func (c CoordSys) Forward() Vec3
- func (c CoordSys) Left() Vec3
- func (c CoordSys) LeftHanded() bool
- func (c CoordSys) Right() Vec3
- func (c CoordSys) RightFrontUp(right, forward, up float64) Vec3
- func (c CoordSys) RightHanded() bool
- func (c CoordSys) Up() Vec3
- type Mat3
- func Mat3Compose(scale, shear, hpr Vec3, cs CoordSys) Mat3
- func Mat3FromAxisAngle(axis Vec3, angle float64, cs CoordSys) Mat3
- func Mat3FromScaleShear(scale, shear Vec3, cs CoordSys) Mat3
- func Mat3FromTranslation(translation Vec2) Mat3
- func Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22 float64) Mat3
- func (a Mat3) Add(b Mat3) Mat3
- func (a Mat3) AddScalar(s float64) Mat3
- func (a Mat3) AlmostEquals(b Mat3, epsilon float64) bool
- func (a Mat3) Col(column int) Vec3
- func (a Mat3) ColVec2(column int) Vec2
- func (a Mat3) Decompose(cs CoordSys) (scale, shear, hpr Vec3)
- func (a Mat3) Determinant() float64
- func (a Mat3) DivScalar(s float64) Mat3
- func (a Mat3) Equals(b Mat3) bool
- func (a Mat3) Inverse() (result Mat3, ok bool)
- func (a Mat3) InverseTransposed() (result Mat3, ok bool)
- func (a Mat3) IsNaN() bool
- func (a Mat3) Mul(b Mat3) Mat3
- func (a Mat3) MulQuat(b Quat) Mat3
- func (a Mat3) MulScalar(s float64) Mat3
- func (a Mat3) Row(row int) Vec3
- func (a Mat3) RowVec2(row int) Vec2
- func (a Mat3) SetCol(column int, values Vec3) Mat3
- func (a Mat3) SetColVec2(column int, values Vec2) Mat3
- func (a Mat3) SetRow(row int, values Vec3) Mat3
- func (a Mat3) SetRowVec2(row int, values Vec2) Mat3
- func (a Mat3) String() string
- func (a Mat3) Sub(b Mat3) Mat3
- func (a Mat3) SubScalar(s float64) Mat3
- func (a Mat3) Transposed() Mat3
- type Mat4
- func Mat4FromAxisAngle(axis Vec3, angle float64, cs CoordSys) Mat4
- func Mat4FromFrustum(left, right, bottom, top, near, far float64) Mat4
- func Mat4FromScale(scale Vec3) Mat4
- func Mat4FromScaleShear(scale, shear Vec3, cs CoordSys) Mat4
- func Mat4FromTranslation(translation Vec3) Mat4
- func Mat4Ortho(left, right, bottom, top, near, far float64) Mat4
- func Mat4Perspective(fovY, aspectRatio, near, far float64) Mat4
- func Mat4UnOrtho(left, right, bottom, top, near, far float64) Mat4
- func Matrix4(...) Mat4
- func (a Mat4) Add(b Mat4) Mat4
- func (a Mat4) AddScalar(s float64) Mat4
- func (a Mat4) AffineInverse() (out Mat4, ok bool)
- func (a Mat4) AlmostEquals(b Mat4, epsilon float64) bool
- func (a Mat4) Col(column int) Vec4
- func (a Mat4) ColVec3(column int) Vec3
- func (a Mat4) Determinant() float64
- func (a Mat4) DivScalar(s float64) Mat4
- func (a Mat4) Equals(b Mat4) bool
- func (a Mat4) Inverse() (result Mat4, ok bool)
- func (a Mat4) IsNaN() bool
- func (a Mat4) Mul(b Mat4) Mat4
- func (a Mat4) MulQuat(b Quat) Mat4
- func (a Mat4) MulScalar(s float64) Mat4
- func (a Mat4) Project(p3 Vec3) (p2 Vec2, ok bool)
- func (a Mat4) Row(row int) Vec4
- func (a Mat4) RowVec3(row int) Vec3
- func (a Mat4) SetCol(column int, values Vec4) Mat4
- func (a Mat4) SetColVec3(column int, values Vec3) Mat4
- func (a Mat4) SetRow(row int, values Vec4) Mat4
- func (a Mat4) SetRowVec3(row int, values Vec3) Mat4
- func (a Mat4) SetTranslation(t Vec3) Mat4
- func (a Mat4) SetUpperMat3(b Mat3) Mat4
- func (a Mat4) String() string
- func (a Mat4) Sub(b Mat4) Mat4
- func (a Mat4) SubScalar(s float64) Mat4
- func (a Mat4) Translation() Vec3
- func (a Mat4) Transposed() Mat4
- func (a Mat4) UpperMat3() Mat3
- type Quat
- func (a Quat) Add(b Quat) Quat
- func (a Quat) AddScalar(b float64) Quat
- func (a Quat) AlmostEquals(b Quat, epsilon float64) bool
- func (a Quat) Angle() float64
- func (a Quat) AngleQuat(cs CoordSys, b Quat) float64
- func (a Quat) Axis() Vec3
- func (a Quat) Clamp(min, max float64) Quat
- func (a Quat) Conjugate() Quat
- func (a Quat) Div(b Quat) Quat
- func (a Quat) DivScalar(b float64) Quat
- func (a Quat) Dot(b Quat) float64
- func (a Quat) Equals(b Quat) bool
- func (a Quat) ExtractToMat3() Mat3
- func (a Quat) ExtractToMat4() Mat4
- func (a Quat) Forward(cs CoordSys) Vec3
- func (a Quat) Hpr(cs CoordSys) (hpr Vec3)
- func (a Quat) Inverse() Quat
- func (a Quat) IsNaN() bool
- func (a Quat) Length() float64
- func (a Quat) LengthSq() float64
- func (a Quat) Lerp(b Quat, t float64) Quat
- func (a Quat) Max(b Quat) Quat
- func (a Quat) Min(b Quat) Quat
- func (a Quat) Mul(b Quat) Quat
- func (a Quat) MulScalar(b float64) Quat
- func (a Quat) Normalized() Quat
- func (a Quat) Right(cs CoordSys) Vec3
- func (a Quat) String() string
- func (a Quat) Sub(b Quat) Quat
- func (a Quat) SubScalar(b float64) Quat
- func (a Quat) TransformVec3(v Vec3) Vec3
- func (a Quat) TransformVec4(v Vec4) Vec4
- func (a Quat) Up(cs CoordSys) Vec3
- func (a Quat) Vec4() Vec4
- type Rect3
- func (r Rect3) Add(p Vec3) Rect3
- func (r Rect3) AlmostEmpty(epsilon float64) bool
- func (r Rect3) AlmostEquals(s Rect3, epsilon float64) bool
- func (r Rect3) Area() float64
- func (r Rect3) Canon() Rect3
- func (r Rect3) Center() Vec3
- func (r Rect3) Closest(p Vec3) Vec3
- func (r Rect3) Contains(p Vec3) bool
- func (r Rect3) Corners() [8]Vec3
- func (r Rect3) Empty() bool
- func (r Rect3) Equals(s Rect3) bool
- func (r Rect3) Furthest(p Vec3) Vec3
- func (r Rect3) In(s Rect3) bool
- func (r Rect3) InSphere(s Sphere) bool
- func (r Rect3) Inset(n float64) Rect3
- func (r Rect3) Intersect(s Rect3) (largest Rect3, ok bool)
- func (r Rect3) Overlaps(s Rect3) bool
- func (r Rect3) Size() Vec3
- func (r Rect3) SqDistToPoint(p Vec3) float64
- func (r Rect3) String() string
- func (r Rect3) Sub(p Vec3) Rect3
- func (r Rect3) Union(s Rect3) Rect3
- type Sphere
- type Vec2
- func (a Vec2) Add(b Vec2) Vec2
- func (a Vec2) AddScalar(b float64) Vec2
- func (a Vec2) AlmostEquals(b Vec2, epsilon float64) bool
- func (a Vec2) Angle(b Vec2) float64
- func (a Vec2) AnyGreater(b Vec2) bool
- func (a Vec2) AnyLess(b Vec2) bool
- func (a Vec2) Clamp(min, max float64) Vec2
- func (a Vec2) Degrees() Vec2
- func (a Vec2) Div(b Vec2) Vec2
- func (a Vec2) DivScalar(b float64) Vec2
- func (a Vec2) Dot(b Vec2) float64
- func (a Vec2) Equals(b Vec2) bool
- func (a Vec2) Greater(b Vec2) bool
- func (a Vec2) Inverse() Vec2
- func (a Vec2) IsNaN() bool
- func (a Vec2) Length() float64
- func (a Vec2) LengthSq() float64
- func (a Vec2) Lerp(b Vec2, t float64) Vec2
- func (a Vec2) Less(b Vec2) bool
- func (a Vec2) Max(b Vec2) Vec2
- func (a Vec2) Min(b Vec2) Vec2
- func (a Vec2) Mul(b Vec2) Vec2
- func (a Vec2) MulScalar(b float64) Vec2
- func (a Vec2) Normalized() (v Vec2, ok bool)
- func (a Vec2) Proj(b Vec2) Vec2
- func (a Vec2) Radians() Vec2
- func (a Vec2) Rounded() Vec2
- func (a Vec2) String() string
- func (a Vec2) Sub(b Vec2) Vec2
- func (a Vec2) SubScalar(b float64) Vec2
- func (a Vec2) TransformPointVec2(b Mat3) Vec2
- func (a Vec2) TransformVec2(b Mat3) Vec2
- type Vec3
- func (a Vec3) Add(b Vec3) Vec3
- func (a Vec3) AddScalar(b float64) Vec3
- func (a Vec3) AlmostEquals(b Vec3, epsilon float64) bool
- func (a Vec3) Angle(b Vec3) float64
- func (a Vec3) AnyGreater(b Vec3) bool
- func (a Vec3) AnyLess(b Vec3) bool
- func (a Vec3) Clamp(min, max float64) Vec3
- func (a Vec3) Cross(b Vec3) Vec3
- func (a Vec3) Degrees() Vec3
- func (a Vec3) Div(b Vec3) Vec3
- func (a Vec3) DivScalar(b float64) Vec3
- func (a Vec3) Dot(b Vec3) float64
- func (a Vec3) Equals(b Vec3) bool
- func (a Vec3) Greater(b Vec3) bool
- func (v Vec3) HprToXyz() Vec3
- func (a Vec3) Inverse() Vec3
- func (a Vec3) IsNaN() bool
- func (a Vec3) Length() float64
- func (a Vec3) LengthSq() float64
- func (a Vec3) Lerp(b Vec3, t float64) Vec3
- func (a Vec3) Less(b Vec3) bool
- func (a Vec3) Max(b Vec3) Vec3
- func (a Vec3) Min(b Vec3) Vec3
- func (a Vec3) Mul(b Vec3) Vec3
- func (a Vec3) MulScalar(b float64) Vec3
- func (a Vec3) Normalized() (v Vec3, ok bool)
- func (a Vec3) Proj(b Vec3) Vec3
- func (a Vec3) Radians() Vec3
- func (a Vec3) Rounded() Vec3
- func (a Vec3) SignedAngle(b, reference Vec3) float64
- func (a Vec3) String() string
- func (a Vec3) Sub(b Vec3) Vec3
- func (a Vec3) SubScalar(b float64) Vec3
- func (a Vec3) TransformGeneralMat3(b Mat3) Vec3
- func (a Vec3) TransformGeneralMat4(b Mat4) Vec3
- func (a Vec3) TransformMat3(b Mat3) Vec3
- func (a Vec3) TransformMat4(b Mat4) Vec3
- func (a Vec3) TransformVecMat4(b Mat4) Vec3
- func (v Vec3) XyzToHpr() Vec3
- type Vec4
- func (a Vec4) Add(b Vec4) Vec4
- func (a Vec4) AddScalar(b float64) Vec4
- func (a Vec4) AlmostEquals(b Vec4, epsilon float64) bool
- func (a Vec4) AnyGreater(b Vec4) bool
- func (a Vec4) AnyLess(b Vec4) bool
- func (a Vec4) Clamp(min, max float64) Vec4
- func (a Vec4) Degrees() Vec4
- func (a Vec4) Div(b Vec4) Vec4
- func (a Vec4) DivScalar(b float64) Vec4
- func (a Vec4) Dot(b Vec4) float64
- func (a Vec4) Equals(b Vec4) bool
- func (a Vec4) Greater(b Vec4) bool
- func (a Vec4) IsNaN() bool
- func (a Vec4) Length() float64
- func (a Vec4) LengthSq() float64
- func (a Vec4) Lerp(b Vec4, t float64) Vec4
- func (a Vec4) Less(b Vec4) bool
- func (a Vec4) Max(b Vec4) Vec4
- func (a Vec4) Min(b Vec4) Vec4
- func (a Vec4) Mul(b Vec4) Vec4
- func (a Vec4) MulScalar(b float64) Vec4
- func (a Vec4) Normalized() (v Vec4, ok bool)
- func (a Vec4) Proj(b Vec4) Vec4
- func (a Vec4) Quat() Quat
- func (a Vec4) Radians() Vec4
- func (a Vec4) Rounded() Vec4
- func (a Vec4) String() string
- func (a Vec4) Sub(b Vec4) Vec4
- func (a Vec4) SubScalar(b float64) Vec4
- func (a Vec4) Transform(b Mat4) Vec4
- func (a Vec4) Vec3() Vec3
Constants ¶
const EPSILON = 1.0E-8
The default epsilon value used for floating point comparisons.
Variables ¶
var ( Mat3Identity = Matrix3( 1, 0, 0, 0, 1, 0, 0, 0, 1, ) Mat3YToZUp = Matrix3( 1, 0, 0, 0, 0, 1, 0, -1, 0, ) Mat3ZToYUp = Matrix3( 1, 0, 0, 0, 0, -1, 0, 1, 0, ) Mat3FlipY = Matrix3( 1, 0, 0, 0, -1, 0, 0, 0, 1, ) Mat3FlipZ = Matrix3( 1, 0, 0, 0, 1, 0, 0, 0, -1, ) Mat3LZToRY = Mat3FlipY.Mul(Mat3ZToYUp) Mat3LYToRZ = Mat3FlipZ.Mul(Mat3YToZUp) )
var ( Mat4Identity = Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, ) Mat4Zeros = Matrix4( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ) Mat4Ones = Matrix4( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ) Mat4YToZUp = Matrix4( 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, ) Mat4ZToYUp = Matrix4( 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, ) Mat4FlipY = Matrix4( 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, ) Mat4FlipZ = Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, ) Mat4LZToRY = Mat4FlipY.Mul(Mat4ZToYUp) Mat4LYToRZ = Mat4FlipZ.Mul(Mat4YToZUp) )
var ( QuatIdentity = Quat{1, 0, 0, 0} QuatZero = Quat{0, 0, 0, 0} )
var ( Vec2One = Vec2{1, 1} Vec2XUnit = Vec2{1, 0} Vec2YUnit = Vec2{0, 1} Vec2Zero = Vec2{0, 0} )
var ( Vec3One = Vec3{1, 1, 1} Vec3XUnit = Vec3{1, 0, 0} Vec3YUnit = Vec3{0, 1, 0} Vec3ZUnit = Vec3{0, 0, 1} Vec3Zero = Vec3{0, 0, 0} )
var ( Vec4One = Vec4{1, 1, 1, 1} Vec4XUnit = Vec4{1, 0, 0, 0} Vec4YUnit = Vec4{0, 1, 0, 0} Vec4ZUnit = Vec4{0, 0, 1, 0} Vec4WUnit = Vec4{0, 0, 0, 1} Vec4Zero = Vec4{0, 0, 0, 0} )
var Rect3Zero = Rect3{}
Rect3Zero is the zero rectangle.
Functions ¶
func AlmostEqual ¶
AlmostEqual tells if the two floating point values x and y are considered equal within the specified absolute==relative tolerence value.
The method of comparison used is that described at:
http://realtimecollisiondetection.net/blog/?p=89
func Equal ¶
Equal tells if the two floating point values a and b are considered equal within the default EPSILON comparison value. It is short-handed for:
AlmostEqual(a, b, EPSILON)
func Lerp ¶
Lerp performs a linear interpolation between a and b. The t parameter is a number in the range 0.0-1.0. Some examples:
Lerp(0, 10, 0) == 0 Lerp(0, 10, 0.5) == 5 Lerp(0, 10, 1) == 10
The interpolation method is precise, so it is guaranteed that:
Lerp(a, b, 1) == a
Types ¶
type CoordSys ¶
type CoordSys uint8
CoordSys represents an specific coordinate system.
const ( // Invalid coordinate system CoordSysInvalid CoordSys = iota // Z up axis, right handed coordinate system CoordSysZUpRight // Y up axis, right handed coordinate system CoordSysYUpRight // Z up axis, left handed coordinate system CoordSysZUpLeft // Y up axis, left handed coordinate system CoordSysYUpLeft )
func (CoordSys) Back ¶
Back returns the back vector for the given coordinate system A panic will occur if the coordinate system is invalid.
func (CoordSys) ConvertMat3 ¶
ConvertMat3 returns a matrix that transforms from the indicated coordinate system, to the coordinate system specified. A panic will occur if the coordinate system is invalid.
func (CoordSys) ConvertMat4 ¶
ConvertMat4 returns a matrix that transforms from the indicated coordinate system, to the coordinate system specified. A panic will occur if the coordinate system is invalid.
func (CoordSys) Down ¶
Down returns the down vector for the given coordinate system A panic will occur if the coordinate system is invalid.
func (CoordSys) Forward ¶
Forward returns the forward vector for the given coordinate system A panic will occur if the coordinate system is invalid.
func (CoordSys) Left ¶
Left returns the left vector for the given coordinate system A panic will occur if the coordinate system is invalid.
func (CoordSys) Right ¶
Right returns the right vector for the given coordinate system A panic will occur if the coordinate system is invalid.
func (CoordSys) RightFrontUp ¶
RightFrontUp returns an vector that is described by it's right, forward, and up components in whatever way the specified coordinate system represents that vector. A panic will occur if the coordinate system is invalid.
func (CoordSys) RightHanded ¶
RightHanded tells whether this coordinate system is right-handed. A panic will occur if the coordinate system is invalid.
type Mat3 ¶
type Mat3 [3][3]float64
Mat3 represents an 3x3 matrix, indices are in m[row][column] order.
func Mat3Compose ¶
Mat3Compose composes a transformation matrix that applies the given scaling, shearing, and hew/pitch/roll euler rotation values for the given coordinate system.
func Mat3FromAxisAngle ¶
Mat3FromAxisAngle returns a rotation matrix that will rotate by the given angle in radians counterclockwise about the indicated axis.
func Mat3FromScaleShear ¶
Mat3FromScaleShear returns a matrix that will apply the given scaling and shearing values along their respective axis in the specified coordinate system. A panic will occur if the coordinate system is invalid.
func Mat3FromTranslation ¶
Mat3FromTranslation returns a matrix that will apply the given translation vector.
func (Mat3) AlmostEquals ¶
AlmostEquals tells whether a is memberwise equal to b using the specified epsilon value.
func (Mat3) Col ¶
Col returns the values in the specified matrix column as an three-component vector. The column parameter must be 0, 1, or 2 or else a panic will occur.
func (Mat3) ColVec2 ¶
ColVec2 returns the values in the specified matrix column as an two-component vector, ignoring the third element of the column. The column parameter must be 0, 1, or 2 or else an panic will occur.
func (Mat3) Decompose ¶
Decompose extracts out the scaling, shearing, and hew/pitch/roll components from the composed rotation matrix. The coordinate system must be one of: CoordSysZUpRight, CoordSysZUpLeft, or CoordSysYUpLeft.
func (Mat3) Determinant ¶
Determinant calculates and returns the determinant of the matrix.
func (Mat3) Equals ¶
Equals tells whether a is memberwise equal to b using the default EPSILON value.
func (Mat3) Inverse ¶
Inverse returns the inverse of the matrix a. This is a fully general operation and has no requirements about the transformation represented by this matrix. Returned is result=Mat3Identity, ok=false if the matrix was singular and could not be inverted.
func (Mat3) InverseTransposed ¶
InverseTransposed simultaneously inverts and transposes the matrix and returns it. Returned is result=Mat3Identity, ok=false if the matrix was singular and could not be inverted.
func (Mat3) MulQuat ¶
MulQuat multiplies the matrix by the specified quaternion rotation and returns the result,
func (Mat3) Row ¶
Row returns the values in the specified matrix row as an three-component vector. The row parameter must be 0, 1, or 2 or else a panic will occur.
func (Mat3) RowVec2 ¶
RowVec2 returns the values in the specified matrix row as an two-component vector, the third element of the row is ignored. The row parameter must be 0, 1, or 2 or else a panic will occur.
func (Mat3) SetCol ¶
SetCol sets the values in the specified matrix column to the values in the specified three-component vector. The column parameter must be 0, 1, or 2 or else a panic will occur.
func (Mat3) SetColVec2 ¶
SetColVec2 sets the values in the specified matrix column to the values in the specified two-component vector, leaving the third element in the column untouched. The column parameter must be 0, 1, or 2 or else an panic will occur.
func (Mat3) SetRow ¶
SetRow sets the values of the specified matrix row to the values in the specified three-component vector. The row parameter must be 0, 1, or 2 or else a panic will occur.
func (Mat3) SetRowVec2 ¶
SetRowVec2 sets the values in the specified matrix row to the values in the specified three-component vector, leaving the third element in the row untouched. The row parameter must be 0, 1, or 2 or else a panic will occur.
func (Mat3) Transposed ¶
Transposed returns the transposed version of matrix a.
type Mat4 ¶
type Mat4 [4][4]float64
Mat4 represents an 4x4 matrix, indices are in m[row][column] order.
func Mat4FromAxisAngle ¶
Mat4FromAxisAngle returns a rotation matrix that will rotate by the given angle in radians counterclockwise about the indicated axis.
func Mat4FromFrustum ¶
Mat4FromFrustum returns a matrix that represents the given frustum given the specified bounds.
func Mat4FromScale ¶
Mat4FromScale returns a matrix that will apply the given scaling values along their respective axis.
func Mat4FromScaleShear ¶
Mat4FromScaleShear returns a matrix that will apply the given scaling and shearing values along their respective axis in the specified coordinate system. A panic will occur if the coordinate system is invalid.
func Mat4FromTranslation ¶
Mat4FromTranslation returns a matrix that will apply the given translation vector.
func Mat4Ortho ¶
Mat4Ortho returns a orthographic projection matrix given the specified frustum bounds. See: http://en.wikipedia.org/wiki/Orthographic_projection_(geometry)
func Mat4Perspective ¶
Mat4Perspective returns a matrix that represents a perspective viewing frustum given the specified field of view, aspect ratio, and near/far values.
func Mat4UnOrtho ¶
Mat4UnOrtho returns a orthographic unprojection matrix given the specified frustum bounds. See: http://en.wikipedia.org/wiki/Orthographic_projection_(geometry)
func Matrix4 ¶
func Matrix4(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33 float64) Mat4
Matrix4 returns an new *Mat4 given the specified matrix components.
func (Mat4) AddScalar ¶
AddScalar performs in-place memberwise addition a + s and returns the result.
func (Mat4) AffineInverse ¶
AffineInverse returns the inverse of the affine transformation matrix and returns the result. Returned is Mat4Identity, ok=false if the matrix was singular and could not be inverted,
func (Mat4) AlmostEquals ¶
AlmostEquals tells whether a is memberwise equal to b using the specified epsilon value.
func (Mat4) Col ¶
Col returns the values in the specified matrix column as an four-component vector. The column parameter must be 0, 1, 2, or 3 or else an panic will occur.
func (Mat4) ColVec3 ¶
ColVec3 returns the values in the specified matrix column as an three-component vector, ignoring the fourth element of the column. The column parameter must be 0, 1, 2, or 3 or else an panic will occur.
func (Mat4) Determinant ¶
Determinant calculates and returns the determinant of the matrix.
func (Mat4) DivScalar ¶
DivScalar performs in-place memberwise division a / s and returns the result.
func (Mat4) Equals ¶
Equals tells whether a is memberwise equal to b using the default EPSILON value.
func (Mat4) Inverse ¶
Inverse returns the inverse of the matrix, as a fully general operation and makes no requirements about the type of transform represented by the matrix. Returned is Mat4Identity, ok=false if the matrix was singular and could not be inverted.
func (Mat4) MulScalar ¶
MulScalar performs in-place memberwise multiplication a * s and returns the result.
func (Mat4) Project ¶
Project returns a 2D point in the range -1 to +1 given a 3D point also in the frustum matrix a's coordinate space.
If ok=false is returned then the point is outside of the frustum matrix a, and the returned point may not be meaningful.
func (Mat4) Row ¶
Row returns the values in the specified matrix row as an three-component vector. The row parameter must be 0, 1, 2, or 3 or else an panic will occur.
func (Mat4) RowVec3 ¶
RowVec3 returns the values in the specified matrix row as an three-component vector, the fourth element of the row is ignored. The row parameter must be 0, 1, 2, or 3 or else an panic will occur.
func (Mat4) SetCol ¶
SetCol sets the values in the specified matrix column to the values in the specified four-component vector. The column parameter must be 0, 1, 2, or 3 or else an panic will occur.
func (Mat4) SetColVec3 ¶
SetColVec3 sets the values in the specified matrix column to the values in the specified three-component vector, leaving the fourth element in the column untouched. The column parameter must be 0, 1, 2, or 3 or else an panic will occur.
func (Mat4) SetRow ¶
SetRow sets the values in the specified matrix row to the values in the specified four-component vector. The row parameter must be 0, 1, 2, or 3 or else an panic will occur.
func (Mat4) SetRowVec3 ¶
SetRowVec3 sets the values in the specified matrix row to the values in the specified three-component vector, leaving the fourth element in the row untouched. The row parameter must be 0, 1, 2, or 3 or else an panic will occur.
func (Mat4) SetTranslation ¶
SetTranslation sets the translation components of the matrix to the given vector and returns the result.
func (Mat4) SetUpperMat3 ¶
SetUpperMat3 sets the upper-left 3x3 matrix to the specified one and returns the new 4x4 matrix.
func (Mat4) SubScalar ¶
SubScalar performs in-place memberwise subtraction a - s and returns the result.
func (Mat4) Translation ¶
Translation returns the translation components of the matrix as a vector.
func (Mat4) Transposed ¶
Transposed returns the transposed version of matrix a.
type Quat ¶
type Quat struct {
W, X, Y, Z float64
}
Quat represents a four component vector.
func QuatFromAxisAngle ¶
QuatFromAxisAngle returns a quaternion rotation which represents the given angle of rotation in radians about the given axis.
func QuatFromHpr ¶
QuatFromHpr returns a quaternion equivilent to the heading, pithc, and roll Euler angles in radians for the given coordinate system.
func QuatFromMat3 ¶
QuatFromMat3 returns a quaternion rotation according to the rotation represented by the matrix.
func (Quat) AlmostEquals ¶
AlmostEquals tells if a == b using the specified epsilon value.
func (Quat) Angle ¶
Angle returns the rotation represented by the quaternion as an angle about an arbitrary axis (returned by the Axis() function), the returned value is expressed in radian units counterclockwise about the axis.
func (Quat) AngleQuat ¶
Angle returns the angle between the orientation represented by this quaternion and the orientation represent by the quaternion b in radians.
func (Quat) Axis ¶
Axis returns the axis of the rotation represented by the quaternion. The returned vector is not normalized.
func (Quat) Clamp ¶
Clamp clamps each value in the quaternion to the range of [min, max] and returns it.
func (Quat) ExtractToMat3 ¶
ExtractToMat3 extracts the quaternion into a three-component matrix and returns it.
func (Quat) ExtractToMat4 ¶
ExtractToMat4 extracts the quaternion into a four-component matrix and returns it.
func (Quat) Forward ¶
Forward returns the orientation represented by this quaternion expressed as an forward vector.
func (Quat) Hpr ¶
Hpr extracts the equivilent heading, pitch, and roll euler angles in radians from the quaternion for the given coordinate system.
func (Quat) Length ¶
Length returns the magnitude of this quaternion. To avoid a sqrt call when strictly comparing distances, LengthSq can be used instead.
func (Quat) LengthSq ¶
LengthSq returns the magnitude squared of this quaternion, useful for comparing distances.
func (Quat) Lerp ¶
Lerp returns a quaternion representing the linear interpolation between the quaternions a and b. The t parameter is the amount to interpolate (0.0 - 1.0) between the quaternions.
func (Quat) Max ¶
Max returns a quaternion representing the largest components of both the quaternions.
func (Quat) Min ¶
Min returns a quaternion representing the smallest components of both the quaternions.
func (Quat) Normalized ¶
Normalized returns the normalized (i.e. length/magnitude == 1) quaternion of a. The quaternion a must be non-zero or else division by zero may occur.
func (Quat) Right ¶
Right returns the orientation represented by this quaternion expressed as an right vector.
func (Quat) TransformVec3 ¶
TransformVec3 transforms the 3-component vector by the specified quaternion rotation and returns the result.
func (Quat) TransformVec4 ¶
TransformVec4 transforms the 4-component vector by the specified quaternion rotation and returns the result.
type Rect3 ¶
type Rect3 struct {
Min, Max Vec3
}
Rect3 represents a 3D rectangle. Although it can be used to represent any form of 3D rectangle, a common use is for representing axis-aligned bounding boxes.
The rectangle contains all points where:
Min.X <= X < Max.X Min.Y <= Y < Max.Y Min.Z <= Z < Max.Z
A rectangle is considered empty if it would contain no points.
func (Rect3) AlmostEmpty ¶
AlmostEmpty reports whether the rectangle contains no points using the specified epsilon value.
func (Rect3) AlmostEquals ¶
AlmostEquals tells whether a is memberwise equal to b using the specified epsilon value.
func (Rect3) Canon ¶
Canon returns the canonical version of r. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.
func (Rect3) Corners ¶
Corners returns an array of the eight corner points of this 3D rectangle. The corners are returned in the order of left to right, back to front, bottom to top:
left, back, bottom right, back, bottom left, front, bottom right, front, bottom left, back, top right, back, top left, front, top right, front, top
func (Rect3) Empty ¶
Empty reports whether the rectangle contains no points using the default epsilon for equality.
func (Rect3) Equals ¶
Equals reports whether r and s are equal using the default epsilon for equality.
func (Rect3) Furthest ¶
Furthest returns the furthest point away from p contained by this rectangle.
func (Rect3) Inset ¶
Inset returns the rectangle r inset by n, which may be negative. If either of r's dimensions is less than 2*n then an empty rectangle near the center of r will be returned.
func (Rect3) Intersect ¶
Intersect intersects the two rectangles and returns the largest rectangle that is contained by both r and s. If the two rectangles do not overlap then Rect3Zero, ok=false will be returned.
For simple boolean tests, one should instead use the Overlaps method (as it is equivilent and faster).
func (Rect3) Overlaps ¶
Overlaps reports whether r and s have a non-empty intersection. It is functionally equivilent to, but faster than:
_, overlaps := r.Intersect(s)
func (Rect3) Size ¶
Size returns a vector whose X, Y, and Z components directly relate to the width, depth, and height of this rectangle.
func (Rect3) SqDistToPoint ¶
SqDistToPoint returns the squared distance between the point p and the rectangle r. It is functionally equivilent to (but faster than):
dist2 := r.Closest(p).Sub(p).LengthSq()
type Sphere ¶
Sphere describes a 3D sphere composed of a center point and radius.
func (Sphere) InRect3 ¶
InRect3 reports whether the sphere s is completely inside the rectangle r. It is short-hand for:
s.Rect3().In(r)
func (Sphere) OverlapsRect3 ¶
OverlapsRect3 reports whether the sphere s has a non-empty intersection with the rectangle r.
type Vec2 ¶
type Vec2 struct {
X, Y float64
}
Vec2 represents a 2D vector or point.
func (Vec2) AlmostEquals ¶
AlmostEquals tells if a == b using the specified epsilon value.
func (Vec2) AnyGreater ¶
AnyGreater tells if a is componentwise any greater than b:
return a.X > b.X || a.Y > b.Y
func (Vec2) AnyLess ¶
AnyLess tells if a is componentwise any less than b:
return a.X < b.X || a.Y < b.Y
func (Vec2) Clamp ¶
Clamp clamps each value in the vector to the range of [min, max] and returns it.
func (Vec2) Degrees ¶
Degrees converts each value in the vector from radians to degrees and returns it.
func (Vec2) Greater ¶
Greater tells if a is componentwise greater than b:
return a.X > b.X && a.Y > b.Y
func (Vec2) Length ¶
Length returns the magnitude of this vector. To avoid a sqrt call when strictly comparing distances, LengthSq can be used instead.
func (Vec2) LengthSq ¶
LengthSq returns the magnitude squared of this vector, useful for comparing distances.
func (Vec2) Lerp ¶
Lerp returns a vector representing the linear interpolation between the vectors a and b. The t parameter is the amount to interpolate (0.0 - 1.0) between the vectors.
func (Vec2) Normalized ¶
Normalized returns the normalized (i.e. length/magnitude == 1) vector of a. If the vector's length is zero (and division by zero would occur) then [Vec2Zero, false] is returned.
func (Vec2) Radians ¶
Radians converts each value in the vector from degrees to radians and returns it.
func (Vec2) Rounded ¶
Rounded rounds each value in the vector to the nearest whole number and returns it.
func (Vec2) TransformPointVec2 ¶
TransformPointVec2 transforms a 2-component point vector by the matrix (with translation component) and returns the result. This function assumes that the matrix is an affine transformation.
func (Vec2) TransformVec2 ¶
TransformVec2 transforms a 2-component point vector by the matrix (without translation component) and returns the result. This function assumes that the matrix is an affine transformation.
type Vec3 ¶
type Vec3 struct {
X, Y, Z float64
}
Vec3 represents a 3D vector or point.
func CartToSphere ¶
CartToSphere converts the point in cartesian coordinate space, p, into spherical coordinates in the form of Vec3{radiys, inclination, azimuth} and returns it.
It is implemented according to:
http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
func SphereToCart ¶
SphereToCart converts the Vec2{inclination, azimuth} point on a sphere of the given radius to cartesian coordinates and returns it.
It is implemented according to:
http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
func (Vec3) AlmostEquals ¶
AlmostEquals tells if a == b using the specified epsilon value.
func (Vec3) AnyGreater ¶
AnyGreater tells if a is componentwise any greater than b:
return a.X > b.X || a.Y > b.Y || a.Z > b.Z
func (Vec3) AnyLess ¶
AnyLess tells if a is componentwise any less than b:
return a.X < b.X || a.Y < b.Y || a.Z < b.Z
func (Vec3) Clamp ¶
Clamp clamps each value in the vector to the range of [min, max] and returns it.
func (Vec3) Degrees ¶
Degrees converts each value in the vector from radians to degrees and returns it.
func (Vec3) Greater ¶
Greater tells if a is componentwise greater than b:
return a.X > b.X && a.Y > b.Y && a.Z > b.Z
func (Vec3) Length ¶
Length returns the magnitude of this vector. To avoid a sqrt call when strictly comparing distances, LengthSq can be used instead.
func (Vec3) LengthSq ¶
LengthSq returns the magnitude squared of this vector, useful for comparing distances.
func (Vec3) Lerp ¶
Lerp returns a vector representing the linear interpolation between the vectors a and b. The t parameter is the amount to interpolate (0.0 - 1.0) between the vectors.
func (Vec3) Less ¶
Less tells if a is componentwise less than b:
return a.X < b.X && a.Y < b.Y && a.Z < b.Z
func (Vec3) Normalized ¶
Normalized returns the normalized (i.e. length/magnitude == 1) vector of a. If the vector's length is zero (and division by zero would occur) then [Vec3Zero, false] is returned.
func (Vec3) Radians ¶
Radians converts each value in the vector from degrees to radians and returns it.
func (Vec3) Rounded ¶
Rounded rounds each value in the vector to the nearest whole number and returns it.
func (Vec3) SignedAngle ¶
SignedAngle returns the signed angle between the vectors a and b, in radians. The returned angle is positive if the rotation from a to b is clockwise when looking in the direction of the reference vector.
func (Vec3) TransformGeneralMat3 ¶
TransformGeneralMat3 transforms this vector by the matrix (vector * matrix) without translation component, and returns the result, as a fully general operation.
func (Vec3) TransformGeneralMat4 ¶
TransformGeneralMat4 transforms this vector by the matrix (vector * matrix) without translation component, and returns the result, as a fully general operation.
func (Vec3) TransformMat3 ¶
TransformMat3 transforms this point vector by the matrix (vector * matrix), and returns the result. Can operate on orthonormal transformation matrices.
func (Vec3) TransformMat4 ¶
TransformMat4 transforms this point vector by the affine transformation matrix (vector * matrix) and returns the result. The matrix parameter must be an affine transformation matrix.
func (Vec3) TransformVecMat4 ¶
TransformVecMat4 transforms this vector (without translation component) by the orthonormal matrix and returns the result.
type Vec4 ¶
type Vec4 struct {
X, Y, Z, W float64
}
Vec4 represents a four component vector.
func (Vec4) AlmostEquals ¶
AlmostEquals tells if a == b using the specified epsilon value.
func (Vec4) AnyGreater ¶
AnyGreater tells if a is componentwise any greater than b:
return a.X > b.X || a.Y > b.Y || a.Z > b.Z || a.W > b.W
func (Vec4) AnyLess ¶
AnyLess tells if a is componentwise any less than b:
return a.X < b.X || a.Y < b.Y || a.Z < b.Z || a.W < b.W
func (Vec4) Clamp ¶
Clamp clamps each value in the vector to the range of [min, max] and returns it.
func (Vec4) Degrees ¶
Degrees converts each value in the vector from radians to degrees and returns it.
func (Vec4) Greater ¶
Greater tells if a is componentwise greater than b:
return a.X > b.X && a.Y > b.Y
func (Vec4) Length ¶
Length returns the magnitude of this vector. To avoid a sqrt call when strictly comparing distances, LengthSq can be used instead.
func (Vec4) LengthSq ¶
LengthSq returns the magnitude squared of this vector, useful for comparing distances.
func (Vec4) Lerp ¶
Lerp returns a vector representing the linear interpolation between the vectors a and b. The t parameter is the amount to interpolate (0.0 - 1.0) between the vectors.
func (Vec4) Normalized ¶
Normalized returns the normalized (i.e. length/magnitude == 1) vector of a. If the vector's length is zero (and division by zero would occur) then [Vec4Zero, false] is returned.
func (Vec4) Quat ¶
Quat converts this vector to a quaternion. It's short-hand for:
Quat{a.X, a.Y, a.Z, a.W}
func (Vec4) Radians ¶
Radians converts each value in the vector from degrees to radians and returns it.
func (Vec4) Rounded ¶
Rounded rounds each value in the vector to the nearest whole number and returns it.