fork download
  1. #include <stdio.h>
  2.  
  3. // Define a structure to hold 3D points
  4. typedef struct {
  5. float x;
  6. float y;
  7. float z;
  8. } Point3D;
  9.  
  10. // Function to reflect a point in the XY plane (flip z-axis)
  11. Point3D reflectXY(Point3D p) {
  12. p.z = -p.z;
  13. return p;
  14. }
  15.  
  16. // Function to reflect a point in the YZ plane (flip x-axis)
  17. Point3D reflectYZ(Point3D p) {
  18. p.x = -p.x;
  19. return p;
  20. }
  21.  
  22. // Function to reflect a point in the ZX plane (flip y-axis)
  23. Point3D reflectZX(Point3D p) {
  24. p.y = -p.y;
  25. return p;
  26. }
  27.  
  28. int main() {
  29. // Define a 3D point
  30. Point3D point = {3.0f, 4.0f, 5.0f};
  31.  
  32. // Print the original point
  33. printf("Original point: (%.2f, %.2f, %.2f)\n", point.x, point.y, point.z);
  34.  
  35. // Reflect the point in the XY plane
  36. Point3D reflectedXY = reflectXY(point);
  37. printf("Reflection in XY plane: (%.2f, %.2f, %.2f)\n", reflectedXY.x, reflectedXY.y, reflectedXY.z);
  38.  
  39. // Reflect the point in the YZ plane
  40. Point3D reflectedYZ = reflectYZ(point);
  41. printf("Reflection in YZ plane: (%.2f, %.2f, %.2f)\n", reflectedYZ.x, reflectedYZ.y, reflectedYZ.z);
  42.  
  43. // Reflect the point in the ZX plane
  44. Point3D reflectedZX = reflectZX(point);
  45. printf("Reflection in ZX plane: (%.2f, %.2f, %.2f)\n", reflectedZX.x, reflectedZX.y, reflectedZX.z);
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 5284KB
stdin
9.00
stdout
Original point: (3.00, 4.00, 5.00)
Reflection in XY plane: (3.00, 4.00, -5.00)
Reflection in YZ plane: (-3.00, 4.00, 5.00)
Reflection in ZX plane: (3.00, -4.00, 5.00)