# Setting camera projection angle in tikz to enhance the depth perception when drawing 3D figures

First please see the following example using MATLAB drawing command

 >>surf(membrane);


We can adjust the camera angle using MATLAB's built-in command camproj, the effects are as follows:

It is like the effect of adjusting the camera angle in Paraview, not just adjust the viewpoint's polar angle and azimuthal angle. This is more like human's visual perception whereas the farther the object is from our viewpoint, the smaller that object appears.

For example, for the following figure:

\documentclass{minimal}
\usepackage{tikz,tikz-3dplot}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}

\begin{document}
\tdplotsetmaincoords{70}{200}
\begin{tikzpicture}[scale = 2.5,thick,tdplot_main_coords]
\coordinate (A1) at (0,0,0);
\coordinate (A2) at (2,0,0);
\coordinate (A3) at (2,2,0);
\coordinate (A4) at (0,2,0);

\coordinate (S) at (0.5,0.5,0);
\coordinate (E) at (0.5,3,1.5);
\coordinate (P) at (1.15,1.15,0);
\fill[fill=blue!20] (A1) -- (A2) -- (A3)  -- (A4) -- cycle;
\draw[black, -latex] (S) -- (E);
\draw[black!80, -latex] (S) -- (P);
\draw[black!50,dashed] (E) -- (P);
\node[above] at (E) {$\mathbf{v}$};
\node[below] at (P) {$\mathrm{Proj}_H\mathbf{v}$};

\draw[red!70] (2,2.3,1.2) node[above]
{Projection using inner product} to [out=-90,in=180] ($0.5*($(E)+(P)$)$);

\draw[red!70] (2.3,2.3,0.4) node[above]
{Hilbert space H} to [out=-90,in=90] ($(A3)+(-0.2,-0.2,0)$);
\end{tikzpicture}

\end{document}


Above is a figure I drew sometime ago for a presentation:

Despite the fact that \tdplotsetmaincoords being used to set the camera viewing angle, the picture still does not look like that it is in a real 3d space. It does not have any depth perspective effect like the first staircase picture in the Wikipedia entry of perspective, the parallelogram above should not appear as a parallelogram to our visual perception.

I looked in the documents of tikz-3dplot, \tdplotsetmaincoords is rather a trick of setting camera angle using coordinate transformation, not a real camera angle setting.

So my question is: Is there any trick or tweaking to set the camera projection in tikz so that the 3d figure looks we are observing it in a real perspective?

-
Maybe this will help getting started: texample.net/tikz/examples/cuboid –  Count Zero Jul 2 '13 at 15:27
@CountZero Thanks, interesting, I should have googled harder. –  Shuhao Cao Jul 2 '13 at 15:28

I always set it to \tdplotsetmaincoords{60}{130}. I feel this gives the best view. Your plot is designed for your coordinate so it looks funny with my settings. Therefore, here is a plot I made with mine.

\documentclass[convert = false]{standalone}
\usepackage{tikz, tikz-3dplot}
\usetikzlibrary{arrows, decorations.markings}
\begin{document}
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[line join = round, line cap = round, >=triangle 45,
tdplot_main_coords]
\coordinate (O) at (0, 0, 0);
\coordinate (Y) at (0, 6, 0);
\coordinate (Z) at (0, 0, 5);
\coordinate (X) at (6, 0, 0);
\coordinate (M1) at (-3, 0, 0);
\coordinate (M2) at (4, 0, 0);
\coordinate (M) at (3, 4, 5);

\draw[-latex] (O) -- (Y) node[right, font = \tiny] {$$y$$};
\draw[-latex] (O) -- (Z) node[above, font = \tiny] {$$z$$};
\draw[dashed] (M1) -- (O);
\draw[-latex] (O) -- (X) node[below, font = \tiny] {$$x$$};

\shadedraw[opacity = .5] (M1) circle (.22cm);
\shadedraw[opacity = .6] (M2) circle (.3cm);
\shadedraw[blue, opacity = .8] (M) circle (.1cm);

\draw[dashed] (M) -- (3, 4, 0);
\draw[dashed] (3, 4, 0) -- (3, 0, 0);
\draw[dashed] (3, 4, 0) -- (0, 4, 0);
\draw[dashed] (M1) -- (-3, -3, 0);
\draw[dashed] (M2) -- (4, -3, 0);
\draw[latex-latex] (4, -2, 0) -- (-3, -2, 0) node[font = \tiny, fill = white,
inner sep = 0cm, pos = .5] {$$r_{12}$$};
\draw[-latex] (M2) -- (M) node[font = \tiny, fill = white,
inner sep = 0cm, pos = .5] {$$\mathbf{r}_2$$};
\draw[-latex] (M1) -- (M) node[font = \tiny, fill = white,
inner sep = 0cm, pos = .5] {$$\mathbf{r}_1$$};
\draw[-latex] (O) -- (M) node[font = \tiny, fill = white,
inner sep = 0cm, pos = .5] {$$\mathbf{r}$$};
\node[right, font = \tiny] at (-3, -.2, -0.6) {$$m_1$$}
node[font = \tiny, fill = white, inner sep = 0cm] at (-3, 1.2, 0.5)
{$$(x_1,0,0)$$};
\node[scale = .75] at (3, 4, 5.25) {$$m$$} node[font = \tiny]
at (3, 5, 5.4) {$$(x,y,z)$$};
\node[right, scale = .75] at (4, 0.35, 0) {$$m_2$$} node[font = \tiny]
at (4.25, 0.15, -0.5) {$$(x_2,0,0)$$};
\end{tikzpicture}

\end{document}


-
I think there is a misunderstanding. That's not what is asked here. –  percusse Jul 13 '13 at 8:38
@percusse he asked at the bottom if there is any trick or tweak to setting it. My tweak is the {60}{130}. So I feel that is answer. –  dustin Jul 13 '13 at 8:41
That's a camera view angle not a projection. The camera projection is specifically asked here. That is the reason why OP's image looks funny in your code. –  percusse Jul 13 '13 at 8:42