Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from pandas import *
- u = np.array((-0.17, -0.85, 0.5)) # UP Vector.
- v = np.array((-0.27, -0.53, -0.80)) # View Direction.
- e = np.array((1, 2, 3)) # Eye Position.
- c = np.array((None, None, None)) # Center (Aiming Point)
- Point = np.array((1, 1, 1, 1)) # Point to compute on the new space. (Last value is always 1)
- d = 0.5
- if not v.all(): F = e - c
- else: F = -v
- F = np.array(list(map(lambda n: round(n, 5), F / np.linalg.norm(F))))
- print(f'F Vector: {F} | Module: {round(np.linalg.norm(F), 2)}')
- S = np.array(list(map(lambda n: round(n, 5), np.cross(u, F) / np.linalg.norm(np.cross(u, F)))))
- print(f'S Vector: {S} | Module: {round(np.linalg.norm(S), 2)}')
- T = np.array(list(map(lambda n: round(n, 5), np.cross(F, S) / np.linalg.norm(np.cross(F, S)))))
- print(f'T Vector: {T} | Module: {round(np.linalg.norm(T), 2)}')
- Ps = -S[0]*e[0] - S[1]*e[1] - S[2]*e[2]
- Pt = -T[0]*e[0] - T[1]*e[1] - T[2]*e[2]
- Pf = -F[0]*e[0] - F[1]*e[1] - F[2]*e[2]
- S = np.concatenate((S, [Ps]))
- T = np.concatenate((T, [Pt]))
- F = np.concatenate((F, [Pf]))
- print(f'P Point: {np.array([Ps, Pt, Pf])}')
- M = np.matrix([S, T, F, [0, 0, 0, 1]])
- print('\n # View Matrix #')
- print(DataFrame(M).to_string(header=False, index=False))
- print('\n # Point in Camera Space #')
- NewPoint = np.matmul(M, Point)
- print(tuple(map(lambda n: round(float(n), 3), NewPoint.T)))
- xProjected, yProjected, zProjected = float(NewPoint.T[0]*(d/NewPoint.T[2])), float(NewPoint.T[1]*(d/NewPoint.T[2])), d
- projectedPoint = tuple(map(lambda n: round(n, 3), [xProjected, yProjected, zProjected, 1]))
- print(f'\n # Projected Point in {d} #')
- print(projectedPoint)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement