Hi,
I want to graphically display eigen-vectors and eigen-values of a matrix
I have begined with this relatively basic 3x3 matrix given at Vecteurs propres et espaces propres d'une matrice 3x3 - YouTube
-1 2 2
2 2 -1
2 -1 2
Eigen-values of this matrix are 3 and -3
Eigen vectors of this matrix are
E3 = { 1/2 , 1 , 0 } and { 1/2 , 0 , 1 }
E-3 = { -2 , 1, 1 }
I have used the 3x3 matrix as three 3D coordinates for to display it as a triangle :
(since this is a symetric matrix, no need to handle the row or column major order)
x0 y0 z0
x1 y1 z1
x2 y2 z2
where (x0,y0,z0), (x1,y1,z1) and (x2,y2,z2) are 3D coordinates of the triangle vertices
After I have displayed eigen-vectors as 3D vectors for to try to understand what they really represent in 3D
(for this, I display each eigen-vector as a line in a different color)
But I don’t graphically see what is the rapport between the triangle and his eigen-vectors
(the only think that I clearly see is that eigen-vectors are orthogonals but this is all)
Here is the basic code that I actually use for to display the triangle and his eigen-vectors
#include <GL/gl.h>
#include <GL/glut.h>
float angle = 0.0f;
float angleInc = 1;
GLfloat vertices[3][3];
void SetVertice( int idx, GLfloat x, GLfloat y, GLfloat z)
{
vertices[idx][0] = x;
vertices[idx][1] = y;
vertices[idx][2] = z;
}
void MakeArrays()
{
SetVertice(0, -1, 2, 2);
SetVertice(1, 2, 2, -1);
SetVertice(2, 2, -1, 2);
}
void DrawAxes()
{
glBegin(GL_LINES);
glColor3f( 1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( 1.0f, 0.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f( 0.0f, 0.0f, 1.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 0.0f, 1.0f);
glEnd();
}
void DrawHeigenVectors()
{
glBegin(GL_LINES);
glColor3f( 1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( 0.5f, 1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( 0.5f, 0.0f, 1.0f);
glColor3f( 0.0f, 0.0f, 1.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( -2.0f, 1.0f, 1.0f);
glEnd();
}
void DrawTriangle()
{
int i;
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLES);
for( i = 0 ; i < 3 ; i++)
{
glVertex3fv(vertices[i]);
}
glEnd();
}
void renderScene(void)
{
// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Set the camera
gluLookAt( 0.0f, 0.0f, 10.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
glRotatef(angle, 1.0f, 1.0f, 1.0f);
// DrawAxes();
DrawTriangle();
DrawHeigenVectors();
angle += angleInc;
glutSwapBuffers();
}
void changeSize(int w, int h)
{
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (h == 0)
h = 1;
float ratio = w * 1.0 / h;
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset Matrix
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(45.0f, ratio, 0.1f, 100.0f);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}
void keyboardFunc( unsigned char key, int x, int y )
{
switch ( key )
{
case 27: // Escape key
exit (0);
break;
case ' ' : // pause/play key
if( angleInc == 0.0f )
{
angleInc = 1.0f;
}
else
{
angleInc = 0.0f;
}
break;
}
glutPostRedisplay();
}
int main(int argc, char **argv)
{
// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(640,480);
glutCreateWindow("Lighthouse3D- GLUT Tutorial");
// register callbacks
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutKeyboardFunc(keyboardFunc);
MakeArrays();
// here is the idle func registration
glutIdleFunc(renderScene);
// enter GLUT event processing cycle
glutMainLoop();
return 0;
}
I plane after to use eigen-values and eigen-vectors for to can handle the spectral compression of a 3D object via his Laplacian matrix
For example, for the very basic example of a triangle :
The Adjency matrix is :
0 1 1
1 0 1
1 1 0
The Degree matrix is :
2 0 0
0 2 0
0 0 2
So, the symetric Laplacian matrix Ls = D - A
2-1 -1
-1 2 -1
-1 -1 2
And the “true” Laplacian matrix is
(this seem the same but divided by 2)
1 -1/2 -1/2
-1/2 1 -1/2
-1/2 -1/2 1
But since I don’t see the rapport between the 3D coordinates of a triangle and his eigen-vector,
it’s again more difficult to imagine what is the rapport between a Laplacian matrix and his eigen-vectors
=> someone can help me a little to understand in more depth how I can represent eigen-values and eigen-vectors on a OpenGL 3D fashion , please ?