fork download
  1. #include <iostream>
  2.  
  3. struct Position {
  4. double x, y, z;
  5. };
  6.  
  7. struct UnitVector {
  8. double x, y, z;
  9. };
  10.  
  11. struct Plane {
  12. Position pos; // arbitrary point that lies on the plane
  13. UnitVector normal; // normal vector to the plane
  14. };
  15.  
  16. // Helper function to calculate the dot product of two vectors
  17. double calculate_dot_product(const UnitVector& vec1, const UnitVector& vec2) {
  18. return vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z;
  19. }
  20.  
  21. // Helper function to check if two vectors are perpendicular
  22. bool is_perpendicular(const UnitVector& vec1, const UnitVector& vec2) {
  23. return calculate_dot_product(vec1, vec2) == 0;
  24. }
  25.  
  26. bool isVectorInPlane(const UnitVector& vec, const Plane& plane) {
  27. // Create a vector from the plane's point to the given vector
  28. UnitVector pointToVec = {vec.x - plane.pos.x, vec.y - plane.pos.y, vec.z - plane.pos.z};
  29.  
  30. // Check if the vector from the plane's point to the given vector is perpendicular to the plane's normal vector
  31. return is_perpendicular(pointToVec, plane.normal);
  32. }
  33.  
  34. int main() {
  35. UnitVector vec = {0.0, 1.0, 0.0};
  36. Plane plane = {{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}};
  37.  
  38. if (isVectorInPlane(vec, plane)) {
  39. std::cout << "The vector lies in the plane." << std::endl;
  40. } else {
  41. std::cout << "The vector does not lie in the plane." << std::endl;
  42. }
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
The vector lies in the plane.