EXTREMEXPLOIT

Camera Coordinate System

Jan 26th, 2021
848
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from pandas import *
  4.  
  5. u = np.array((-0.17, -0.85, 0.5)) # UP Vector.
  6. v = np.array((-0.27, -0.53, -0.80)) # View Direction.
  7. e = np.array((1, 2, 3)) # Eye Position.
  8. c = np.array((None, None, None)) # Center (Aiming Point)
  9. Point = np.array((1, 1, 1, 1)) # Point to compute on the new space. (Last value is always 1)
  10. d = 0.5
  11.  
  12. if not v.all(): F = e - c
  13. else: F = -v
  14.  
  15. F = np.array(list(map(lambda n: round(n, 5), F / np.linalg.norm(F))))
  16. print(f'F Vector: {F} | Module: {round(np.linalg.norm(F), 2)}')
  17.  
  18. S = np.array(list(map(lambda n: round(n, 5), np.cross(u, F) / np.linalg.norm(np.cross(u, F)))))
  19. print(f'S Vector: {S} | Module: {round(np.linalg.norm(S), 2)}')
  20.  
  21. T = np.array(list(map(lambda n: round(n, 5),  np.cross(F, S) / np.linalg.norm(np.cross(F, S)))))
  22. print(f'T Vector: {T} | Module: {round(np.linalg.norm(T), 2)}')
  23.  
  24. Ps = -S[0]*e[0] - S[1]*e[1] - S[2]*e[2]
  25. Pt = -T[0]*e[0] - T[1]*e[1] - T[2]*e[2]
  26. Pf = -F[0]*e[0] - F[1]*e[1] - F[2]*e[2]
  27. S = np.concatenate((S, [Ps]))
  28. T = np.concatenate((T, [Pt]))
  29. F = np.concatenate((F, [Pf]))
  30. print(f'P Point: {np.array([Ps, Pt, Pf])}')
  31. M = np.matrix([S, T, F, [0, 0, 0, 1]])
  32. print('\n # View Matrix #')
  33. print(DataFrame(M).to_string(header=False, index=False))
  34. print('\n # Point in Camera Space #')
  35. NewPoint = np.matmul(M, Point)
  36. print(tuple(map(lambda n: round(float(n), 3), NewPoint.T)))
  37.  
  38. xProjected, yProjected, zProjected = float(NewPoint.T[0]*(d/NewPoint.T[2])), float(NewPoint.T[1]*(d/NewPoint.T[2])), d
  39. projectedPoint = tuple(map(lambda n: round(n, 3), [xProjected, yProjected, zProjected, 1]))
  40. print(f'\n # Projected Point in {d} #')
  41. print(projectedPoint)
  42.  
RAW Paste Data