Paste Search Dynamic
dotproduct
  1. import math
  2. from math import pi, sin, cos
  3.  
  4. def dotproduct(v1, v2):
  5.   return sum((a*b) for a, b in zip(v1, v2))
  6.  
  7. def length(v):
  8.   return math.sqrt(dotproduct(v, v))
  9.  
  10. def angle(v1, v2):
  11.   return math.acos(dotproduct(v1, v2) / (length(v1) * length(v2)))
  12.  
  13. def R(theta, u):
  14.     return [[cos(theta) + u[0]**2 * (1-cos(theta)),
  15.              u[0] * u[1] * (1-cos(theta)) - u[2] * sin(theta),
  16.              u[0] * u[2] * (1 - cos(theta)) + u[1] * sin(theta)],
  17.             [u[0] * u[1] * (1-cos(theta)) + u[2] * sin(theta),
  18.              cos(theta) + u[1]**2 * (1-cos(theta)),
  19.              u[1] * u[2] * (1 - cos(theta)) - u[0] * sin(theta)],
  20.             [u[0] * u[2] * (1-cos(theta)) - u[1] * sin(theta),
  21.              u[1] * u[2] * (1-cos(theta)) + u[0] * sin(theta),
  22.              cos(theta) + u[2]**2 * (1-cos(theta))]]
  23.  
  24. def Rotate(point, axis, theta):
  25.     len = length(axis)
  26.     axis = [i/len for i in axis]
  27.     r = R(theta, axis)
  28.     rotated = []
  29.  
  30.     for i in range(3):
  31.         rotated.append((sum([r[j][i] * point[j] for j in range(3)])))
  32.  
  33.     return rotated
  34.  
  35.  
  36. Test = (int)(input())
  37. for test in range(Test):
  38.     (xA, yA, xB, yB, xC, yC) = map(float, input().split())
  39.     (sA, sB, sC) = map(int, input().split())
  40.     p0 = [0.0, 0.0, 0.0]
  41.     p1 = [xB, yB, math.sqrt(1.0 - xB**2 - yB**2)]
  42.     p2 = [xC, yC, math.sqrt(1.0 - xC**2 - yC**2)]
  43.     point = [xA, yA, math.sqrt(1.0 - xA**2 - yA**2)]
  44.  
  45.     if (sA == 0):
  46.         point[2] = -point[2]
  47.     if (sB == 0):
  48.         p1[2] = -p1[2]
  49.     if (sC == 0):
  50.         p2[2] = -p2[2]
  51.  
  52.     if (p1 == p2):
  53.         txt = "{x:.7f} {y:.7f} {z:.7f}".format(x = point[0], y=point[1], z=point[2])
  54.         print(txt)
  55.         continue
  56.  
  57.     theta = angle(p1, p2)
  58.     x0, y0, z0 = p0
  59.     x1, y1, z1 = p1
  60.     x2, y2, z2 = p2
  61.  
  62.     ux, uy, uz = u = [x1-x0, y1-y0, z1-z0]
  63.     vx, vy, vz = v = [x2-x0, y2-y0, z2-z0]
  64.  
  65.     axis = [uy*vz-uz*vy, uz*vx-ux*vz, ux*vy-uy*vx]
  66.  
  67.     ans = Rotate(point, axis, -theta)
  68.     txt = "{x:.7f} {y:.7f} {z:.7f}".format(x = ans[0], y=ans[1], z=ans[2])
  69.     print(txt)
  70.  
Parsed in 0.015 seconds