ketaro-m / acg-ketaro-m

acg-ketaro-m created by GitHub Classroom
MIT License
0 stars 0 forks source link

Task04 #7

Closed ketaro-m closed 2 years ago

ketaro-m commented 2 years ago

I'm not confident whether my answer is correct. Especially return value.

ketaro-m commented 2 years ago

I implemented the transformation of the local coordinate to the world coordinate (this part) with the process below.

The rotational transformation matrix can be represented as the combination of the rotation around three axes.

$$R{local2world} = R{z} R{y} R{x}$$

The rotational matrices around each axis are represented as follows.

$z$-axis

$$ R_{z} = \begin{bmatrix} \cos{\psi} & \sin{\psi} & 0\ -\sin{\psi} & \cos{\psi} & 0\ 0 & 0 & 1 \end{bmatrix} $$

$y$-axis

$$ R_{y} = \begin{bmatrix} \cos{\theta} & 0 & \sin{\theta} \ 0 & 1 & 0 \ -\sin{\theta} & 0 & \cos{\theta} \end{bmatrix} $$

$x$-axis

$$ R_{x} = \begin{bmatrix} 1 & 0 & 0 \ 0 & \cos{\phi} & -\sin{\phi} \ 0 & \sin{\phi} & \cos{\phi} \end{bmatrix} $$

Since "phi" in the code is distributed uniformly, rotation around $z$-axis does nothing. Therefore, the rotational transformation matrix from the local coordinate to the world one should be,

$$ \begin{eqnarray} R{yx} &=&
R
{y}R_{x} \ &=& \begin{bmatrix} \cos{\theta} & 0 & \sin{\theta} \ 0 & 1 & 0 \ -\sin{\theta} & 0 & \cos{\theta} \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \ 0 & \cos{\phi} & -\sin{\phi} \ 0 & \sin{\phi} & \cos{\phi} \end{bmatrix} \ &=& \begin{bmatrix} \cos{\theta} & \sin{\theta}\sin{\phi} & \sin{\theta}\cos{\phi} \ 0 & \cos{\phi} & -\sin{\phi} \ -\sin{\theta} & \cos{\theta}\sin{\phi} & \cos{\theta}\cos{\phi} \end{bmatrix} \end{eqnarray} $$

Then, from the equation (local $z$-axis is transformed to the norm vector) below,

$$ R{yx} \begin{bmatrix} 0 \ 0 \ 1 \end{bmatrix} = \begin{bmatrix} n{0} \ n{1} \ n{2} \end{bmatrix} $$

$$ \Leftrightarrow \begin{empheq} [left=\empheqlbrace]{align} n{0} &= \sin{\theta}\cos{\phi} \ n{1} &= -\sin{\phi} \ n_{2} &= \cos{\theta}\cos{\phi} \end{empheq} \ $$

$$ \Leftrightarrow \begin{empheq} [left=\empheqlbrace]{align} \sin{\theta} &= \frac{n_{0}}{\sqrt{1-n1^2}} \ \cos{\theta} &= \frac{n{2}}{\sqrt{1-n1^2}} \ \sin{\phi} &= -n{1} \ \cos{\phi} &= -\sqrt{1-n_1^2} \end{empheq} $$

the rotational transformation matrix $R_{yx}$ is

$$ R{yx} = \begin{bmatrix} \frac{n{2}}{\sqrt{1-n1^2}} & -\frac{n{0}n_{1}}{\sqrt{1-n1^2}} & n{0} \ 0 & \sqrt{1-n1^2} & n{1} \ -\frac{n_{0}}{\sqrt{1-n1^2}} & -\frac{n{1}n_{2}}{\sqrt{1-n1^2}} & n{2} \end{bmatrix} $$

I compared my solution with one explained in the lecture printing out the "dir" (the code). The result doesn't exactly match. Could you explain where my mistake exists?

ketaro-m commented 2 years ago

And I couldn't understand why the returning value was 1.0.

nobuyuki83 commented 2 years ago

well done @ketaro-m !

nobuyuki83 commented 2 years ago

And I couldn't understand why the returning value was 1.0.

Originally, the integration has a weight of \cos\theta. With importance sampling, we sample the direction according to this cosine weight. Hence we can use the weight 1 here.