Documentation ¶
Overview ¶
Package matrix represents a matrix of a given dimension. It provides commonly used matrix operations.
Index ¶
- func CheckInBounds(m *Matrix, row, col uint) error
- func Cofactor(m *Matrix, row, col uint) (float64, error)
- func Determinant(m *Matrix) (float64, error)
- func IsInvertible(m *Matrix) bool
- func MatrixToPoint(m *Matrix) (*point.Point, error)
- func MatrixToVector(m *Matrix) (*vector.Vector, error)
- func Minor(m *Matrix, row, col uint) (float64, error)
- type Matrix
- func Inverse(m *Matrix) (*Matrix, error)
- func Multiply(m1, m2 *Matrix) (*Matrix, error)
- func Multiply4x4(m1, m2 *Matrix) *Matrix
- func NewIdentityMatrix(size uint) *Matrix
- func NewMatrix(rows, cols uint) *Matrix
- func NewScalingMatrix(x, y, z float64) *Matrix
- func NewShearingMatrix(xy, xz, yx, yz, zx, zy float64) *Matrix
- func NewTranslationMatrix(x, y, z float64) *Matrix
- func NewXRotationMatrix(radians float64) *Matrix
- func NewYRotationMatrix(radians float64) *Matrix
- func NewZRotationMatrix(radians float64) *Matrix
- func PointToMatrix(pt *point.Point) *Matrix
- func Submatrix(m *Matrix, row, col uint) (*Matrix, error)
- func Transpose(m Matrix) *Matrix
- func VectorToMatrix(vec *vector.Vector) *Matrix
- func ViewTransform(from, to point.Point, up vector.Vector) *Matrix
- func (m *Matrix) Equals(m1 *Matrix) bool
- func (m *Matrix) GetCols() uint
- func (m *Matrix) GetRows() uint
- func (m *Matrix) GetValue(row, col uint) (float64, error)
- func (m *Matrix) RotateX(radians float64) *Matrix
- func (m *Matrix) RotateY(radians float64) *Matrix
- func (m *Matrix) RotateZ(radians float64) *Matrix
- func (m *Matrix) Scale(x, y, z float64) *Matrix
- func (m *Matrix) SetValue(row, col uint, val float64) error
- func (m *Matrix) Shear(xy, xz, yx, yz, zx, zy float64) *Matrix
- func (m *Matrix) Translate(x, y, z float64) *Matrix
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckInBounds ¶
CheckInBounds returns an error if either the row or column values are out of bounds of the passed Matrix.
func Cofactor ¶
Cofactor returns the cofactor of the submatrix. If the passed row or col are not in bounds of the passed Matrix, then an error is returned.
func Determinant ¶
Determinant calculate and returns the determinant of the passed Matrix. If the passed Matrix is not a square matrix, then an error is returned.
func IsInvertible ¶
IsInvertible returns true if the passed Matrix is invertible. The passed Matrix is invertible if it's determinant is equal to 0.
func MatrixToPoint ¶
MatrixToPoint returns a Point representation of the passed Matrix. An error is returned if the passed Matrix is not of a 3x1 or 4x1 dimension.
func MatrixToVector ¶
MatrixToVector returns a Point representation of the passed Matrix. An error is returned if the passed Matrix is not of a 3x1 or 4x1 dimension.
Types ¶
type Matrix ¶
type Matrix struct {
// contains filtered or unexported fields
}
Matrix represents an n-dimensional grid of floating point numbers.
func Multiply ¶
Multiply returns a new Matrix that is the result of multiplying the passed matrices. If the column length in m1 is not equal to the row length in m2, an error is returned.
func Multiply4x4 ¶
Multiply4x4 returns a new Matrix that is the result of multiplying the passed 4x4 matrices. The passed matrices are assumed to be of 4x4 order.
func NewIdentityMatrix ¶
NewIdentityMatrix returns a new identity Matrix having row and column length equal to the passed size.
func NewScalingMatrix ¶
NewScalingMatrix returns a new 4x4 scaling Matrix.
The scaling Matrix returned has the form:
| x 0 0 0 | | 0 y 0 0 | | 0 0 z 0 | | 0 0 0 1 |
func NewShearingMatrix ¶
NewShearingMatrix returns a new 4x4 shearing Matrix that can be used for a shear transformation of a Point.
The shearing Matrix returned has the form:
| 1 xy xz 0 | | yx 1 yz 0 | | zx zy 1 0 | | 0 0 0 1 |
func NewTranslationMatrix ¶
NewTranslationMatrix returns a new 4x4 translation Matrix.
The translation Matrix returned has the form:
| 1 0 0 x | | 0 1 0 y | | 0 0 1 z | | 0 0 0 1 |
func NewXRotationMatrix ¶
NewXRotationMatrix returns a new 4x4 rotation Matrix that can be used to rotate a Point or Vector around the X axis by the passed number of radians.
The rotation Matrix returned has the form:
| 1 0 0 0 | | 0 cos(r) -sin(r) 0 | | 0 sin(r) cos(r) 0 | | 0 0 0 1 |
func NewYRotationMatrix ¶
NewYRotationMatrix returns a new 4x4 rotation Matrix that can be used to rotate a Point or Vector around the Y axis by the passed number of radians.
The rotation Matrix returned has the form:
| cos(r) 0 sin(r) 0 | | 0 1 0 0 | | -sin(r) 0 cos(r) 0 | | 0 0 0 1 |
func NewZRotationMatrix ¶
NewZRotationMatrix returns a new 4x4 rotation Matrix that can be used to rotate a Point or Vector around the z-axis by the passed number of radians.
The rotation Matrix returned has the form:
| cos(r) -sin(r) 0 0 | | sin(r) cos(r) 0 0 | | 0 0 1 0 | | 0 0 0 1 |
func PointToMatrix ¶
PointToMatrix returns a 4x1 Matrix that represents the passed Point. The returned Matrix is known as a 'column vector' in linear algebra.
func Submatrix ¶
Submatrix returns a new Matrix that is the result of removing the passed row and column index from the passed Matrix. If the passed row or col are not in bounds of the passed Matrix, then an error is returned.
func Transpose ¶
Transpose returns a new Matrix that is the result of transposing the passed Matrix. Transposing a Matrix turns the nth row into the nth column in the resulting Matrix.
func VectorToMatrix ¶
VectorToMatrix returns a 4x1 Matrix that represents the passed Vector. The returned Matrix is known as a 'column vector' in linear algebra.
func ViewTransform ¶
ViewTransform returns a transformation matrix that can be used to transform a camera view in a scene.
The from parameter specifies where the eye is at in the scene. The to parameter specifies the point in the scene at which to look at. The up parameter specifies which direction is up.
func (*Matrix) Equals ¶
Equals returns true if this Matrix has identical rows, columns, and elements as the passed Matrix.
func (*Matrix) GetValue ¶
GetValue sets the passed value at the passed row and column in the Matrix.
func (*Matrix) RotateX ¶
RotateX rotates this Matrix around the x-axis by the passed number of radians. Rotation happens clockwise when looking down the positive x-axis towards the negative x-axis.
func (*Matrix) RotateY ¶
RotateY rotates this Matrix around the y-axis by the passed number of radians. Rotation happens clockwise when looking down the positive y-axis towards the negative y-axis.
func (*Matrix) RotateZ ¶
RotateZ rotates this Matrix around the z-axis by the passed number of radians. Rotation happens clockwise when looking down the positive z-axis towards the negative z-axis.
func (*Matrix) SetValue ¶
SetValue sets the passed value at the passed row and column in the Matrix.