MCPcopy
hub / github.com/tdewolff/canvas / Eigen

Method Eigen

util.go:747–770  ·  view source on GitHub ↗

Eigen returns the matrix eigenvalues and eigenvectors. The first eigenvalue is related to the first eigenvector, and so for the second pair. Eigenvectors are normalized.

()

Source from the content-addressed store, hash-verified

745
746// Eigen returns the matrix eigenvalues and eigenvectors. The first eigenvalue is related to the first eigenvector, and so for the second pair. Eigenvectors are normalized.
747func (m Matrix) Eigen() (float64, float64, Point, Point) {
748 if Equal(m[1][0], 0.0) && Equal(m[0][1], 0.0) {
749 return m[0][0], m[1][1], Point{1.0, 0.0}, Point{0.0, 1.0}
750 }
751
752 lambda1, lambda2 := solveQuadraticFormula(1.0, -m[0][0]-m[1][1], m.Det())
753 if math.IsNaN(lambda1) && math.IsNaN(lambda2) {
754 // either m[0][0] or m[1][1] is NaN or the the affine matrix has no real eigenvalues
755 return lambda1, lambda2, Point{}, Point{}
756 } else if math.IsNaN(lambda2) {
757 lambda2 = lambda1
758 }
759
760 // see http://www.math.harvard.edu/archive/21b_fall_04/exhibits/2dmatrices/index.html
761 var v1, v2 Point
762 if !Equal(m[1][0], 0.0) {
763 v1 = Point{lambda1 - m[1][1], m[1][0]}.Norm(1.0)
764 v2 = Point{lambda2 - m[1][1], m[1][0]}.Norm(1.0)
765 } else if !Equal(m[0][1], 0.0) {
766 v1 = Point{m[0][1], lambda1 - m[0][0]}.Norm(1.0)
767 v2 = Point{m[0][1], lambda2 - m[0][0]}.Norm(1.0)
768 }
769 return lambda1, lambda2, v1, v2
770}
771
772// Pos extracts the translation component as (tx,ty).
773func (m Matrix) Pos() (float64, float64) {

Callers 2

TestMatrixFunction · 0.80
TransformMethod · 0.80

Calls 4

DetMethod · 0.95
EqualFunction · 0.85
solveQuadraticFormulaFunction · 0.85
NormMethod · 0.80

Tested by 1

TestMatrixFunction · 0.64