Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <algorithm>
  7.  
  8. #define EPS 1e-13
  9.  
  10. using std::pair;
  11. using std::numeric_limits;
  12. using std::make_pair;
  13.  
  14. typedef struct pt{
  15. long double x, y, z;
  16. pt(long double tx = 0., long double ty = 0., long double tz = 0.) {
  17. x = tx;
  18. y = ty;
  19. z = tz;
  20. }
  21. } myvector;
  22. myvector operator *(myvector a, long double m){
  23. return pt(a.x * m, a.y * m, a.z * m);
  24. }
  25. myvector operator /(myvector a, long double m){
  26. return pt(a.x / m, a.y / m, a.z / m);
  27. }
  28. myvector operator +(myvector a, myvector b){
  29. return pt(a.x + b.x, a.y + b.y, a.z + b.z);
  30. }
  31. myvector operator -(myvector a, myvector b){
  32. return pt(a.x - b.x, a.y - b.y, a.z - b.z);
  33. }
  34. myvector operator %(myvector a, myvector b){
  35. return pt(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
  36. }
  37. bool operator ==(myvector a, myvector b){
  38. return ((fabs(b.x - a.x) < EPS) && (fabs(b.y - a.y) < EPS) && (fabs(b.z - a.z) < EPS));
  39. }
  40. long double vsqllen(myvector v){
  41. return v.x * v.x + v.y * v.y + v.z * v.z;
  42. }
  43. long double vlen(myvector v){
  44. return sqrt(vsqllen(v));
  45. }
  46. myvector norm(myvector v){
  47. long double l = vlen(v);
  48. return v / l;
  49. }
  50.  
  51. typedef struct pl {
  52. long double a, b, c, d;
  53. myvector normal;
  54. pl(myvector ta = pt(0., 0., 0.), myvector tb = pt(0., 0., 0.), myvector tc = pt(0., 0., 0.)) {
  55. a = -tb.y * ta.z + tc.y * ta.z + ta.y * tb.z - tc.y * tb.z - ta.y * tc.z + tb.y * tc.z;
  56. b = tb.x * ta.z - tc.x * ta.z - ta.x * tb.z + tc.x * tb.z + ta.x * tc.z - tb.x * tc.z;
  57. c = -tb.x * ta.y + tc.x * ta.y + ta.x * tb.y - tc.x * tb.y - ta.x * tc.y + tb.x * tc.y;
  58. d = tc.x * tb.y * ta.z - tb.x * tc.y * ta.z - tc.x * ta.y * tb.z + ta.x * tc.y * tb.z + tb.x * ta.y * tc.z - ta.x * tb.y * tc.z;
  59. normal = pt(a, b, c);
  60. }
  61. } myplane;
  62.  
  63.  
  64. typedef struct ln {
  65. myvector a, b;
  66. ln(myvector ta = pt(0., 0., 0.), myvector tb = pt(0., 0., 0.)) {
  67. a = ta;
  68. b = tb;
  69. }
  70. } myline;
  71.  
  72.  
  73. typedef struct cr {
  74. myvector center;
  75. long double radius;
  76.  
  77. cr(myvector a = pt(0., 0., 0.), myvector b = pt(0., 0., 0.), myvector c = pt(0., 0., 0.)) {
  78. myvector ta = a - c;
  79. myvector tb = b - c;
  80. radius = (vlen(ta) * vlen(tb) * vlen(ta - tb)) / (2. * vlen(ta % tb));
  81. center = ((((tb * vsqllen(ta)) - (ta * vsqllen(tb))) % (ta % tb)) / (2. * vsqllen(ta % tb))) + c;
  82. }
  83. } circle;
  84.  
  85. myline intersection(myplane a, myplane b) {
  86. myline res = ln(pt(0., 0., 0.), pt(0., 0., 0.));
  87. res.b = a.normal % b.normal;
  88. res.a = ((a.normal * b.d - b.normal * a.d) % res.b) / pow(vlen(res.b), 2);
  89. return res;
  90. }
  91. pair<myvector, myvector> intersection(const myline l, const circle c) {
  92. long double Mnan = numeric_limits<long double>::quiet_NaN();
  93. long double A = vsqllen(l.b);
  94. long double B = -2. * (l.b.x * (c.center.x + l.a.x) - l.b.y * (c.center.y + l.a.y) - l.b.z * (c.center.z + l.a.z));
  95. long double C = vsqllen(myvector(c.center) - myvector(l.a)) - pow(c.radius, 2);
  96. long double D = B * B - 4 * A * C;
  97. if (D < EPS) return make_pair(pt(Mnan, Mnan, Mnan), pt(Mnan, Mnan, Mnan));
  98. if (fabs(A) < EPS) {
  99. if (fabs(B) < EPS) {
  100. if (fabs(C) < EPS) return make_pair(l.a, l.a);
  101. return make_pair(pt(Mnan, Mnan, Mnan), pt(Mnan, Mnan, Mnan));
  102. }
  103. return make_pair(pt(l.a) + pt(l.b) * (-C / B), pt(l.a) + pt(l.b) * (-C / B));
  104. }
  105. return make_pair(myvector(l.a) + myvector(l.b) * ((-B + sqrt(D)) / (2. * A)),
  106. pt(l.a) + myvector(l.b) * ((-B - sqrt(D)) / (2. * A)));
  107. }
  108.  
  109. bool paralel_plane(myplane p1, myplane p2, circle cr1, circle cr2) {
  110. if ((fabs(p1.a - p2.a) < EPS) && fabs(p1.b - p2.b) < EPS && fabs(p1.c - p2.c) < EPS){
  111. if (fabs(p1.d - p2.d) < EPS){
  112. printf("%d\n", vlen(cr2.center - cr1.center) - cr1.radius - cr2.radius < EPS ? 1 : 0);
  113. }
  114. else{
  115. printf("%d\n", 0);
  116. }
  117. return true;
  118. }
  119. return false;
  120. }
  121.  
  122. bool inpect(myvector a, myplane p, circle c) {
  123. if ((fabs(p.a * a.x + p.b * a.y + p.c * a.z + p.d) < EPS) && (vlen(a - c.center) - c.radius < EPS)) {
  124. printf("%d\n", 1);
  125. return true;
  126. }
  127. return false;
  128. }
  129. int main() {
  130. freopen("input.txt", "r", stdin);
  131. freopen("output.txt", "w", stdout);
  132. long double x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6;
  133. scanf("%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf", &x1, &y1, &z1, &x2, &y2, &z2, &x3, &y3, &z3, &x4, &y4, &z4, &x5, &y5, &z5, &x6, &y6, &z6);
  134. myvector a1(x1, y1, z1);
  135. myvector b1(x2, y2, z2);
  136. myvector c1(x3, y3, z3);
  137. myvector a2(x4, y4, z4);
  138. myvector b2(x5, y5, z5);
  139. myvector c2(x6, y6, z6);
  140. myplane p1 = pl(b1, a1, c1);
  141. myplane p2 = pl(a2, b2, c2);
  142. circle cr1(a1, b1, c1);
  143. circle cr2(a2, b2, c2);
  144. if (paralel_plane(p1, p2, cr1, cr2))
  145. return 0;
  146. myline inter = intersection(p1, p2);
  147. pair<myvector, myvector> ip1 = intersection(inter, cr1), ip2 = intersection(inter, cr2);
  148. if (inpect(ip1.first, p2, cr2) || inpect(ip1.second, p2, cr2) ||
  149. inpect(ip2.first, p1, cr1) || inpect(ip2.second, p1, cr1)) return 0;
  150. printf("%d\n", 0);
  151. fclose(stdin);
  152. fclose(stdout);
  153. return(0);
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement