[Tex/LaTex] Adding planes and lines to a 3D plot using tikz


I currently have the following code and result.



% Draw a 3D coordinate system

\begin{tikzpicture}[x  = {(1cm,0cm)},
                    y  = {(0.4cm,0.6cm)},
                    z  = {(0cm,1cm)},
                    scale = 1,
                    color = {black}]

\begin{scope}[canvas is xy plane at z=0]
  % x-axis
  \draw[black,->] (0,0) -- (5,0) node (x-axis) [right] {$x$};
  \draw[dashed, ->] (-5,0) -- (0,0);
  % y-axis
  \draw[dashed, black,->] (0,0) -- (0,5) node (y-axis) [above] {$y$};
  \draw[black,->] (0,-5) -- (0,0);


\begin{scope}[canvas is yz plane at x=0]
  % z-axis
  \draw[black,->] (0,0) -- (0,5) node (z-axis) [above] {$z$};
  \draw[dashed,black,->] (0,-5) -- (0,0);


enter image description here

I would like to add the plane z=1 to this image, as well as a line passing through the origin. Can someone explain how to do this? I'm very new to tikz and have been trying to extrapolate information that I've read on other posts, but can't seem to figure out how to achieve what I'm looking for. My ultimate goal is to achieve images resembling the ones found in this Crypto SE post.

Best Answer

Here is an example for a single line.

\coordinate (O) at (0,0,0);
\fill[blue!50,opacity=0.5] (-3,0.5,1) -- (3,0.5,1) -- (3,3,1) -- (-3,3,1) -- cycle;
\draw[thick,red] (-1.25,-0.75,-1.25) -- (2.5,1.5,2.5);
\fill[blue!50,opacity=0.5] (-3,0.5,1) -- (3,0.5,1) -- (3,-3,1) -- (-3,-3,1) -- cycle;
    \draw[->] (O) --++ (3,0,0) node[below] {$x$};
    \draw[->] (O) --++ (0,3,0) node[below] {$y$};
    \draw[->] (O) --++ (0,0,3) node[right] {$z$};

enter image description here

This works because I draw the plane in two portions such that only the relevant part of the line gets "hidden". However, as soon as there a several lines, this approach will become very cumbersome. One can still cook up something but the cleaner way would be to switch to asymptote.