Drawing a curve (not necessarily an arc) in tikz-3dplot

I'm trying to draw a curve in tikz-3dplot that isn't the arc of a circle. I would like for it to specified by control points, similar to how tikz has (0,0) to [controls=+(45:1) and +(135:1)] (1,0). I know I can draw an arc of a circle, with \tdplotdrawpolytopearc, but I couldn't find anything in the documentation about how to draw any other type of curve. If I use the same syntax as for 2D curves, it seems a default plane is chosen in which the control points act (seems like the xy-plane). Maybe there's a way to choose that plane (and change it for every point)?

Here's a MWE and output for what I have:

\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{75}{130}
\begin{tikzpicture}[tdplot_main_coords]
% Shape and boundary
\draw[blue] (0,0,0)--(-1,1,0);
\fill[green,fill opacity=.8] (0,0,0)--(0,1,0)--(-1,1,0)--(-1,1,1)--(0,0,1);
\draw[blue] (0,0,0)--(0,1,0)--(-1,1,0)--(-1,1,1)--(0,1,1)--(0,0,1)--(0,0,0);
\draw[blue] (0,0,1)--(-1,1,1) (0,1,0)--(0,1,1);
% Natural guess how to draw curve
\draw[red] (0,0,0) to [controls=+(45:1) and +(135:1)] (0,1,0);
% Closest documented way how to draw curve
\tdplotdefinepoints(0,.5,-.3)(0,-.5,.3)(0,1.5,.3)
\tdplotdrawpolytopearc{.583}{}{}
\end{tikzpicture}
\end{document}


I would like to draw a curve on the "face" of this prism that's facing left, like the black curve, but with more "strength" at the end points (like a sine curve). The failed attempt is the red curve that seems to be in the plane of the "bottom" face of the prism.

So, my question is: How can I draw a curve in 3D that is not the arc of a circle?

It is true that the manual of tikz-3dplot is not too explicit on this. However, IMHO the main feature of tikz-3dplot is to install an orthonormal projection of a 3d coordinate system. Apart from that, you can use the standard TikZ commands.

In particular, you can use parametric plots to draw anything you want.

\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{75}{130}
\begin{tikzpicture}[tdplot_main_coords]
% Shape and boundary
\draw[blue] (0,0,0)--(-1,1,0);
\fill[green,fill opacity=.8] (0,0,0)--(0,1,0)--(-1,1,0)--(-1,1,1)--(0,0,1);
\draw[blue] (0,0,0)--(0,1,0)--(-1,1,0)--(-1,1,1)--(0,1,1)--(0,0,1)--(0,0,0);
\draw[blue] (0,0,1)--(-1,1,1) (0,1,0)--(0,1,1);
\draw plot[variable=\x,domain=0:1] (0,\x,{0.3*sin(\x*180)});
\end{tikzpicture}
\end{document}


However, in your example you seem to be looking for a way of drawing an ordinary curve on one of the faces. To this end, you only need to use the 3d library and to draw the curve in the plane that coincides with the corresponding face.

\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{3d}
\begin{document}
\tdplotsetmaincoords{75}{130}
\begin{tikzpicture}[tdplot_main_coords]
% Shape and boundary
\draw[blue] (0,0,0)--(-1,1,0);
\fill[green,fill opacity=.8] (0,0,0)--(0,1,0)--(-1,1,0)--(-1,1,1)--(0,0,1);
\draw[blue] (0,0,0)--(0,1,0)--(-1,1,0)--(-1,1,1)--(0,1,1)--(0,0,1)--(0,0,0);
\draw[blue] (0,0,1)--(-1,1,1) (0,1,0)--(0,1,1);
\begin{scope}[canvas is yz plane at x=0]
\draw[red] (0,0) to [controls=+(45:1) and +(135:1)] (1,0);
\end{scope}
%\draw plot[variable=\x,domain=0:1] (0,\x,{0.3*sin(\x*180)});
\end{tikzpicture}
\end{document}


These projections work not only with TikZ commands but even with external graphics.

\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{3d}
\begin{document}
\tdplotsetmaincoords{75}{130}
\begin{tikzpicture}[tdplot_main_coords]
% Shape and boundary
\draw[blue] (0,0,0)--(-1,1,0);
\fill[green,fill opacity=.8] (0,0,0)--(0,1,0)--(-1,1,0)--(-1,1,1)--(0,0,1);
\draw[blue] (0,0,0)--(0,1,0)--(-1,1,0)--(-1,1,1)--(0,1,1)--(0,0,1)--(0,0,0);
\draw[blue] (0,0,1)--(-1,1,1) (0,1,0)--(0,1,1);
\begin{scope}[canvas is xz plane at y=1,transform shape]
\node at (-0.5,0.5) {\includegraphics[width=0.9cm]{example-image-duck}};
\end{scope}
%\draw plot[variable=\x,domain=0:1] (0,\x,{0.3*sin(\x*180)});
\end{tikzpicture}
\end{document}


• Great, thank you! This definitely solves my current problem. But I notice the most general answer (the second one) specifies a particular plane - is it possible to draw a curve that is not completely within any one plane (if I don't know its parametric formula)? – Jānis Lazovskis Feb 27 at 1:50
• @JānisLazovskis In principle you can do that. However, all the familiar curves use two-dimensional concepts such as in=angle,out=angle, bend=angle and so on. In 3d you would need more information to define analogous constructions. It can certainly be done but the question is whether users will be comfortable with them. bend left=alpha would have to be replaced by bend in first orthogonal direction by alpha and in the orthogonal direction by beta. My take is that "guessing" a parametrization for the curve is more efficient. – user121799 Feb 27 at 1:59
• @JānisLazovskis However, if you have a set of points in 3d, you can definitely run smooth curve through them with \draw plot[smooth] coordinate {(first) (second) ...};, or possibly with the hobby library. – user121799 Feb 27 at 2:01