diff --git a/README.md b/README.md index 613b1ff..6acbaca 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/makefile b/makefile index 7a7677e..3d6cedb 100644 --- a/makefile +++ b/makefile @@ -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)) @@ -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: diff --git a/reflection_box.png b/reflection_box.png new file mode 100644 index 0000000..ec258d1 Binary files /dev/null and b/reflection_box.png differ diff --git a/reflection_boxgradient.png b/reflection_boxgradient.png new file mode 100644 index 0000000..44c5b1d Binary files /dev/null and b/reflection_boxgradient.png differ diff --git a/reflection_boxscene.png b/reflection_boxscene.png new file mode 100644 index 0000000..7779221 Binary files /dev/null and b/reflection_boxscene.png differ diff --git a/reflection_concavemirror.png b/reflection_concavemirror.png new file mode 100644 index 0000000..284398f Binary files /dev/null and b/reflection_concavemirror.png differ diff --git a/vector_reflect.png b/vector_reflect.png new file mode 100644 index 0000000..11fa205 Binary files /dev/null and b/vector_reflect.png differ diff --git a/vector_reflect.tex b/vector_reflect.tex new file mode 100644 index 0000000..01a4027 --- /dev/null +++ b/vector_reflect.tex @@ -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}