fork download
  1. #include <cmath>
  2. #include <iostream>
  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. bool isUnitVectorOnPlane(const UnitVector& vector, const Plane& plane) {
  17. // Calculate the dot product of the unit vector and the plane's normal vector
  18. double dotProduct = vector.x * plane.normal.x + vector.y * plane.normal.y + vector.z * plane.normal.z;
  19.  
  20. // Check if the dot product is close to zero (considering floating-point precision)
  21. const double epsilon = 1e-6;
  22. return std::abs(dotProduct) < epsilon;
  23. }
  24.  
  25. int main() {
  26. UnitVector vec = {0.0, 1.0, 0.0};
  27. Plane plane = {{500.0, 500.0, 500.0}, {1.0, 0.0, 0.0}};
  28.  
  29. if (isUnitVectorOnPlane(vec, plane)) {
  30. std::cout << "The vector lies in the plane." << std::endl;
  31. } else {
  32. std::cout << "The vector does not lie in the plane." << std::endl;
  33. }
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
The vector lies in the plane.