This commit is contained in:
Michael Zhang 2023-05-03 04:14:29 -05:00
parent 28d85930db
commit f4dc18852a
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
5 changed files with 216 additions and 114 deletions

BIN
exam-2/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -11,10 +11,11 @@ author: |
--- ---
\renewcommand{\c}[1]{\textcolor{gray}{#1}} \renewcommand{\c}[1]{\textcolor{gray}{#1}}
\renewcommand{\r}[1]{\textcolor{red}{#1}}
\newcommand{\now}[1]{\textcolor{blue}{#1}} \newcommand{\now}[1]{\textcolor{blue}{#1}}
\newcommand{\todo}[0]{\textcolor{red}{\textbf{TODO}}} \newcommand{\todo}[0]{\textcolor{red}{\textbf{TODO}}}
[ 1 2 3 6 8 9 ] [ 2 3 8 9 ]
## Reflection and Refraction ## 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 1.0$). If a ray emanating from the point $e = (0, 0, 0)$ intersects $S$ at a
point $p = (1, 4, 8)$:} 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$?} 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 The incoming ray is in the direction $I = v_0 = p - e = (1, 4, 8)$, and the
at that point is $N = p - s = (1, 4, 8) - (2, 2, 10) = (1, -2, 2)$. The angle normal at that point is:
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) - $N = p - s = (1, 4, 8) - (2, 2, 10) = (-1, 2, -2)$
\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 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$?} b. \c{(1 points) What is the angle of reflection $\theta_r$?}
The angle of reflection always equals the angle of incidence, $\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?} 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 reflected ray can be found by first projecting the incident ray $v_0$ onto
the normalized normal $N$, which is $v = N \times |-I|\cos(\theta_i) = the normalized normal $n$, which is:
(\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 = - $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)$
(1, 4, 8) + (-1, 2, -2) = (0, 6, 6)$.
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 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 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 us $(0, 12, 12)$, which means a point from the origin will get reflected to
$(0, 12, 12)$. $(0, 12, 12)$.
@ -56,34 +70,45 @@ author: |
d. \c{(3 points) What is the angle of transmission $\theta_t$?} 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 Using Snell's law, we know that
= 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 = \begin{align}
\sin^{-1}(\frac{2}{3} \times \sin(\cos^{-1}(-\frac{1}{3}))) \approx \eta_i \sin \theta_i &= \eta_t \sin \theta_t \\
\boxed{0.6796}$ (in radians). \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?} 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' = We can just add together $s - p$ and $v_5$ in the diagram above, these two
(-1, 2, -2)$ (since that will be transmitted through the material). For the make up the orthogonal basis of the transmitted ray $v_4$. The lengths of
tangent direction, we can use the vector from the ray's origin to the these two are not important, but related through the angle $\theta_t$.
incident ray projected onto the normal, which we'll call $v = (0, 6, 6)$.
Now we know that the relationship between the coefficients of $n'$ and $v$ is Also note that in the diagram, the sphere is drawn as a 2D circle. But in
$\tan(\theta_t)$. We can add these to obtain a point along the transmitted reality, the number of vectors perpendicular to $s - p$ is infinite. The
ray (it doesn't actually matter where this occurs since we're going to $v_5$ we're looking for is parallel with $v_1$, so we can just use
normalize this anyway, the proportion stays consistent regardless). So using $\frac{v_1}{\|v_1\|_2}$ as our unit vector for $v_5$.
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}})$.
The final step is then adding these vectors together and subtracting the \begin{align}
interersection point: $(\frac{1}{3}, -\frac{2}{3}, \frac{2}{3}) + v_4 &= (s - p) + \tan \theta_t \times \|s - p\|_2 \times \frac{v_1}{\|v_1\|_2} \\
\tan(\theta_t) \times (0, \frac{1}{\sqrt{2}}, \frac{1}{\sqrt{2}}) - (1, 4, v_4 &= (\r{ (2, 2, 10) - (1, 4, 8) }) + \tan \theta_t \times \|s - p\|_2 \times \frac{v_1}{\|v_1\|_2} \\
8)$. 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 ## Geometric Transformations
@ -380,14 +405,14 @@ author: |
i) \c{(2 points) Where will the six vertex locations be after such a i) \c{(2 points) Where will the six vertex locations be after such a
projection, omitting the normalization step?} 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}- \sqrt{3} & - \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1 & -1 & 7\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}-1.732 & 1.732 & -6.928\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1.0 & 1.0 & 7.0\end{matrix}]$ - $[\begin{matrix}\sqrt{3} & - \sqrt{3} & - 4 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 & -1 & 7\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}1.732 & -1.732 & -6.928\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1.0 & -1.0 & 7.0\end{matrix}]$ - $[\begin{matrix}- \sqrt{3} & - \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1 & -1 & 5\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} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}-1 & 1 & 5\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}\sqrt{3} & - \sqrt{3} & - 2 \sqrt{3}\end{matrix}]$ $\rightarrow$ $[\begin{matrix}1 & -1 & 5\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} & - 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 ii) \c{(1 points) Sketch the result, being as accurate as possible and
labeling the colors of each of the visible faces.} 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 sides are not visible because the cube is parallel to the axis, and when you
do an orthographic projection, those faces are lost. 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 iii) \c{(2 points) Show how you could achieve this transformation using one or
more matrix multiplication operations. Specify the matrix entries you would more matrix multiplication operations. Specify the matrix entries you would
use, and, if using multiple matrices, the order in which they would be use, and, if using multiple matrices, the order in which they would be
@ -405,14 +432,7 @@ author: |
in this Python script: in this Python script:
```py ```py
def ortho(points): def ortho_transform(left, right, bottom, top, near, far):
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))
step_1 = np.array([ step_1 = np.array([
[1, 0, 0, 0], [1, 0, 0, 0],
[0, 1, 0, 0], [0, 1, 0, 0],
@ -421,20 +441,20 @@ author: |
]) ])
step_2 = np.array([ step_2 = np.array([
[1, 0, 0, -(left + right) / 2.0], [1, 0, 0, -((left + right) / 2)],
[0, 1, 0, -(bottom + top) / 2.0], [0, 1, 0, -((bottom + top) / 2)],
[0, 0, 1, -(near + far) / 2.0], [0, 0, 1, -((near + far) / 2)],
[0, 0, 0, 1], [0, 0, 0, 1],
]) ])
step_3 = np.array([ step_3 = np.array([
[2.0 / (right - left), 0, 0, 0], [(2 / (right - left)), 0, 0, 0],
[0, 2.0 / (top - bottom), 0, 0], [0, (2 / (top - bottom)), 0, 0],
[0, 0, 2.0 / (far - near), 0], [0, 0, (2 / (far - near)), 0],
[0, 0, 0, 1], [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 = 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 i) \c{(3 points) Where will the six vertex locations be after such a
projection, omitting the normalization step?} 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 ii) \c{(2 points) Sketch the result, being as accurate as possible and
labeling the colors of each of the visible faces.} 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 iii) \c{(4 points) Show how you could achieve this transformation using one
or more matrix multiplication operations. Specify the matrix entries you or more matrix multiplication operations. Specify the matrix entries you
would use, and, if using multiple matrices, the order in which they would be would use, and, if using multiple matrices, the order in which they would be
multiplied.} 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 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 of height 1 and one of height 2, are both resting on a horizontal groundplane
($y = -\frac{1}{2}$), with the smaller cubes front face aligned with $z = ($y = -\frac{1}{2}$), with the smaller cubes front face aligned with $z =

View file

@ -1,7 +1,12 @@
import itertools import itertools
import numpy as np import numpy as np
from sympy import *
import math 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) unit = lambda v: v/np.linalg.norm(v)
@ -57,45 +62,65 @@ def print_bmatrix(arr):
print("\\\\") print("\\\\")
def problem_1(): def problem_1():
p = np.array([1, 4, 8]) C = CoordSys3D('C')
e = np.array([0, 0, 0]) p = 1 * C.i + 4 * C.j + 8 * C.k
s = np.array([2, 2, 10]) 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 v0 = p - e
print("incoming", i) print("v0 (incoming ray) =", v0)
print("|I| =", np.linalg.norm(i)) print(" - |v0| =", v0.magnitude())
n = s - p print()
print("normal", n)
n_norm = unit(n) n = p - s
print("normal_norm", n_norm) print("n (normal) =", n)
cos_theta_i = np.dot(-i, n) / (np.linalg.norm(i) * np.linalg.norm(n)) n_norm = n.normalize()
print("part a = cos^{-1} of ", cos_theta_i) print(" - n_norm (normalized) =", n_norm)
print(np.arccos(cos_theta_i)) print()
proj = n_norm * np.linalg.norm(i) * cos_theta_i cos_theta_i = (-v0).dot(n) / (v0.magnitude() * n.magnitude())
print("proj", proj) theta_i = sympy.acos(cos_theta_i)
print("[1a] theta_i (angle of incidence) =", theta_i)
print()
p_ = p + proj proj_len = cos_theta_i * v0.magnitude()
print("proj point", p_) proj = n_norm * proj_len
print("projection of v0 onto n =", proj)
v2 = p_ - e nx = p + proj
print("v2", v2) print("nx (proj point) =", nx)
print()
sin_theta_i = np.sin(np.arccos(cos_theta_i)) v1 = nx - e
print("sin theta_i =", sin_theta_i) print("v1 (from e to nx) =", v1)
theta_t = np.arcsin(1.0 / 1.5 * sin_theta_i) z = e + 2 * v1
print("approx answer for part d", theta_t) print("z =", z)
uin = unit(n_norm) v3 = z - p
print("unit inv normal", uin) print("v3 =", v3)
print()
uperp = unit(v2) sin_theta_i = sympy.sin(theta_i)
print("uperp", uperp) print("sin(theta_i) =", sin_theta_i)
answer_1e = uin + math.tan(theta_t) * uperp - p theta_t = sympy.asin(Rational(2, 3) * sin_theta_i)
print("1e answer", unit(answer_1e)) 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(): def problem_4():
camera_pos = np.array([2, 3, 5]) camera_pos = np.array([2, 3, 5])
@ -229,14 +254,11 @@ def problem_7():
solve(camera_pos, angle) solve(camera_pos, angle)
def problem_6(): def problem_6():
def calculate(points): # sqrt3 = math.sqrt(3)
left = min(map(lambda p: p[0], points)) sqrt3 = sympy.sqrt(3)
right = max(map(lambda p: p[0], points)) width = 2 * sqrt3
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([ step_1 = np.array([
[1, 0, 0, 0], [1, 0, 0, 0],
[0, 1, 0, 0], [0, 1, 0, 0],
@ -245,46 +267,75 @@ def problem_6():
]) ])
step_2 = np.array([ step_2 = np.array([
[1, 0, 0, -(left + right) / 2.0], [1, 0, 0, -((left + right) / 2)],
[0, 1, 0, -(bottom + top) / 2.0], [0, 1, 0, -((bottom + top) / 2)],
[0, 0, 1, -(near + far) / 2.0], [0, 0, 1, -((near + far) / 2)],
[0, 0, 0, 1], [0, 0, 0, 1],
]) ])
step_3 = np.array([ step_3 = np.array([
[2.0 / (right - left), 0, 0, 0], [(2 / (right - left)), 0, 0, 0],
[0, 2.0 / (top - bottom), 0, 0], [0, (2 / (top - bottom)), 0, 0],
[0, 0, 2.0 / (far - near), 0], [0, 0, (2 / (far - near)), 0],
[0, 0, 0, 1], [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: for point in points:
point_ = np.r_[point, [1]] point_ = np.r_[point, [1]]
trans_ = M_ortho @ point_ trans_ = M(left, right, bottom, top, near, far) @ point_
trans = trans_[:3] 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) cube_center = np.array([0, 0, -3 * sqrt3])
width = 2.0 * sqrt3
cube_center = np.array([0, 0, -3.0 * sqrt3])
print("HELLOSU")
points = [] points = []
for (dx, dy, dz) in itertools.product([-1, 1], [-1, 1], [-1, 1]): 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]) point = cube_center + np.array([
dx * width / 2,
dy * width / 2,
dz * width / 2,
])
points.append(point) points.append(point)
calculate(points) print("Helosu Ortho")
calculate(ortho_transform, points)
print("Helosu Oblique")
calculate(oblique_transform, points)
def problem_9(): def problem_9():
pass pass
print("\nPROBLEM 8 -------------------------"); problem_8() print("\nPROBLEM 8 -------------------------"); problem_8()
print("\nPROBLEM 1 -------------------------"); problem_1()
print("\nPROBLEM 5 -------------------------"); problem_5() print("\nPROBLEM 5 -------------------------"); problem_5()
print("\nPROBLEM 9 -------------------------"); problem_9() print("\nPROBLEM 9 -------------------------"); problem_9()
print("\nPROBLEM 7 -------------------------"); problem_7() print("\nPROBLEM 7 -------------------------"); problem_7()
print("\nPROBLEM 6 -------------------------"); problem_6()
print("\nPROBLEM 4 -------------------------"); problem_4() print("\nPROBLEM 4 -------------------------"); problem_4()
print("\nPROBLEM 6 -------------------------"); problem_6()
print("\nPROBLEM 1 -------------------------"); problem_1()