2

How I can easily draw the direction cosines using TikZ?enter image description here

  • 1
    Welcome. What have you tried so far? Consider adding a minimal working example (MWE). – hola Aug 4 '14 at 2:38
  • I draw the vector but I don`t know how I can put the angles – alejandro muñoz Aug 4 '14 at 3:03
  • \tdplotsetmaincoords{60}{110} \pgfmathsetmacro{\rvec}{.8} \pgfmathsetmacro{\thetavec}{30} \pgfmathsetmacro{\phivec}{60} \begin{tikzpicture}[scale=5,tdplot_main_coords] \coordinate (O) at (0,0,0); \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$}; \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$}; \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec} \draw[-stealth,color=red] (O) -- (P) node[above right] {$P$}; \end{tikzpicture} – alejandro muñoz Aug 4 '14 at 3:05
  • @alejandromuñoz Have a look at the example in chapter 3.5.1 tdplotdrawarc in the tikz-3dplotdocumentation – Dan H. Aug 4 '14 at 6:45
2

This is a 3D solution via tikz-3dplot. Two inputs are required (1) Euclidean coordinate (\ax,\ay,\az) and (2) its Euclidean 2-norm/distance \r.

The code below basically does the following

  1. Draw coordinate systems
  2. From input, one gets the P point, then extended to V point via external extention skill.
  3. Draw angles from P to 3 axes in the first quadrant, respectively via tdplot-define-points command which requires 3 inputs (the origin, P, and a point in axis) to form a triangular polytope
    and then draw the each arc via tdplot-polytope-arc.

enter image description here

Code

\documentclass[border=10pt,varwidth]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{calc}
\begin{document}

\tikzset{vector/.style={<-,black,thin}
}
%  ---- draw coordinates
\tdplotsetmaincoords{60}{120}
\pgfmathsetmacro{\ax}{0.2}%{0.3}
\pgfmathsetmacro{\ay}{0.3}%{0.3}
\pgfmathsetmacro{\az}{0.6}%{0.5}
\def\r{0.7}               %{0.655} %  2-norm of (x,y,z)
\begin{tikzpicture}[scale=5,tdplot_main_coords]     
\coordinate (O) at (0,0,0);  

\draw[thick,->,orange] 
(0,0,0) -- (1.3,0,0)node[anchor=north east]{$\mathbf{V_x}$};   
\draw[thick,->,orange] (0,0,0) -- (0,1.3,0)node[anchor=north west]{$\mathbf{V_y}$}; 
\draw[thick,->,orange] (0,0,0) -- (0,0,1.3)node[anchor=south]{$\mathbf{V_z}$};

\draw[thick,->,blue] 
(0,0,0) -- (1,0,0)node[above]{$\mathbf{e_x}$}; 
\draw[thick,->,blue]  (0,0,0) -- (0,1,0)node[below]{$\mathbf{e_y}$}; 
\draw[thick,->,blue]  (0,0,0) -- (0,0,1)node[right]{$\mathbf{e_z}$};   
% ---- start from P to draw angles a, b, c
\coordinate [] (P) at (\ax,\ay,\az){}; 
\draw[-stealth,thick] (P) -- ($(P)!-0.3cm!(O)$) coordinate (V)node[above]{$V$};

{     %define 3 points 0,A,B for angle c
\tdplotdefinepoints(0,0,0)(0,0,\r)(\ax,\ay,\az) 
\draw[fill=cyan](0,0,\r) --(0,0,0)--(\tdplotbx,\tdplotby,\tdplotbz);
\tdplotdrawpolytopearc[fill=cyan]{\r}{anchor=south}{$c$}
\tdplotdrawpolytopearc[vector]{\r}{anchor=south}{$c$}     % draw arc arrow
}
{     %define 3 points 0,A,B for angle a
\tdplotdefinepoints(0,0,0)(\r,0,0)(\ax,\ay,\az)
\draw[fill=cyan,opacity=0.8](\r,0,0)--(0,0,0)--(\tdplotbx,\tdplotby,\tdplotbz);
\tdplotdrawpolytopearc[fill=cyan,opacity=0.8]{\r}{anchor=south}{$a$}
\tdplotdrawpolytopearc[vector]{\r}{anchor=south}{$a$}     % draw arc arrow
}
{     % define 3 points 0,A,B for angle b
\tdplotdefinepoints(0,0,0)(0,\r,0)(\ax,\ay,\az) 
\draw[fill=cyan](0,\r,0) --(0,0,0)--(\tdplotbx,\tdplotby,\tdplotbz);
\tdplotdrawpolytopearc[fill=cyan]{\r}{anchor=west}{$b$}
\tdplotdrawpolytopearc[vector]{\r}{anchor=west}{$b$}      % draw arc arrow
}
\end{tikzpicture}
\end{document}
| improve this answer | |
1

A simple 2-D solution:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc,positioning}
\definecolor{corange}{rgb}{0.93, 0.57, 0.13}
\begin{document}
\begin{tikzpicture}[>=latex,scale=0.7,inner sep=2pt]
\path coordinate (o) at (0,0)
coordinate (x) at (220:4)node(X) at($(o)!.9!(x)$)[label=below right:$\textcolor{corange}{V_x}\textcolor{blue}{e_x}$]{}
coordinate (y) at (0:6) node(Y)  at($(o)!.9!(y)$)[label=below:$\textcolor{corange}{V_y}\textcolor{blue}{e_y}$]{}
coordinate (z) at (90:6)node(Z)  at($(o)!.9!(z)$)[label=right:$\textcolor{corange}{V_z}\textcolor{blue}{e_z}$]{}
coordinate (v) at (50:5)node at($(o)!1!(v)$)[label=right:$V$]{};

\draw [fill=green,->]($(o)!.42!(y)$)to (o) to($(o)!0.5!(v)$) to [bend left] node[right]{$b$}($(o)!.42!(y)$);
\draw [fill=green,->]($(o)!.37!(z)$)to (o) to($(o)!0.4!(v)$) to [bend right] node[above]{$c$}($(o)!.37!(z)$);
\draw [fill=green,->]($(o)!.3!(x)$)to (o) to($(o)!0.25!(v)$) to [bend right] node[above left]{$a$}($(o)!.3!(x)$);
\draw  (o) edge [->,corange] (x) edge [->,thick,blue] (X)
           edge [->,corange] (y) edge [->,thick,blue] (Y)
           edge [->,corange] (z) edge [->,thick,blue] (Z)
           edge [->,thick] (v); 
\end{tikzpicture}
\end{document}

The result is like this:

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.