测试矩阵相乘
#include <QtWidgets/QApplication> #include <QtWidgets/QGraphicsScene> #include <QtWidgets/QGraphicsView> #include <QtCore/QPointF> #include <QtCore/QDebug> // 定义矩阵类 class Matrix { public: Matrix(float m00, float m01, float m02, float m10, float m11, float m12) : m00(m00), m01(m01), m02(m02), m10(m10), m11(m11), m12(m12) {} float operator()(float x, float y) const { return m00 + m01 * x + m02 * y; } private: float m00, m01, m02; float m10, m11, m12; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); // 创建场景和视图 QGraphicsScene scene(400, 400); QGraphicsView view(&scene); // 定义矩阵A和矩阵B Matrix matrixA(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f); Matrix matrixB(7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f); // 计算矩阵C = matrixA * matrixB Matrix matrixC(matrixA(0, 0), matrixA(0, 1), matrixA(0, 2), matrixA(1, 0), matrixA(1, 1), matrixA(1, 2), matrixA(2, 0), matrixA(2, 1), matrixA(2, 2)); // 绘制矩阵C view.scene().addTransformedShape(&matrixC); // 显示场景 view.show(); return a.exec(); }
##########################
QQ 3087438119