This commit is contained in:
Michael Zhang 2023-04-30 17:10:11 -05:00
parent d1603f4296
commit 66a4e60e0d
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
2 changed files with 100 additions and 17 deletions

View file

@ -69,7 +69,7 @@ author: |
in the $+z$ direction. Derive a sequence of model transformation matrices
that can be applied to the vertices of the airplane to position it in space
at the location $p = (4, 4, 7)$, with a direction of flight $w = (2, 1, -2)$
and the wings aligned with the direction $d = (-2, 2, 1)$.}
and the wings aligned with the direction $d = (-2, 2, -1)$.}
The translation matrix is
@ -92,25 +92,89 @@ author: |
Since the direction of flight was originally $(0, 0, 1)$, we have to
transform it to $(2, 1, -2)$.
8. Consider the perspective projection-normalization matrix P which maps the
contents of the viewing frustum into a cube that extends from -1 to 1 in $x,
y, z$ (called normalized device coordinates).
3.
Suppose you want to define a square, symmetric viewing frustum with a near
clipping plane located 0.5 units in front of the camera, a far clipping plane
located 20 units from the front of the camera, a 60 ̊vertical field of view,
and a 60 ̊horizontal field of view.
## The Camera/Viewing Transformation
a. \c{(2 points) What are the entries in P?}
4. \c{Consider the viewing transformation matrix $V$ that enables all of the
vertices in a scene to be expressed in terms of a coordinate system in which
the eye is located at $(0, 0, 0)$, the viewing direction ($-n$) is aligned
with the $-z$ axis $(0, 0, 1)$, and the camera's 'up' direction (which
controls the roll of the view) is aligned with the $y$ axis (0, 1, 0).}
a. (4 points) When the eye is located at $e = (2, 3, 5)$, the camera is
pointing in the direction $(1, -1, -1)$, and the camera's 'up' direction is
$(0, 1, 0)$, what are the entries in $V$?
$$\begin{bmatrix}
0 & 1 & 0 & d_x \\
\end{bmatrix}$$
b. (3 points) How should be matrix P be re-defined if the viewing window is
re-sized to be twice as tall as it is wide?
b. (2 points) How will this matrix change if the eye moves forward in the
direction of view? [which elements in V will stay the same? which elements
will change and in what way?]
c. (3 points) What are the new horizontal and vertical fields of view after
this change has been made?
c. (2 points) How will this matrix change if the viewing direction spins in
the clockwise direction around the camera's 'up' direction? [which elements
in V will stay the same? which elements will change and in what way?]
d. (2 points) How will this matrix change if the viewing direction rotates
directly upward, within the plane defined by the viewing and 'up' directions?
[which elements in V will stay the same? which elements will change and in
what way?]
5.
## The Projection Transformation
6.
7.
8. \c{Consider the perspective projection-normalization matrix $P$ which maps
the contents of the viewing frustum into a cube that extends from -1 to 1 in
$x, y, z$ (called normalized device coordinates).}
\c{Suppose you want to define a square, symmetric viewing frustum with a near
clipping plane located 0.5 units in front of the camera, a far clipping plane
located 20 units from the front of the camera, a $60^\circ$ vertical field of
view, and a $60^\circ$ horizontal field of view.}
a. \c{(2 points) What are the entries in $P$?}
The left / right values are found by using the tangent of the field-of-view
triangle: $\tan(60^\circ) = \frac{\textrm{right}}{0.5}$, so $\textrm{right} =
\tan(60^\circ) \times 0.5 = \boxed{\frac{\sqrt{3}}{2}}$. The same goes for the
vertical, which also yields $\frac{\sqrt{3}}{2}$.
$$\begin{bmatrix}
\frac{2\times near}{right - left} & 0 & \frac{right + left}{right - left} & 0 \\
0 & \frac{2\times near}{top - bottom} & \frac{top + bottom}{top - bottom} & 0 \\
0 & 0 & -\frac{far + near}{far - near} & -\frac{2\times far\times near}{far - near} \\
0 & 0 & -1 & 0
\end{bmatrix}$$
$$= \begin{bmatrix}
\frac{2\times 0.5}{\frac{\sqrt{3}}{2} - (-\frac{\sqrt{3}}{2})} & 0 & \frac{\frac{\sqrt{3}}{2} + (-\frac{\sqrt{3}}{2})}{\frac{\sqrt{3}}{2} - (-\frac{\sqrt{3}}{2})} & 0 \\
0 & \frac{2\times 0.5}{\frac{\sqrt{3}}{2} - (-\frac{\sqrt{3}}{2})} & \frac{\frac{\sqrt{3}}{2} + (-\frac{\sqrt{3}}{2})}{\frac{\sqrt{3}}{2} - (-\frac{\sqrt{3}}{2})} & 0 \\
0 & 0 & -\frac{20 + 0.5}{20 - 0.5} & -\frac{2\times 20\times 0.5}{20 - 0.5} \\
0 & 0 & -1 & 0
\end{bmatrix}$$
$$= \boxed{\begin{bmatrix}
\frac{1}{\sqrt{3}} & 0 & 0 & 0 \\
0 & \frac{1}{\sqrt{3}} & 0 & 0 \\
0 & 0 & -\frac{41}{39} & -\frac{40}{39} \\
0 & 0 & -1 & 0
\end{bmatrix}}$$
b. \c{(3 points) How should be matrix $P$ be re-defined if the viewing window
is re-sized to be twice as tall as it is wide?}
c. \c{(3 points) What are the new horizontal and vertical fields of view
after this change has been made?}
## Clipping

View file

@ -1,4 +1,6 @@
import numpy as np
from sympy import *
import math
unit = lambda v: v/np.linalg.norm(v)
@ -33,6 +35,9 @@ def problem_1():
print("approx answer for part d", np.arcsin(1.0 / 1.5 * sin_theta_i))
def problem_4():
print("part 4a.")
def problem_8():
def P(left, right, bottom, top, near, far):
return np.array([
@ -42,9 +47,23 @@ def problem_8():
[0, 0, -1, 0],
])
near, far = left, right = bottom, top = -1, 1
print("part 8a", P(left, right, bottom, top, near, far))
near = 0.5
far = 20
def compute_view(vfov, hfov):
left = -math.tan(hfov) * near
right = math.tan(hfov) * near
bottom = -math.tan(vfov) * near
top = math.tan(vfov) * near
return left, right, bottom, top
print("part 8a")
vfov = hfov = math.radians(60)
left, right, bottom, top = compute_view(vfov, hfov)
print(P(left, right, bottom, top, near, far))
print()
problem_8()
problem_1()
print("\nPROBLEM 4 -------------------------"); problem_4()
print("\nPROBLEM 8 -------------------------"); problem_8()
print("\nPROBLEM 1 -------------------------"); problem_1()