#include#include #include using namespace std; struct Vector3 { double x, y, z; }; Vector3 cross(Vector3 a, Vector3 b) { Vector3 result; result.x = a.y * b.z - a.z * b.y; result.y = a.z * b.x - a.x * b.z; result.z = a.x * b.y - a.y * b.x; return result; } int main() { Vector3 a = {1, 2, 3}; Vector3 b = {4, 5, 6}; Vector3 c = cross(a, b); cout << "(" << c.x << ", " << c.y << ", " << c.z << ")" << endl; return 0; }
#includeThis program will output the normal vector of the plane passing through the three points: (-29, -15, -13). The Vector3 cross function is commonly used in 3D computer graphics and physics simulations. It is part of the glm library, which is a header-only C++ math library for graphics applications.#include #include using namespace std; struct Vector3 { double x, y, z; }; Vector3 cross(Vector3 a, Vector3 b) { Vector3 result; result.x = a.y * b.z - a.z * b.y; result.y = a.z * b.x - a.x * b.z; result.z = a.x * b.y - a.y * b.x; return result; } int main() { Vector3 p1 = {-1, 2, 3}; Vector3 p2 = {4, 5, 6}; Vector3 p3 = {7, 8, -1}; Vector3 a = {p2.x - p1.x, p2.y - p1.y, p2.z - p1.z}; Vector3 b = {p3.x - p1.x, p3.y - p1.y, p3.z - p1.z}; Vector3 n = cross(a, b); cout << "The normal vector of the plane is: (" << n.x << ", " << n.y << ", " << n.z << ")" << endl; return 0; }