Skip to content

Commit

Permalink
Add reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
miloyip committed Nov 12, 2017
1 parent 4a19d32 commit 20ac86a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,23 @@ Examples of various shapes defined by SDF:
![ ](shapes.png)

![ ](m.png)

# Reflection

Source code: [reflection.c](reflection.c)

Test scene with two boxes:

![ ](reflection_boxscene.png)

Visualization of SDF gradient, which is approximated by central difference:

![ ](reflection_boxgradient.png)

Reflection via recursive tracing:

![ ](reflection_box.png)

Concave mirror scene generates caustics effect:

![ ](reflection_concavemirror.png)
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGETS=basic csg shapes
TARGETS=basic csg shapes reflection
OUTPUTS=$(addsuffix .png, $(TARGETS))
TEXFILES=$(basename $(wildcard *.tex))
DIAGRAMS=$(addsuffix .png, $(TEXFILES))
Expand All @@ -15,7 +15,7 @@ diagram: $(DIAGRAMS)

%.png: %.tex
xelatex $<
convert $(basename $<).pdf $(basename $<).png
convert -density 150 $(basename $<).pdf $(basename $<).png
rm $(basename $<).aux $(basename $<).log $(basename $<).pdf

clean:
Expand Down
Binary file added reflection_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reflection_boxgradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reflection_boxscene.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reflection_concavemirror.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vector_reflect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions vector_reflect.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,angles,quotes,calc,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[>=triangle 45,line width=1.6pt,scale=1.5,font=\fontsize{20pt}{0},
interface/.style={
postaction={draw,decorate,decoration={border,angle=-45,
amplitude=0.3cm,segment length=2mm}}}]
\coordinate (O) at (0,0);
\coordinate (V) at (-3,2);
\coordinate (R) at (3,2);
\coordinate (N) at (0, 1.5);
\draw[blue,line width=.5pt,interface](-4,0)--(4,0);
\draw[->] (O) -- (N) node[anchor=south] {$\hat{\mathbf{n}}$};
\draw[->] (V) -- (O) node[midway, anchor=north east] {$\mathbf{i}$};
\draw[->] (O) -- (R) node[midway, anchor=north west] {$\mathbf{r}$};
\draw[->, blue, style=dashed] (V) -- (-3, 0) node[midway, anchor=east] {$(\mathbf{i} \cdot \hat{\mathbf{n}})\hat{\mathbf{n}}$};
\draw[->, blue, style=dashed] (-3, 0) -- (-3, -2) node[midway, anchor=east] {$(\mathbf{i} \cdot \hat{\mathbf{n}})\hat{\mathbf{n}}$};
\draw[->, style=dashed] (-3, -2) -- (O) node[midway, anchor=north west] {$\mathbf{r}$};
\end{tikzpicture}
\end{document}

0 comments on commit 20ac86a

Please sign in to comment.