AlloSphere-Research-Group / AlloSystem

AlloSystem is a cross-platform suite of C++ components for building interactive multimedia tools and applications.
http://mat.ucsb.edu/allosphere/software.php
BSD 3-Clause "New" or "Revised" License
65 stars 22 forks source link

Determinant not being divided correctly #64

Closed nathanw15 closed 8 years ago

nathanw15 commented 8 years ago

Here:

https://github.com/AlloSphere-Research-Group/AlloSystem/blob/devel/allocore/allocore/math/al_Mat.hpp#L586

Example:

#include "allocore/al_Allocore.hpp"

using namespace al;

template <class T>
bool invert2(Mat<2,T>& m){
    T det = determinant(m);
    if(det != 0){
        m.set(m(1,1)/det,-m(0,1)/det,
             -m(1,0)/det, m(0,0)/det);
        return true;
    }
    return false;
}

int main (int argc, char * argv[]){
     Mat<2,double> mat(4.0,7.0,2.0,6.0),matInv,matIdent;
     matInv = mat;

     //al_Mat.hpp
     invert(matInv);

     //inver2 defined above
     //invert2(matInv);

     //Multiply to produce identity matrix
     matIdent = mat*matInv;
     printf("%f %f\n%f %f\n\n",matIdent[0],matIdent[2],matIdent[1],matIdent[3]);

    return 0;
}
LancePutnam commented 8 years ago

Fixed in 48400e8d2953cb99719cbb6ad1b7cc1b907b27e3. The problem was because the set function takes references, so self-assignment doesn't work.