Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eigenvalues and eigenvectors #321

Open
droundy opened this issue Aug 13, 2022 · 3 comments · May be fixed by #589
Open

eigenvalues and eigenvectors #321

droundy opened this issue Aug 13, 2022 · 3 comments · May be fixed by #589

Comments

@droundy
Copy link

droundy commented Aug 13, 2022

It would be nice to have methods to compute the eigenvalues and eigenvectors of matrices.

@bitshifter
Copy link
Owner

Out of curiosity, what do you want to use them for? I have not seen eigenvalues and eigenvectors used in the context of game dev that I can recall. I don't mean to question adding them, I just like to understand the use case of features before adding them.

@droundy
Copy link
Author

droundy commented Aug 18, 2022

I'm doing an animation drawing program not a game, and I'm computing the moment of inertia tensor to get a first guess as to the relative orientation of two frames. See https://github.com/droundy/sketch/blob/main/src/tween.rs#L205

@EmiOnGit
Copy link

Is this still relevant? I've implemented the methods myself in the past for this crate whenever I needed them and would be open to give it a try.

However, I feel like implementing methods for calculating the Eigenpair might be not as simple as it might seem.

Talking points

  1. Eigenvalues can be complex.

Currently, glam doesn't have a implementation for complex numbers (which it shouldn't IMO).
A possible solution would be to only return the real Eigenvalues and ignore the complex ones.

  1. Efficient implementations are not as simple simple.

The Eigenpair implementation for 2x2 shouldn't be a big problem, 3x3 on the other hand might get ugly.
Most people might know the method of finding and solving the characteristic polynomial (analytic approach). This sadly has proven to be numerical unstable in some cases. For a 3x3 matrix QR (or QL) decomposition or using householder reflections seem to be the goto standard.

  1. How long do we iterate?

QR (and I think househoulder too) is implemented iterative. It is possible to find a upper bound for the error but we might want to agree on a error we allow for optimization reasons.

  1. What do we do in case of a wrong input.

How do we respond to a 0 or close-to-0 matrix? Sure we could panic but this would be unpractical, considering that the user would need to make sure that the matrix is allowed.

  1. Real and complex (1 and 3)

We might end up with 'slightly complex' eigenvalues through numerical errors. Would we map them to a real number with the risk of returning eigenvalues that shouldn't be returned or do we make sure to only return real eigenvalues with the risk of loosing some through numerical errors.

@squaaawk squaaawk linked a pull request Nov 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants