gtsam::Point3
是 GTSAM 库中的一个类,用于表示三维空间中的点或向量。它主要用于几何计算和优化问题中的三维位置和方向。以下是 gtsam::Point3
类的详细介绍:
gtsam::Point3
类概述
Point3
类表示一个三维点或向量,通常用于描述空间中的位置或方向。它提供了多种操作和计算功能,便于进行几何变换和优化。
主要功能
-
三维点表示:
- 包含三个坐标分量(x, y, z)。
- 可以表示空间中的任何位置或向量。
-
向量运算:
- 支持基本的向量运算,如加法、减法和标量乘法。
- 支持点与点之间的距离计算。
-
变换操作:
- 可以应用旋转和位移变换,计算点在变换后的坐标。
主要成员函数
-
构造函数
Point3(); // 默认构造函数,创建 (0, 0, 0) 的点
Point3(double x, double y, double z); // 使用给定的坐标创建点
- 获取坐标
double x() const; // 获取 x 坐标
double y() const; // 获取 y 坐标
double z() const; // 获取 z 坐标
- 运算
Point3 operator+(const Point3& other) const; // 向量加法
Point3 operator-(const Point3& other) const; // 向量减法
Point3 operator*(double scalar) const; // 向量与标量乘法
double dot(const Point3& other) const; // 点积
Point3 cross(const Point3& other) const; // 叉积
- 变换
Point3 transform(const gtsam::Pose3& pose) const; // 将点应用到 Pose3 变换
- 输出
std::ostream& operator<<(std::ostream& os, const Point3& point); // 输出点的坐标
示例代码
#include <gtsam/geometry/Point3.h>
#include <iostream>
int main() {
gtsam::Point3 p1(1.0, 2.0, 3.0);
gtsam::Point3 p2(4.0, 5.0, 6.0);
gtsam::Point3 sum = p1 + p2; // 向量加法
double dotProduct = p1.dot(p2); // 点积
std::cout << "Sum: " << sum << std::endl;
std::cout << "Dot Product: " << dotProduct << std::endl;
return 0;
}
这段代码展示了如何使用 Point3
类进行向量加法和点积操作,并输出结果。