Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which linear algebra to use for OpenGL in Haskell?

I am trying to do some OpenGL programming in haskell. But i am confused by the current state of the libraries. OpenGL uses the Tensor package which only defines several vector types (but doesn't do so in a generic way). It doesn't seem to provide any Matrix implementations.

There are several other packages for linear algebra: tensor (note the lowercase T), Vec, hmatrix which seem to be more complete than Tensor.

What i am searching for should at least contain common functions used in 3d and 2d graphics, have reasonable performance and should be compatible with OpenGL but i guess i'll have to change the library for that.

like image 727
fho Avatar asked Aug 12 '12 19:08

fho


2 Answers

Late answer, sorry. HMatrix is the standard choice for things like this. It's very compatible, has a nice API, and is actually used for computer vision among other applications: http://dis.um.es/profesores/alberto/research.html

like image 61
sclv Avatar answered Nov 01 '22 07:11

sclv


I was wondering the same recently, and was especially annoyed that Tensor doesn't provide you with convenient functions for dot product, cross product, normalization etc.

As you pointed out, vect is "hardcoded" for Float and Double, and therfore cannot have useful typeclass instances like Functor, Monoid or Applicative - with those we would get a lot of operations "for free", e.g. addition: (+) <$> v1 <*> v2.

On #haskell, I was pointed to the linear package. It is well-maintained and comes with a bunch of useful instances and functions.

like image 21
nh2 Avatar answered Nov 01 '22 08:11

nh2