2

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:

enter image description here

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.

BowPark
  • 1,213
  • 2
    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
  • 1
    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.) –  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. –  Apr 24 '18 at 14:37
  • @marmot what interpretation you can give to ($(c)!1.4cm!90:(a)$) in 3d ? This was the starting point of my comment. I think that the problem is not what package is used but what is the @BowPark's understanding of how the things work in 3d. – Kpym Apr 24 '18 at 15:02
  • Hello Kpym The interpretation is clear, I think, if you are working in a specific 2D plane. Do you agree? I think that the missing piece is in @Bowpark's code is the specification of that plane, that's why I am pushing for tikz-3dplot, but right now I try to see if there is more elegant way. tikz-3dplot is unfortunate because it uses the Euler angles and that's why IMHO it is somewhat hard to guess the relevant transformations. (BTW, how do you manage to address comments to two users?) –  Apr 24 '18 at 15:09
  • @marmot @Kpym As far as I understood, the syntax ($(c)!1.4cm!90:(a)$) can not handle a 3D environment and it would work only when a plane is specified. By default, it is the (x,y) plane. Here it is a different one. Whatever is the solution, with TikZ or with tikz-3dplot, it is welcome. (Sidenote: @marmot I think that you can just type the names preceeded by the @ symbol to address a comment to multiple users, even if automatic completion would work only for the first one). – BowPark Apr 24 '18 at 15:30
  • @BowPark The problem is that tikz-3dplot is very insisting on having the z-axis point up while in your examples the y-axis points up. Even though it is possible to cure this, the resulting code is not really what one may call elegant. That's why I'd like to know if you would be fine with the z-axis pointing up. (BTW, in my browser it is not possible to address two users, it just would not let me submit the comment.) –  Apr 24 '18 at 15:36
  • We all agree that ($(c)!1.4cm!90:(a)$) make sens only in 2d (that could be an oriented sub-plane in a 3d). For me in all the recent questions of @BowPark it is not clear what he wants to do : every time he gives a code by saying that is is not working, but we should guess what he wants. @BowPark I think that you should write your questions following the lines "I have this data ... I want to obtain this ... I have tried that M(N)WE". – Kpym Apr 24 '18 at 15:42
  • @marmot here is how the @-adressing works. In general you can't address two users, but if one of them is the main author, I think you can. – Kpym Apr 24 '18 at 15:47
  • @Kpym Thanks! So you are using backticks then? –  Apr 24 '18 at 15:50
  • @marmot no, I mentioned as second @ the author of the post, that is in any case notified (and so it is allowed). – Kpym Apr 24 '18 at 15:55
  • @Kpym I edited the question with (hopefully) the asked details. Read the question in a reverse order: "I have tried that... I have this data... I want to obtain this". – BowPark Apr 24 '18 at 17:59
  • If your first vector is (3.1,0,1.2), the orthogonal direction in the plane (x,z) to it is generated by (-1.2,0,3.1). And so your second vector should be a multiple of this direction. The third vector should be proportional to the vector product of the first two : in your case to (0,1,0). So you can use this 3 vectors to draw what you want : you don't need some complex calculations. – Kpym Apr 24 '18 at 20:16
  • @Kpym This is true, based upon linear algebra considerations, but it is related to a specific value of point a. As written in the question, vector b (and so point a) "is in the (x,z) plane in a general position" (this is particularly about the computation of vector c; vector d will always be of the type (0,value,0), being always orthogonal to the (x,z) plane). The code should allow to change the a point keeping the vector structure, without new computations. – BowPark Apr 26 '18 at 10:35
  • 1
    @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

1 Answers1

1

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}

enter image description here

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
  • 1
    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. –  Apr 24 '18 at 18:15