Matrix Class
- 定义矩阵:使用
Matrix<typename scalar, int RowsAtCompileTime, int ColsAtCompileTime>
来定义矩阵。实际使用时,如果矩阵是4x4或更小的,则可以直接使用特定的方阵,如Matrix4f (typedef Matrix<float,4,4> Matrix4f
),否则使用MatrixXd。 - 向量: Eigen中向量也是矩阵,包括行向量Vector (
typedef Matrix<float,3,1>' Vector3f)和列向量RowVector ('typedef Matrix<float,1,3> RowVector3f
)。 - Dynamic Size: 即动态尺寸,如
typedef Matrix<double, Dynamic, Dynamic> MatrixXd
,同样有VectorXd
。 - 构造函数:
i. 默认构造函数:MatrixXd a;
,这样的尺寸是0x0。
ii. 带尺寸的(只适用于动态尺寸):MatrixXd a(30, 15);
iii. 用数值初始化(只适用于定长的向量):Vector3d(4.0, 5.0, 6.0);
- 索引: 矩阵用
m(0,1)
, 向量用v(1)
或v[1