import numpy as np unit = lambda v: v/np.linalg.norm(v) def problem_1(): p = np.array([1, 4, 8]) e = np.array([0, 0, 0]) s = np.array([2, 2, 10]) i = p - e print("incoming", i) print("|I| =", np.linalg.norm(i)) n = s - p print("normal", n) n_norm = unit(n) print("normal_norm", n_norm) cos_theta_i = np.dot(-i, n) / (np.linalg.norm(i) * np.linalg.norm(n)) print("part a = cos^{-1} of ", cos_theta_i) print(np.arccos(cos_theta_i)) proj = n_norm * np.linalg.norm(i) * cos_theta_i print("proj", proj) p_ = p + proj print("proj point", p_) v2 = p_ - e print("v2", v2) sin_theta_i = np.sin(np.arccos(cos_theta_i)) print("sin theta_i =", sin_theta_i) print("approx answer for part d", np.arcsin(1.0 / 1.5 * sin_theta_i)) def problem_8(): def P(left, right, bottom, top, near, far): return np.array([ [2.0 * near / (right - left), 0, (right + left) / (right - left), 0], [0, 2.0 * near / (top - bottom), (top + bottom) / (top - bottom), 0], [0, 0, -(far + near) / (far - near), -(2.0 * far * near) / (far - near)], [0, 0, -1, 0], ]) near, far = left, right = bottom, top = -1, 1 print("part 8a", P(left, right, bottom, top, near, far)) print() problem_8() problem_1()