go-gl / mathgl

A pure Go 3D math library.
BSD 3-Clause "New" or "Revised" License
554 stars 65 forks source link

Matrix multiplication MulNx1 is incorrect #48

Closed shogg closed 9 years ago

shogg commented 9 years ago

A matrix mat Mat3x6 with 3 rows and 6 columns multiplicated with a vector v Vec6 should yield a Vec3. But MulNx1 currently expects mat to have 6 rows and tries to produce a Vec6: panic: index out of range.

correction in matmn.go line 416:

//  dst = dst.Resize(len(v.vec))
    dst = dst.Resize(mat.m)

//  for r := range v.vec {
    for r := 0; r < mat.m; r++ {

Also: func VecN.Set is missing. There is MatMxN.At, MatMxN.Set, VecN.Get but no VecN.Set.

UserAB1236872 commented 9 years ago

Can you submit a PR?

Also, it's plausible we should get rid of MatMN/VecN. If people want to do arbitrary-dimensional matrix math, they should probably use Gonum/matrix. The big hurdle here is that we're CMO and it's RMO, and it's potentially expensive to do a bunch of transposes just to feed data to another library. Honestly, that issue was the only reason I wrote the code in the first place.

I don't feel it's ever going to be at the point where it should be if you really want arbitrary dimensions in computer graphics (e.g. there's no way we're implementing pseudo-inverses, which are what someone probably wants for inverse kinematics).

ghost commented 9 years ago

My bad, not there isnt for VecN