Progress
This commit is contained in:
parent
28d85930db
commit
f4dc18852a
5 changed files with 216 additions and 114 deletions
BIN
exam-2/1.jpg
Normal file
BIN
exam-2/1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
BIN
exam-2/6aii.jpg
Normal file
BIN
exam-2/6aii.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
BIN
exam-2/6bii.jpg
Normal file
BIN
exam-2/6bii.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
169
exam-2/exam2.md
169
exam-2/exam2.md
|
@ -11,10 +11,11 @@ author: |
|
|||
---
|
||||
|
||||
\renewcommand{\c}[1]{\textcolor{gray}{#1}}
|
||||
\renewcommand{\r}[1]{\textcolor{red}{#1}}
|
||||
\newcommand{\now}[1]{\textcolor{blue}{#1}}
|
||||
\newcommand{\todo}[0]{\textcolor{red}{\textbf{TODO}}}
|
||||
|
||||
[ 1 2 3 6 8 9 ]
|
||||
[ 2 3 8 9 ]
|
||||
|
||||
## Reflection and Refraction
|
||||
|
||||
|
@ -23,31 +24,44 @@ author: |
|
|||
1.0$). If a ray emanating from the point $e = (0, 0, 0)$ intersects $S$ at a
|
||||
point $p = (1, 4, 8)$:}
|
||||
|
||||
Legend for the rest of the problem:
|
||||
|
||||
![](1.jpg){width=50%}
|
||||
|
||||
a. \c{(2 points) What is the angle of incidence $\theta_i$?}
|
||||
|
||||
The incoming ray is in the direction $I = p - e = (1, 4, 8)$, and the normal
|
||||
at that point is $N = p - s = (1, 4, 8) - (2, 2, 10) = (1, -2, 2)$. The angle
|
||||
can be found by taking the opposite of the incoming ray $-I$ and using the
|
||||
formula $\cos \theta_i = \frac{-I \cdot N}{|I| |N|} = \frac{(-1, -4, -8)
|
||||
\cdot (1, -2, 2)}{9 \cdot 3} = \frac{-1 + 8 - 16}{27} = -\frac{1}{3}$. So the
|
||||
angle $\boxed{\theta_i = \cos^{-1}(-\frac{1}{3})}$.
|
||||
The incoming ray is in the direction $I = v_0 = p - e = (1, 4, 8)$, and the
|
||||
normal at that point is:
|
||||
|
||||
- $N = p - s = (1, 4, 8) - (2, 2, 10) = (-1, 2, -2)$
|
||||
|
||||
The angle can be found by taking the opposite of the incoming ray $-I$ and
|
||||
using the formula:
|
||||
|
||||
- $\cos \theta_i = \frac{-I \cdot N}{\|I\|_2 \|N\|_2}
|
||||
= \frac{(-1, -4, -8) \cdot (-1, 2, -2)}{9 \cdot 3} = \frac{1 - 8 + 16}{27} = \frac{1}{3}$.
|
||||
|
||||
So the angle $\boxed{\theta_i = \cos^{-1}\left(\frac{1}{3}\right)}$.
|
||||
|
||||
b. \c{(1 points) What is the angle of reflection $\theta_r$?}
|
||||
|
||||
The angle of reflection always equals the angle of incidence, $\theta_r =
|
||||
\theta_i = \boxed{\cos^{-1}(-\frac{1}{3})}$.
|
||||
\theta_i = \boxed{\cos^{-1}\left(\frac{1}{3}\right)}$.
|
||||
|
||||
c. \c{(3 points) What is the direction of the reflected ray?}
|
||||
|
||||
The reflected ray can be found by first projecting the incident ray $-I$ onto
|
||||
the normalized normal $N$, which is $v = N \times |-I|\cos(\theta_i) =
|
||||
(\frac{1}{3}, -\frac{2}{3}, \frac{2}{3}) \times 9 \times \frac{1}{3} = (-1,
|
||||
2, -2)$. Then, we know the point on N where this happened is $p' = p + v =
|
||||
(1, 4, 8) + (-1, 2, -2) = (0, 6, 6)$.
|
||||
The reflected ray can be found by first projecting the incident ray $v_0$ onto
|
||||
the normalized normal $n$, which is:
|
||||
|
||||
- $proj = n \times |v_0|\cos(\theta_i) = \left(\frac{1}{3}, -\frac{2}{3}, \frac{2}{3}\right) \times 9 \times \frac{1}{3} = (-1, 2, -2)$
|
||||
|
||||
Then, we know the point on N where this happened is:
|
||||
|
||||
- $nx = p + proj = (1, 4, 8) + (-1, 2, -2) = (0, 6, 6)$.
|
||||
|
||||
Now, we can subtract this point from where the ray originated to know the
|
||||
direction to add in the other direction, which is still $(0, 6, 6)$ in this
|
||||
case since the ray starts at the origin. Adding this to the point $p'$ gets
|
||||
case since the ray starts at the origin. Adding this to the point $nx$ gets
|
||||
us $(0, 12, 12)$, which means a point from the origin will get reflected to
|
||||
$(0, 12, 12)$.
|
||||
|
||||
|
@ -56,34 +70,45 @@ author: |
|
|||
|
||||
d. \c{(3 points) What is the angle of transmission $\theta_t$?}
|
||||
|
||||
Using Snell's law, we know that $\eta_i \sin \theta_i = \eta_t \sin \theta_t
|
||||
= 1.0 \times \sin(\cos^{-1}(-\frac{1}{3})) = 1.5 \times \sin(\theta_t)$. To
|
||||
find the angle $\theta_t$ we can just solve: $\theta_t =
|
||||
\sin^{-1}(\frac{2}{3} \times \sin(\cos^{-1}(-\frac{1}{3}))) \approx
|
||||
\boxed{0.6796}$ (in radians).
|
||||
Using Snell's law, we know that
|
||||
|
||||
\begin{align}
|
||||
\eta_i \sin \theta_i &= \eta_t \sin \theta_t \\
|
||||
\r{1.0} \times \sin \theta_i &= \r{1.5} \times \sin \theta_t \\
|
||||
1.0 \times \sin(\r{ \cos^{-1}(-\frac{1}{3}) }) &= 1.5 \times \sin \theta_t \\
|
||||
1.0 \times \r{ \frac{2\sqrt{2}}{3} } &= 1.5 \times \sin \theta_t \\
|
||||
\r{ \frac{1.0}{1.5} } \times \frac{2\sqrt{2}}{3} &= \sin \theta_t \\
|
||||
\r{ \frac{4}{9} } \sqrt{2} &= \sin \theta_t \\
|
||||
\theta_t &= \sin^{-1} \left(\frac{4}{9}\sqrt{2}\right) \approx
|
||||
\boxed{0.67967 \ldots}
|
||||
\end{align}
|
||||
|
||||
e. \c{(4 points) What is the direction of the transmitted ray?}
|
||||
|
||||
We can just add the angle obtained above to the inverse of the normal $n' =
|
||||
(-1, 2, -2)$ (since that will be transmitted through the material). For the
|
||||
tangent direction, we can use the vector from the ray's origin to the
|
||||
incident ray projected onto the normal, which we'll call $v = (0, 6, 6)$.
|
||||
We can just add together $s - p$ and $v_5$ in the diagram above, these two
|
||||
make up the orthogonal basis of the transmitted ray $v_4$. The lengths of
|
||||
these two are not important, but related through the angle $\theta_t$.
|
||||
|
||||
Now we know that the relationship between the coefficients of $n'$ and $v$ is
|
||||
$\tan(\theta_t)$. We can add these to obtain a point along the transmitted
|
||||
ray (it doesn't actually matter where this occurs since we're going to
|
||||
normalize this anyway, the proportion stays consistent regardless). So using
|
||||
the unit length for the inverse normal which is $\frac{n'}{||n'||} =
|
||||
(\frac{1}{3}, -\frac{2}{3}, \frac{2}{3})$ we know that the perpendicular
|
||||
vector will be $\tan(\theta_t) \times (0, \frac{1}{\sqrt{2}},
|
||||
\frac{1}{\sqrt{2}})$.
|
||||
Also note that in the diagram, the sphere is drawn as a 2D circle. But in
|
||||
reality, the number of vectors perpendicular to $s - p$ is infinite. The
|
||||
$v_5$ we're looking for is parallel with $v_1$, so we can just use
|
||||
$\frac{v_1}{\|v_1\|_2}$ as our unit vector for $v_5$.
|
||||
|
||||
The final step is then adding these vectors together and subtracting the
|
||||
interersection point: $(\frac{1}{3}, -\frac{2}{3}, \frac{2}{3}) +
|
||||
\tan(\theta_t) \times (0, \frac{1}{\sqrt{2}}, \frac{1}{\sqrt{2}}) - (1, 4,
|
||||
8)$.
|
||||
\begin{align}
|
||||
v_4 &= (s - p) + \tan \theta_t \times \|s - p\|_2 \times \frac{v_1}{\|v_1\|_2} \\
|
||||
v_4 &= (\r{ (2, 2, 10) - (1, 4, 8) }) + \tan \theta_t \times \|s - p\|_2 \times \frac{v_1}{\|v_1\|_2} \\
|
||||
v_4 &= \r{ (1, -2, 2) } + \tan \theta_t \times \|\r{(1, -2, 2)}\|_2 \times \frac{v_1}{\|v_1\|_2} \\
|
||||
v_4 &= (1, -2, 2) + \tan \theta_t \times \r{3} \times \frac{v_1}{\|v_1\|_2} \\
|
||||
v_4 &= (1, -2, 2) + \tan \theta_t \times 3 \times \frac{\r{(0, 6, 6)}}{\|\r{(0, 6, 6)}\|_2} \\
|
||||
v_4 &= (1, -2, 2) + \tan \theta_t \times 3 \times \r{\left(0, \frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2}\right)} \\
|
||||
v_4 &= (1, -2, 2) + \tan \theta_t \times \left(0, \r{\frac{3}{2}\sqrt{2}}, \r{\frac{3}{2}\sqrt{2}} \right) \\
|
||||
v_4 &= (1, -2, 2) + \r{\frac{4}{7}\sqrt{2}} \times \left(0, \frac{3}{2}\sqrt{2}, \frac{3}{2}\sqrt{2} \right) \\
|
||||
v_4 &= (1, -2, 2) + \r{\left(0, \frac{12}{7}, \frac{12}{7} \right)} \\
|
||||
v_4 &= \r{\left(1, \frac{-2}{7}, \frac{26}{7} \right)} \\
|
||||
\end{align}
|
||||
|
||||
\todo all the numbers are wrong
|
||||
This can be normalized into $\boxed{\left(\frac{7}{27}, -\frac{2}{27},
|
||||
\frac{26}{27}\right)}$.
|
||||
|
||||
## Geometric Transformations
|
||||
|
||||
|
@ -380,14 +405,14 @@ author: |
|
|||
i) \c{(2 points) Where will the six vertex locations be after such a
|
||||
projection, omitting the normalization step?}
|
||||
|
||||
- $[\begin{matrix}-1.732 & -1.732 & -6.928\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1.0 & -1.0 & 7.0\end{matrix}]$
|
||||
- $[\begin{matrix}-1.732 & -1.732 & -3.464\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1.0 & -1.0 & 5.0\end{matrix}]$
|
||||
- $[\begin{matrix}-1.732 & 1.732 & -6.928\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1.0 & 1.0 & 7.0\end{matrix}]$
|
||||
- $[\begin{matrix}-1.732 & 1.732 & -3.464\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1.0 & 1.0 & 5.0\end{matrix}]$
|
||||
- $[\begin{matrix}1.732 & -1.732 & -6.928\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1.0 & -1.0 & 7.0\end{matrix}]$
|
||||
- $[\begin{matrix}1.732 & -1.732 & -3.464\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1.0 & -1.0 & 5.0\end{matrix}]$
|
||||
- $[\begin{matrix}1.732 & 1.732 & -6.928\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1.0 & 1.0 & 7.0\end{matrix}]$
|
||||
- $[\begin{matrix}1.732 & 1.732 & -3.464\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1.0 & 1.0 & 5.0\end{matrix}]$
|
||||
- $[\begin{matrix}- \sqrt{3} & - \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1 & -1 & 7\end{matrix}]$
|
||||
- $[\begin{matrix}- \sqrt{3} & \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1 & 1 & 7\end{matrix}]$
|
||||
- $[\begin{matrix}\sqrt{3} & - \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 & -1 & 7\end{matrix}]$
|
||||
- $[\begin{matrix}\sqrt{3} & \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 & 1 & 7\end{matrix}]$
|
||||
- $[\begin{matrix}- \sqrt{3} & - \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1 & -1 & 5\end{matrix}]$
|
||||
- $[\begin{matrix}- \sqrt{3} & \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1 & 1 & 5\end{matrix}]$
|
||||
- $[\begin{matrix}\sqrt{3} & - \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 & -1 & 5\end{matrix}]$
|
||||
- $[\begin{matrix}\sqrt{3} & \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 & 1 & 5\end{matrix}]$
|
||||
|
||||
ii) \c{(1 points) Sketch the result, being as accurate as possible and
|
||||
labeling the colors of each of the visible faces.}
|
||||
|
@ -396,6 +421,8 @@ author: |
|
|||
sides are not visible because the cube is parallel to the axis, and when you
|
||||
do an orthographic projection, those faces are lost.
|
||||
|
||||
![](6aii.jpg){width=40%}
|
||||
|
||||
iii) \c{(2 points) Show how you could achieve this transformation using one or
|
||||
more matrix multiplication operations. Specify the matrix entries you would
|
||||
use, and, if using multiple matrices, the order in which they would be
|
||||
|
@ -405,14 +432,7 @@ author: |
|
|||
in this Python script:
|
||||
|
||||
```py
|
||||
def ortho(points):
|
||||
left = min(map(lambda p: p[0], points))
|
||||
right = max(map(lambda p: p[0], points))
|
||||
bottom = min(map(lambda p: p[1], points))
|
||||
top = max(map(lambda p: p[1], points))
|
||||
near = min(map(lambda p: p[2], points))
|
||||
far = max(map(lambda p: p[2], points))
|
||||
|
||||
def ortho_transform(left, right, bottom, top, near, far):
|
||||
step_1 = np.array([
|
||||
[1, 0, 0, 0],
|
||||
[0, 1, 0, 0],
|
||||
|
@ -421,20 +441,20 @@ author: |
|
|||
])
|
||||
|
||||
step_2 = np.array([
|
||||
[1, 0, 0, -(left + right) / 2.0],
|
||||
[0, 1, 0, -(bottom + top) / 2.0],
|
||||
[0, 0, 1, -(near + far) / 2.0],
|
||||
[1, 0, 0, -((left + right) / 2)],
|
||||
[0, 1, 0, -((bottom + top) / 2)],
|
||||
[0, 0, 1, -((near + far) / 2)],
|
||||
[0, 0, 0, 1],
|
||||
])
|
||||
|
||||
step_3 = np.array([
|
||||
[2.0 / (right - left), 0, 0, 0],
|
||||
[0, 2.0 / (top - bottom), 0, 0],
|
||||
[0, 0, 2.0 / (far - near), 0],
|
||||
[(2 / (right - left)), 0, 0, 0],
|
||||
[0, (2 / (top - bottom)), 0, 0],
|
||||
[0, 0, (2 / (far - near)), 0],
|
||||
[0, 0, 0, 1],
|
||||
])
|
||||
|
||||
M_ortho = step_3 @ step_2 @ step_1
|
||||
return step_3 @ step_2 @ step_1
|
||||
```
|
||||
|
||||
b. \c{Show how you could project the vertices of this cube to the plane $z =
|
||||
|
@ -444,14 +464,45 @@ author: |
|
|||
i) \c{(3 points) Where will the six vertex locations be after such a
|
||||
projection, omitting the normalization step?}
|
||||
|
||||
- $[\begin{matrix}- \sqrt{3} & - \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}- \frac{4 \sqrt{3}}{3} - 1 & -1 & 7\end{matrix}]$
|
||||
- $[\begin{matrix}- \sqrt{3} & \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}- \frac{4 \sqrt{3}}{3} - 1 & 1 & 7\end{matrix}]$
|
||||
- $[\begin{matrix}\sqrt{3} & - \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 - \frac{4 \sqrt{3}}{3} & -1 & 7\end{matrix}]$
|
||||
- $[\begin{matrix}\sqrt{3} & \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 - \frac{4 \sqrt{3}}{3} & 1 & 7\end{matrix}]$
|
||||
- $[\begin{matrix}- \sqrt{3} & - \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}- \frac{2 \sqrt{3}}{3} - 1 & -1 & 5\end{matrix}]$
|
||||
- $[\begin{matrix}- \sqrt{3} & \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}- \frac{2 \sqrt{3}}{3} - 1 & 1 & 5\end{matrix}]$
|
||||
- $[\begin{matrix}\sqrt{3} & - \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 - \frac{2 \sqrt{3}}{3} & -1 & 5\end{matrix}]$
|
||||
- $[\begin{matrix}\sqrt{3} & \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 - \frac{2 \sqrt{3}}{3} & 1 & 5\end{matrix}]$
|
||||
|
||||
ii) \c{(2 points) Sketch the result, being as accurate as possible and
|
||||
labeling the colors of each of the visible faces.}
|
||||
|
||||
![](6bii.jpg){width=40%}
|
||||
|
||||
Excuse the poor sketch but the point is the transformation exposes the green
|
||||
face to the left by doing a shear first.
|
||||
|
||||
iii) \c{(4 points) Show how you could achieve this transformation using one
|
||||
or more matrix multiplication operations. Specify the matrix entries you
|
||||
would use, and, if using multiple matrices, the order in which they would be
|
||||
multiplied.}
|
||||
|
||||
It's the same as the ortho, except it uses an extra matrix that is applied
|
||||
before any of the other transformations:
|
||||
|
||||
```py
|
||||
def oblique_transform(left, right, bottom, top, near, far):
|
||||
step_0 = np.array([
|
||||
[1, 0, (1 / sqrt3), 0],
|
||||
[0, 1, 0, 0],
|
||||
[0, 0, 1, 0],
|
||||
[0, 0, 0, 1],
|
||||
])
|
||||
|
||||
M_ortho = ortho_transform(left, right, bottom, top, near, far)
|
||||
|
||||
return M_ortho @ step_0
|
||||
```
|
||||
|
||||
7. \c{Consider the simple scene shown in the image below, where two cubes, one
|
||||
of height 1 and one of height 2, are both resting on a horizontal groundplane
|
||||
($y = -\frac{1}{2}$), with the smaller cube’s front face aligned with $z =
|
||||
|
|
161
exam-2/exam2.py
161
exam-2/exam2.py
|
@ -1,7 +1,12 @@
|
|||
import itertools
|
||||
import numpy as np
|
||||
from sympy import *
|
||||
import math
|
||||
from sympy import N, Number, Rational, init_printing, latex, simplify, Expr
|
||||
from sympy.vector import CoordSys3D, Vector
|
||||
|
||||
init_printing()
|
||||
|
||||
import sympy
|
||||
|
||||
unit = lambda v: v/np.linalg.norm(v)
|
||||
|
||||
|
@ -57,45 +62,65 @@ def print_bmatrix(arr):
|
|||
print("\\\\")
|
||||
|
||||
def problem_1():
|
||||
p = np.array([1, 4, 8])
|
||||
e = np.array([0, 0, 0])
|
||||
s = np.array([2, 2, 10])
|
||||
C = CoordSys3D('C')
|
||||
p = 1 * C.i + 4 * C.j + 8 * C.k
|
||||
e = 0 * C.i + 0 * C.j + 0 * C.k
|
||||
s = 2 * C.i + 2 * C.j + 10 * C.k
|
||||
radius = 3
|
||||
|
||||
i = p - e
|
||||
print("incoming", i)
|
||||
print("|I| =", np.linalg.norm(i))
|
||||
n = s - p
|
||||
print("normal", n)
|
||||
v0 = p - e
|
||||
print("v0 (incoming ray) =", v0)
|
||||
print(" - |v0| =", v0.magnitude())
|
||||
print()
|
||||
|
||||
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))
|
||||
n = p - s
|
||||
print("n (normal) =", n)
|
||||
n_norm = n.normalize()
|
||||
print(" - n_norm (normalized) =", n_norm)
|
||||
print()
|
||||
|
||||
proj = n_norm * np.linalg.norm(i) * cos_theta_i
|
||||
print("proj", proj)
|
||||
cos_theta_i = (-v0).dot(n) / (v0.magnitude() * n.magnitude())
|
||||
theta_i = sympy.acos(cos_theta_i)
|
||||
print("[1a] theta_i (angle of incidence) =", theta_i)
|
||||
print()
|
||||
|
||||
p_ = p + proj
|
||||
print("proj point", p_)
|
||||
proj_len = cos_theta_i * v0.magnitude()
|
||||
proj = n_norm * proj_len
|
||||
print("projection of v0 onto n =", proj)
|
||||
|
||||
v2 = p_ - e
|
||||
print("v2", v2)
|
||||
nx = p + proj
|
||||
print("nx (proj point) =", nx)
|
||||
print()
|
||||
|
||||
sin_theta_i = np.sin(np.arccos(cos_theta_i))
|
||||
print("sin theta_i =", sin_theta_i)
|
||||
v1 = nx - e
|
||||
print("v1 (from e to nx) =", v1)
|
||||
|
||||
theta_t = np.arcsin(1.0 / 1.5 * sin_theta_i)
|
||||
print("approx answer for part d", theta_t)
|
||||
z = e + 2 * v1
|
||||
print("z =", z)
|
||||
|
||||
uin = unit(n_norm)
|
||||
print("unit inv normal", uin)
|
||||
v3 = z - p
|
||||
print("v3 =", v3)
|
||||
print()
|
||||
|
||||
uperp = unit(v2)
|
||||
print("uperp", uperp)
|
||||
sin_theta_i = sympy.sin(theta_i)
|
||||
print("sin(theta_i) =", sin_theta_i)
|
||||
|
||||
answer_1e = uin + math.tan(theta_t) * uperp - p
|
||||
print("1e answer", unit(answer_1e))
|
||||
theta_t = sympy.asin(Rational(2, 3) * sin_theta_i)
|
||||
print("[1d] theta_t (angle of transmission) =", theta_t)
|
||||
print(" - approx =", theta_t.evalf())
|
||||
print()
|
||||
|
||||
v5_len = sympy.tan(theta_t) * (s - p).magnitude()
|
||||
print("v5 len =", v5_len)
|
||||
v4 = (s - p) + v1.normalize() * v5_len
|
||||
print("v4 =", v4)
|
||||
print(" - [1e] normalized =", v4.normalize())
|
||||
print()
|
||||
|
||||
print("s - p =", s - p)
|
||||
print("|s - p| =", (s - p).magnitude())
|
||||
print("|v1| =", v1.normalize())
|
||||
print("tan(theta_t) =", sympy.tan(theta_t))
|
||||
|
||||
def problem_4():
|
||||
camera_pos = np.array([2, 3, 5])
|
||||
|
@ -229,14 +254,11 @@ def problem_7():
|
|||
solve(camera_pos, angle)
|
||||
|
||||
def problem_6():
|
||||
def calculate(points):
|
||||
left = min(map(lambda p: p[0], points))
|
||||
right = max(map(lambda p: p[0], points))
|
||||
bottom = min(map(lambda p: p[1], points))
|
||||
top = max(map(lambda p: p[1], points))
|
||||
near = min(map(lambda p: p[2], points))
|
||||
far = max(map(lambda p: p[2], points))
|
||||
# sqrt3 = math.sqrt(3)
|
||||
sqrt3 = sympy.sqrt(3)
|
||||
width = 2 * sqrt3
|
||||
|
||||
def ortho_transform(left, right, bottom, top, near, far):
|
||||
step_1 = np.array([
|
||||
[1, 0, 0, 0],
|
||||
[0, 1, 0, 0],
|
||||
|
@ -245,46 +267,75 @@ def problem_6():
|
|||
])
|
||||
|
||||
step_2 = np.array([
|
||||
[1, 0, 0, -(left + right) / 2.0],
|
||||
[0, 1, 0, -(bottom + top) / 2.0],
|
||||
[0, 0, 1, -(near + far) / 2.0],
|
||||
[1, 0, 0, -((left + right) / 2)],
|
||||
[0, 1, 0, -((bottom + top) / 2)],
|
||||
[0, 0, 1, -((near + far) / 2)],
|
||||
[0, 0, 0, 1],
|
||||
])
|
||||
|
||||
step_3 = np.array([
|
||||
[2.0 / (right - left), 0, 0, 0],
|
||||
[0, 2.0 / (top - bottom), 0, 0],
|
||||
[0, 0, 2.0 / (far - near), 0],
|
||||
[(2 / (right - left)), 0, 0, 0],
|
||||
[0, (2 / (top - bottom)), 0, 0],
|
||||
[0, 0, (2 / (far - near)), 0],
|
||||
[0, 0, 0, 1],
|
||||
])
|
||||
|
||||
M_ortho = step_3 @ step_2 @ step_1
|
||||
return step_3 @ step_2 @ step_1
|
||||
|
||||
def oblique_transform(left, right, bottom, top, near, far):
|
||||
step_0 = np.array([
|
||||
[1, 0, (1 / sqrt3), 0],
|
||||
[0, 1, 0, 0],
|
||||
[0, 0, 1, 0],
|
||||
[0, 0, 0, 1],
|
||||
])
|
||||
|
||||
M_ortho = ortho_transform(left, right, bottom, top, near, far)
|
||||
|
||||
return M_ortho @ step_0
|
||||
|
||||
def calculate(M, points):
|
||||
left = min(map(lambda p: p[0], points))
|
||||
right = max(map(lambda p: p[0], points))
|
||||
bottom = min(map(lambda p: p[1], points))
|
||||
top = max(map(lambda p: p[1], points))
|
||||
near = min(map(lambda p: p[2], points))
|
||||
far = max(map(lambda p: p[2], points))
|
||||
|
||||
for point in points:
|
||||
point_ = np.r_[point, [1]]
|
||||
trans_ = M_ortho @ point_
|
||||
trans_ = M(left, right, bottom, top, near, far) @ point_
|
||||
trans = trans_[:3]
|
||||
print("-", print_trans(np.around(point, 3), np.around(trans, 3)))
|
||||
v = np.vectorize(lambda x: float(x.evalf()))
|
||||
l = np.vectorize(lambda x: latex(simplify(x)))
|
||||
point = l(point)
|
||||
trans = l(trans)
|
||||
print("-", print_trans(point, trans))
|
||||
|
||||
sqrt3 = math.sqrt(3)
|
||||
width = 2.0 * sqrt3
|
||||
cube_center = np.array([0, 0, -3.0 * sqrt3])
|
||||
print("HELLOSU")
|
||||
cube_center = np.array([0, 0, -3 * sqrt3])
|
||||
|
||||
points = []
|
||||
for (dx, dy, dz) in itertools.product([-1, 1], [-1, 1], [-1, 1]):
|
||||
point = cube_center + np.array([dx * width / 2, dy * width / 2, dz * width / 2])
|
||||
for (dz, dx, dy) in itertools.product([-1, 1], [-1, 1], [-1, 1]):
|
||||
point = cube_center + np.array([
|
||||
dx * width / 2,
|
||||
dy * width / 2,
|
||||
dz * width / 2,
|
||||
])
|
||||
points.append(point)
|
||||
|
||||
calculate(points)
|
||||
print("Helosu Ortho")
|
||||
calculate(ortho_transform, points)
|
||||
|
||||
print("Helosu Oblique")
|
||||
calculate(oblique_transform, points)
|
||||
|
||||
def problem_9():
|
||||
pass
|
||||
|
||||
print("\nPROBLEM 8 -------------------------"); problem_8()
|
||||
print("\nPROBLEM 1 -------------------------"); problem_1()
|
||||
print("\nPROBLEM 5 -------------------------"); problem_5()
|
||||
print("\nPROBLEM 9 -------------------------"); problem_9()
|
||||
print("\nPROBLEM 7 -------------------------"); problem_7()
|
||||
print("\nPROBLEM 6 -------------------------"); problem_6()
|
||||
print("\nPROBLEM 4 -------------------------"); problem_4()
|
||||
print("\nPROBLEM 6 -------------------------"); problem_6()
|
||||
print("\nPROBLEM 1 -------------------------"); problem_1()
|
||||
|
|
Loading…
Reference in a new issue