Add conversion from Vector to Matrix

git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@314 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
chappuis.daniel 2010-05-17 21:30:11 +00:00
parent 9677d4fbae
commit eddd501bae
3 changed files with 16 additions and 1 deletions

View File

@ -101,6 +101,19 @@ Matrix::Matrix(const Matrix3x3& matrix)
}
}
// Conversion from Vector to Matrix
Matrix::Matrix(const Vector& vector) {
// Create the two dimensional dynamic array
array = new double*[vector.getNbComponent()];
assert(array != 0);
for(int i=0; i<nbRow; ++i) {
array[i] = new double[1];
array[i][0] = vector.getValue(i);
}
}
// Destructor of the class Matrix
Matrix::~Matrix() {
// Destruction of the dynamic array

View File

@ -23,6 +23,7 @@
// Libraries
#include "exceptions.h"
#include "Matrix3x3.h"
#include "Vector.h"
#include <stdexcept>
#include <iostream>
@ -47,6 +48,7 @@ class Matrix {
Matrix(int nbRow, int nbColum) throw(std::invalid_argument); // Constructor of the class Matrix
Matrix(const Matrix& matrix); // Copy constructor of the class Matrix
Matrix(const Matrix3x3& matrix); // Conversion from Matrix3x3
Matrix(const Vector& vector); // Conversion from Vector to Matrix
virtual ~Matrix(); // Destructor of the class Matrix
double getValue(int i, int j) const throw(std::invalid_argument); // Return a value in the matrix
void setValue(int i, int j, double value) throw(std::invalid_argument); // Set a value in the matrix

View File

@ -45,7 +45,7 @@ class Vector {
public :
Vector(); // Constructor without argument
Vector(int n) throw(std::invalid_argument); // Constructor of the class Vector
Vector(const Vector& vector); // Copy-constructor of the class Vector
Vector(const Vector& vector); // Copy-constructor of the class Vector
virtual ~Vector(); // Destructor of the class Vector
double getValue(int n) const throw(std::invalid_argument); // Get a component of the vector
void setValue(int n, double value) throw(std::invalid_argument); // Set the value of a component of the vector