#include#include #include // Create a new Vector3d object representing point (1, 2, 3) std::vector point {1.0, 2.0, 3.0}; Vector3d p(point);
#include#include // Calculate the distance between two points using cpp Vector3d double distance(Vector3d p1, Vector3d p2) { std::vector d = p2 - p1; return d.length(); } // Test distance function Vector3d p1(1.0, 2.0, 3.0); Vector3d p2(4.0, 5.0, 6.0); std::cout << distance(p1, p2) << std::endl;
#includeThe cpp Vector3d is commonly used in packages such as Eigen, a C++ template library for linear algebra.#include // Set and get x, y, and z components Vector3d p(1.0, 2.0, 3.0); p.setX(4.0); p.setY(5.0); p.setZ(6.0); std::cout << p.getX() << " " << p.getY() << " " << p.getZ() << std::endl;