예제 #1
0
파일: oimat.cpp 프로젝트: cedmayer/OpenIndy
/*!
 * \brief OiMat::setCol
 * Replace the column at index by the given column
 * \param index
 * \param col
 */
void OiMat::setCol(const int index, const OiVec &col){
    if(this->getColCount() > index){ //if there is a column at index

        if(this->getRowCount() == col.getSize()){ //if the given column has the right number of elements

            for(unsigned int i = 0; i < col.getSize(); i++){
                this->values.at(i).at(index) = col.getAt(i);
            }

        }else{
            throw logic_error("Cannot replace a column of a matrix by a given column with incompatible size");
        }

    }else{
        throw logic_error("Cannot replace a column of a matrix by a given column because of an invalid index");
    }
}
예제 #2
0
파일: oimat.cpp 프로젝트: cedmayer/OpenIndy
/*!
 * \brief OiMat::setRow
 * Replace the row at index by the given row
 * \param index
 * \param row
 */
void OiMat::setRow(const int index, const OiVec &row){
    if(this->getRowCount() > index){ //if there is a row at index

        if(this->getColCount() == row.getSize()){ //if the given row has the right number of elements

            //fill vector with the given values...
            vector<double> rowVec;
            for(unsigned int i = 0; i < row.getSize(); i++){
                rowVec.push_back(row.getAt(i));
            }

            //...and replace the row of the matrix at index
            this->values.at(index) = rowVec;

        }else{
            throw logic_error("Cannot replace a row of a matrix by a given row with incompatible size");
        }

    }else{
        throw logic_error("Cannot replace a row of a matrix by a given row because of an invalid index");
    }
}
예제 #3
0
파일: oimat.cpp 프로젝트: cedmayer/OpenIndy
/*!
 * \brief OiMat::getRotationMatrix
 * Get the rotation matrix corresponding to a rotation around an arbitrary rotation axis by the given amount
 * \param angle
 * \param axis
 * \return
 */
OiMat OiMat::getRotationMatrix(double angle, OiVec axis){
    if(axis.getSize() == 3){
        OiMat result(3, 3);

        axis = axis.normalize();

        double w = qCos(angle / 2.0);
        OiVec x = qSin(angle / 2.0) * axis;

        result.setAt(0, 0, 1.0 - 2.0 * (x.getAt(1)*x.getAt(1) + x.getAt(2)*x.getAt(2)));
        result.setAt(0, 1, 2.0 * (x.getAt(0)*x.getAt(1) - w * x.getAt(2)));
        result.setAt(0, 2, 2.0 * (x.getAt(0)*x.getAt(2) + w * x.getAt(1)));
        result.setAt(1, 0, 2.0 * (x.getAt(0)*x.getAt(1) + w * x.getAt(2)));
        result.setAt(1, 1, 1.0 - 2.0 * (x.getAt(0)*x.getAt(0) + x.getAt(2)*x.getAt(2)));
        result.setAt(1, 2, 2.0 * (x.getAt(1)*x.getAt(2) - w * x.getAt(0)));
        result.setAt(2, 0, 2.0 * (x.getAt(0)*x.getAt(2) - w * x.getAt(1)));
        result.setAt(2, 1, 2.0 * (x.getAt(1)*x.getAt(2) + w * x.getAt(0)));
        result.setAt(2, 2, 1.0 - 2.0 * (x.getAt(0)*x.getAt(0) + x.getAt(1)*x.getAt(1)));

        return result;
    }else{
        throw logic_error("To set up the rotation matrix the given axis has to be of size 3");
        return OiMat();
    }
}
예제 #4
0
/*!
 * \brief LAArmadillo::oiVec2Arma
 * \param result
 * \param v
 */
void LAArmadillo::oiVec2Arma(arma::vec &result, const OiVec &v){
    for(int i = 0; i < v.getSize(); i++){
        result[i] = v.getAt(i);
    }
}