# TikZ, use calc library in 3D space

The TikZ library calc can handle angle values:

\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,intersections}

\begin{document}

\begin{tikzpicture}

\draw[->] (-3,0,0) -- (3,0,0) node[below right] {$x$};
\draw[->] (0,-3,0) -- (0,3,0) node[above right] {$y$};
\draw[->] (0,0,-3) -- (0,0,3) node[below right] {$z$};

\coordinate (o) at (0,0,0);
\coordinate (a) at (3.1,0,1.2);

\draw[dashed] (a) -- (o);

\path (a) -- coordinate[pos=0.32] (b) (o);

\draw [thick,-{Straight Barb},orange] (a) -- ($(a)!1.2cm!90:(o)$) coordinate[label={[black]above left:c}] (c);

\draw[thick,-{Straight Barb},gray] (a) -- node[pos=0.7, below=0.35em] {b} (b);
\draw [thick,-{Straight Barb},red] (a) -- ([shift={(0,1.5,0)}]a) coordinate[label={[black]above right:d}] (d);

\draw (d) -- ($(c)!1.4cm!90:(a)$) coordinate (h);

\end{tikzpicture}

\end{document}


The output is:

Giving the angle in ($(c)!1.4cm!90:(a)$) any positive or negative value, h will always be in the (x,z) plane. In this case, the segment c--h should instead be vertical (parallel to y) with respect to the (x,z) plane. So, how can the expression ($(c)!1.4cm!90:(a)$) be modified in order to accomplish this?

As noticed in the comments, the above code does not use tikz-3dplot. If, however, this package can provide a solution besides the traditional TikZ-only approach, it is ok and it can be used here.

## The requested elucidation

This question is part of a series (1st question, 2nd question, 3rd question, 4th question, 5th question).

It is asked to depict a triad of mutually orthogonal vectors. One of them (b, in the image above) is in the (x,z) plane in a general position and points to the origin; the plane generated by the vectors c and d should be highlighted. This triad should be depicted in a 3D space, and I should be able to arbitrarily rotate the space orientation. The end configuration of the axes should be the one shown in this answer, with the z axis pointing right.

The tool through which this can be obtained is not important: it can be TikZ, as well as tikz-3dplot, as well as a combination of them. Whether tikz-3dplot must be used or not is part of the question: it can sometimes be the only tool, it can sometimes be just an alternative. So far, I don't know tikz-3dplot enough.

All this summary wasn't written at the beginning because it was difficult, if not impossible, for me to work and make all the attempts on this picture directly. I was not able to provide any example or failed attempts regarding the general picture. The question would have certainly disapproved and criticized (as it was the 1st question).

The 2nd question was actually ambiguous, because I didn't notice the 45° line. Given that, I always tried to provide quick and precise questions, after making some attempts.

Thanks to all those who try to work on these images. I hope that this meets as much as possible the clarification that has been asked in the comments.

• If (c) and (a) were points in a 3d space there would not be such point as ($(c)!1.4cm!90:(a)$) because in 3d there is no sens to say "rotate around (c) at 90° in the positive direction". If you want a point to be 1.4cm above (c) you can use ([yshift=1.4cm]c). A point with "coordinate" (x,y,z) is a 2d point that is a (non orthogonal) projection of this 3d point. – Kpym Apr 24 '18 at 12:33
• You are tagging this question tikz-3dplot, but not using it. With this package, you can work in any plane, and then statement "rotate around (c) by 90° in the positive direction" does make sense. (Note that I never used this calc syntax in tikz-3dplot my self, so I am not 100% sure that this is a good advice. The command \draw (a) rectangle (b); does not yield a rotated rectangle.) – marmot Apr 24 '18 at 13:40
• @marmot No, whatever 3d package you use "rotate around (c) by 90° in the positive direction" make no sens. You can rotate around an oriented axis, but not around a point in 3d. – Kpym Apr 24 '18 at 14:25
• @Kpym Hmmh, I guess that is debatable, depending on whether you interpret (c) as vector/axis or point. In the latter case, you are right, but not on the former. – marmot Apr 24 '18 at 14:37
• @BowPark if you stock the coordinates of (a) in two macros \x and \z then the coordinates of (c) would be (a multiple of) (-\z‚0‚\x). – Kpym Apr 26 '18 at 10:57

Not a real answer, but perhaps the first step. If you load the library 3d, you can specify the plane in which you want to work. Here is an example.

\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,intersections,3d}

\begin{document}

\begin{tikzpicture}

\draw[->] (-3,0,0) -- (3,0,0) node[below right] {$x$};
\draw[->] (0,-3,0) -- (0,3,0) node[above right] {$y$};
\draw[->] (0,0,-3) -- (0,0,3) node[below right] {$z$};

\coordinate (o) at (0,0,0);
\coordinate (a) at (3.1,0,1.2);

\draw[dashed] (a) -- (o);

\path (a) -- coordinate[pos=0.32] (b) (o);

\draw [thick,-{Straight Barb},orange] (a) -- ($(a)!1.2cm!90:(o)$) coordinate[label={[black]above left:c}] (c);

\draw[thick,-{Straight Barb},gray] (a) -- node[pos=0.7, below=0.35em] {b} (b);
\draw [thick,-{Straight Barb},red] (a) -- ([shift={(0,1.5,0)}]a) coordinate[label={[black]above right:d}] (d);
\begin{scope}[canvas is yz plane at x=1]
\draw (d) -- ($(c)!1.4cm!90:(a)$) coordinate (h);
\end{scope}
\end{tikzpicture}
\end{document}


As you see, the syntax is rather self-explanatory. I am however struggling to understand what you precisely want since, as pointed out by @Kpym, your instructions are somewhat ambiguous. Yet I do hope that this example will help you achieve what you want.

Notice also that I spent some time translating your code to tikz-3dplot, but did not find an elegant way to do that. Obstacles include the fact that tikz-3dplot doesn't make it too straightforward to make the y-axis point up, it is using Euler angles, which makes it hard to do a rotation about the x-axis, and that there is a reflection required to make the axes match. These are not conceptual problems, but I was not able to produce something elegant either.

• Thank you! There's one thing I don't understand: is \draw (d) -- ($(c)!1.4cm!90:(a)$) coordinate (h); drawing in the (y,z) plane? If yes, this is in general not the plane of the vectors c and d. Thank you also for having tried with tikz-3dplot. I edited the question to add the requested details. In the final result, the z axis should point right and the x axis up, so maybe even this orientation is troublesome. If you think the code is too intricated, tikz-3dplot is not indispensable. – BowPark Apr 24 '18 at 18:09
• You are right, and that's why I said that this is not a full answer. One would have to carefully adjust the plane in such a way that the respective points are in. I think one may use these gorgeous macros to achieve this, or, if that's not the case, write something that does it. And I have mixed feelings about tikz-3dplot. On the one hand, I really love this package and use it a lot, but it has also some limitations starting with the fact that in the main coordinate system the z-axis always points up. – marmot Apr 24 '18 at 18:15