Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct vertex{
  6. int x,y,z;
  7. };
  8.  
  9. struct vector{
  10. int px,py,pz;
  11. };
  12.  
  13. vertex X;
  14.  
  15. void plane(vertex a, vertex b, vertex c, vertex d);
  16.  
  17. vector cross_prod(vector a, vector b);
  18.  
  19. int main(){
  20. int t; cin>>t;
  21. while(t--){
  22. vertex A,B,C,D;
  23. cin>>A.x>>A.y>>A.z;
  24. cin>>B.x>>B.y>>B.z;
  25. cin>>C.x>>C.y>>C.z;
  26. cin>>D.x>>D.y>>D.z;
  27. cin>>X.x>>X.y>>X.z;
  28. plane(B,C,D,A);
  29. plane(A,C,D,B);
  30. plane(A,B,D,C);
  31. plane(A,B,C,D);
  32. cout<<endl;
  33. }
  34. return 0;
  35. }
  36.  
  37. vector cross_prod(vector a, vector b){
  38. vector res;
  39. res.px = a.py*b.pz - a.pz*b.py;
  40. res.py = (a.px*b.pz - a.pz*b.px)*(-1);
  41. res.pz = a.px*b.py - a.py*b.px;
  42.  
  43. return res;
  44. }
  45.  
  46. void plane(vertex a, vertex b, vertex c, vertex d){
  47.  
  48. vector ab = {b.x-a.x, b.y-a.y, b.z-a.z};
  49. vector ac = {c.x-a.x, c.y-a.y, c.z-a.z};
  50.  
  51. vector cross = cross_prod(ab,ac);
  52.  
  53. //ax + by + cz + d = 0;
  54. double pd = 0 - cross.px*a.x - cross.py*a.y - cross.pz*a.z;
  55. // cout<<d<<endl;
  56.  
  57. int res1 = cross.px * d.x + cross.py * d.y + cross.pz * d.z + pd;
  58. int res2 = cross.px * X.x + cross.py * X.y + cross.pz * X.z + pd;
  59.  
  60. if((res1 > 0 && res2 < 0) || (res1 < 0 && res2 > 0)) cout<<"Y";
  61. else cout<<"N";
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement