You seem to be confusing two terms: A matrix M is idempotent if ; it's orthogonal if , which is what you are testing for in your code.
There is an orthogonal basis of eigenvectors for a matrix A if it's symmetric. In your code you're constructing a symmetric matrix, a2, but the matrix a which you're passing to eig is not symmetric.
If A is symmetric, and has two eigenpairs , , with c not equal to c, then x and y must be orthogonal:
Since c and d are not equal, this implies that must be equal to zero, meaning that x and y are orthogonal.
Best Answer