TikZ-PGF – How to Create a 3-D Plane with Normal Line on it with TikZ

tikz-pgf

I want to create this with TikZ, it is from Linear Algebra.Are there any examples where I can learn from?

normalonplane

Best Answer

A (more or less) customizable solution, using TikZ perspective and calc libraries. The first one fixes the 3d view, and the second is helpful to place some coordinates.

My code:

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{calc,perspective}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,
                    3d view={120}{25},
                    scale=2]
% dimensions
\def\xx{2}   % interxection plane -- OX, >0
\def\yy{3}   % interxection plane -- OY, >0
\def\zz{3}   % interxection plane -- OZ, >0
\def\nl{2.5} % normal vector length
\def\px{0.2} % P,  coordinate x
\def\py{0.8} % P,  coordinate y
\def\qx{0.4} % P0, coordinate x
\def\qy{1.6} % P0, coordinate y
\pgfmathsetmacro\pz{\zz*(1-\px/\xx-\py/\yy)} % P,  coordinate z
\pgfmathsetmacro\qz{\zz*(1-\qx/\xx-\qy/\yy)} % P0, coordinate z
% coordinates
\coordinate (O)  at (0,0,0);
\coordinate (A)  at (\xx,0,0);
\coordinate (B)  at (0,\yy,0);
\coordinate (C)  at (0,0,\zz);
\coordinate (P)  at (\px,\py,\pz);
\coordinate (P0) at (\qx,\qy,\qz);
\coordinate (N0) at ($(P0)+(1/\xx,1/\yy,1/\zz)$); % normal vector (end point)
\coordinate (N)  at ($(P0)!\nl cm!(N0)$);         % normal vector (end point),
% axes                                              with the desired length
\foreach\i/\j in {A/x,B/y,C/z}
{
  \draw[dashed] (O)  -- (\i);
  \draw[-latex] (\i) -- ($(\i)!-1cm!(O)$);
  \node      at ($(\i)!-1.2cm!(O)$) {$\j$};
}
% showing that the points are in the plane (not in the original picture)
\draw[gray] (\px,\py,0) -- (P);
\draw[gray] (\px,0,\pz) -- (P);
\draw[gray] (0,\py,\pz) -- (P);
\draw[gray] (\qx,\qy,0) -- (P0);
\draw[gray] (\qx,0,\qz) -- (P0);
\draw[gray] (0,\qy,\qz) -- (P0);
% plane
\draw[green!50!black,thick,fill=green,fill opacity=0.4] (A) -- (B) -- (C) -- cycle;
% points
\fill (P)  circle (1pt) node[above] {$P(x,y,z)$};
\fill (P0) circle (1pt) node[right] {$P_0(x_0,y_0,z_0)$};
\fill (N)  circle (1pt) node[above] {$(a,b,c)$};
% vectors
\draw[very thick,latex-latex,teal!70!blue]
  (P) -- (P0) -- (N) node [black,midway,below right] {$\mathbf{n}$};
% right angle
\coordinate (AUX) at ($($(P0)!0.5cm!(P)$)!0.5!($(P0)!0.5cm!(N)$)$); % right angle vertex
\draw[red] ($(P0)!0.25cm!(P)$) -- (AUX) -- ($(P0)!0.25cm!(N)$);
\end{tikzpicture}
\end{document}

enter image description here enter image description here

Related Question