Exemplo n.º 1
0
Matrix Matrix::operator*(Matrix oper)
{
	float *B = oper.GetMatrix();
	int RB = oper.GetRows();
	int CB = oper.GetColumns();
	Matrix C(oper.GetColumns(), GetColumns());
	int CSize = C.GetColumns()*C.GetRows();
	int Columns = C.GetColumns();
	float *Result = C.GetMatrix();

	Result[0] = A[0]*B[0] + A[1]*B[3] + A[2]*B[6]; 
	Result[1] = A[0]*B[1] + A[1]*B[4] + A[2]*B[7]; 
	Result[2] = A[0]*B[2] + A[1]*B[5] + A[2]*B[8]; 

	Result[3] = A[3]*B[0] + A[4]*B[3] + A[5]*B[6]; 
	Result[4] = A[3]*B[1] + A[4]*B[4] + A[5]*B[7]; 
	Result[5] = A[3]*B[2] + A[4]*B[5] + A[5]*B[8]; 

	Result[6] = A[6]*B[0] + A[7]*B[3] + A[8]*B[6]; 
	Result[7] = A[6]*B[1] + A[7]*B[4] + A[8]*B[7]; 
	Result[8] = A[6]*B[2] + A[7]*B[5] + A[8]*B[8]; 
	

	return C;
}
Exemplo n.º 2
0
void PrintMatrix(Matrix input, int MAX_X, int MAX_Y)
{
	std::ofstream myfile;
	myfile.open("example.txt");
	myfile << "P1\n";
	myfile << MAX_X << " " << MAX_Y << "\n";
	int test = input.GetColumns();
	int position = 0;
	bool noMorePoints = false;
	for (int i = 0; i < MAX_Y; i++)
	{
		for (int j = 0; j < MAX_X; j++)
		{
			if (!noMorePoints)
			{
				int XPosition = input.GetVal(0, position);
				int YPosition = input.GetVal(1, position);
				if (XPosition == i && YPosition == j)
				{
					myfile << "1 ";
					position++;
				}
				else
				{
					myfile << "0 ";
				}
				if (position >= input.GetColumns())
				{
					noMorePoints = true;
				}
			}
			else
			{
				myfile << "0 ";
			}
		}
		myfile << "\n";
	}
	myfile.close();

}
Exemplo n.º 3
0
Matrix<char, float> Matrix<char, float>::operator*(const Matrix<char, float> & p_matrix) const
{
	Matrix<char, float> matrix;

	std::vector<char> rows = GetRows(), columns = GetColumns();

	std::vector<char> _rows = p_matrix.GetRows(), _columns = p_matrix.GetColumns();

	for(int i = 0; i < rows.size(); ++i)
	{
		for(int j = 0; j < _columns.size(); ++j)
		{
			matrix.m_values[Coord(rows[i], _columns[j])] = 0;

			for(int k = 0; k < columns.size(); ++k)
			{
				matrix.m_values[Coord(rows[i], _columns[j])] += GetValue(rows[i], columns[k])*p_matrix.GetValue(_rows[k], _columns[j]);
			}

		}
	}

	return matrix;
}