4

I want to represent a cross product of two vectors $\vec a,\vec b$. I want to make a right-handed triad. How to draw a screw along $\hat n$ and also how to mark the angle with $\theta$? enter image description here

 \documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[line width=.8pt,x={(1,0)},  z={(-0.5,-0.5)}]
\coordinate (O)  at (0,0,0);
\coordinate (Ay) at (0,3,0);
% Draw the axes
\foreach \c/\l/\p in {{4.5,0,0}/\vec{b}/right, {3,-3,0}/\vec{a}/below left}{
 \draw[->] (O) -- +(\c) node[\p] {$\l$};
}
\draw[->] (O) -- node[pos=0.7,above left] {$\hat{n}$} (Ay);
\end{tikzpicture}
\end{document}

enter image description here

Edit:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,quotes}
\begin{document}

\begin{tikzpicture}
\draw (0,0) coordinate (O) -- (0,2)
 \draw (3,0) coordinate (A) -- (0,0) coordinate (B)
-- (2,-2) coordinate (C)
pic [fill=black!50] {angle = C--B--A}
pic [draw,->,red,thick,angle radius=1cm] {angle = C--B--A};
\end{tikzpicture}
\end{document}

enter image description here

4
  • Nice question. Thanks for code that looks complete. Can you please add a screenshot of its current result? Thank you
    – MS-SPO
    Commented Oct 2, 2023 at 7:18
  • 1
    Current result added Commented Oct 2, 2023 at 7:24
  • 1
    It might be easier to use 3d library in tikz. See section 40 of the pgf manual. It starts on page 564.
    – Celdor
    Commented Oct 2, 2023 at 8:58
  • @Celdor Added code and Fig. Thanks a lot. Now, how to add the spring Commented Oct 2, 2023 at 10:23

2 Answers 2

2

I found a parameterised equation of Helix the Wikipedia. tikz handles three-dimensional graphs out of scratch but I believe extra libraries may simplify process of drawing more complex graphs.

Here's an example of something what you try to achieve. Start from the code below. 3d view let you change orientation of the vectors.

\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary {perspective,arrows.meta}

\begin{document}
\begin{tikzpicture}[
    3d view={135}{30},   % "isometric view" with azimuth=45
    axes/.style = {-Latex,line width=0.5pt,Gray},
    helix/.style = {-{Latex[scale=0.75,sep=-10pt]},line width=2pt,black},
  ]
  % \path (tpp cs:x=4, y=5, z=0) node [font=\Large, below left=-3mm and 5mm] {$\mathcal{S}$};
  \draw[axes] (0,0,0) -- (4,0,0) node [pos=1.1,black] {$\bar{a}$};
  \draw[axes] (0,0,0) -- (0,3,0) node [pos=1.1,black] {$\bar{b}$};
  \draw[axes] (0,0,0) -- (0,0,5) node [pos=1.1,black] {$\bar{a} \times \bar{b}$};
  \draw [helix] (0.35,0,0) \foreach \t [
    evaluate=\t as \x using 0.35*cos(\t),
    evaluate=\t as \y using 0.35*sin(\t),
    evaluate=\t as \z using 0.0015*\t,
  ] in {10,20,...,3000} {-- (\x,\y,\z)};
  \draw [-Latex] (tpp cs:x=2, y=0, z=0) arc (0:90:2) node [pos=0.5,above] {$\phi$};
\end{tikzpicture}
\end{document}

enter image description here

3

enter image description here

My code is long since it is not easy to produce a spring in space with a vector inside it, at least in my opinion. There are many variables and constants (for the vectors a and b, and their cross-product, for the sprig's radius and so on). You can also try to change the point of view...

The code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{math, calc, arrows.meta}

\begin{document}
\tikzset{%
  view/.style 2 args={%  observer longitude and latitude (y upwards)
                      %  Remark. lomg=0 means x=0
    z={({-sin(#1)}, {-cos(#1)*sin(#2)})},
    x={({cos(#1)}, {-sin(#1)*sin(#2)})},
    y={(0, {cos(#2)})},
    evaluate={%
      \tox={sin(#1)*cos(#2)};
      \toy={sin(#2)};
      \toz={cos(#1)*cos(#2)};
    },
    longitude = #1,
    latitude = #2
  }
}
\pgfkeys{/tikz/.cd,
  latitude/.store in=\aLatit,  % observer's latitude
  latitude=0
}
\pgfkeys{/tikz/.cd,
  longitude/.store in=\aLongit,  % observer's longitude
  longitude=0  % corresponds to x=0
}

\tikzset{
  arc from/.style args={#1 towards #2}{%
    insert path={coordinate (tmp) let
      \p1 = (tmp),
      \p2 = (#1),
      \p3 = (#2),
      \n1 = {veclen(\x1-\x2, \y1-\y2)},
      \n2 = {atan2(\y2-\y1, \x2-\x1)},
      \n3 = {atan2(\y3-\y1, \x3-\x1)}
      in (\p2) arc (\n2: \n3 : \n1)
    }
  }
}

\tikzmath{
  real \ax, \ay, \az, \bx, \by, \bz, \cx, \cy, \cz;
  \ax = 2; \ay = -1.5; \az = 1;
  \bx = 1.5; \by = .5; \bz = -.75;
  \cx = \ay*\bz -\az*\by;
  \cy = -\ax*\bz +\az*\bx;
  \cz = \ax*\by -\ay*\bx;
  real \an, \bn, \ux, \uy, \uz, \vx, \vy, \vz, \vn, \uv, \wx, \wy, \wz;
  \an = {sqrt(\ax*\ax +\ay*\ay + \az*\az)};
  \ux = \ax/\an; \uy = \ay/\an; \uz = \az/\an; 
  \bn = {sqrt(\bx*\bx +\by*\by + \bz*\bz)};
  \vx = \bx/\bn; \vy = \by/\bn; \vz = \bz/\bn; 
  \uv = \ux*\vx +\uy*\vy +\uz*\vz;
  \vx = \vx -\uv*\ux;
  \vy = \vy -\uv*\uy;
  \vz = \vz -\uv*\uz;
  \vn = {sqrt(\vx*\vx +\vy*\vy + \vz*\vz)};
  \vx = \vx/\vn; \vy = \vy/\vn; \vz = \vz/\vn;
  \wx = \uy*\vz -\uz*\vy;
  \wy = -\ux*\vz +\uz*\vx;
  \wz = \ux*\vy -\uy*\vx;
  real \r, \wl;
  \r = .2;
  \wl = .5;
  integer \N, \nbPoints;
  \N = 4;
  \nbPoints = 24;
}
\begin{tikzpicture}[view={45}{28}, line width=.8pt, every node/.style={scale=.7}]
  % canonical coordinate system
  \begin{scope}[color=gray!80, line width=.2pt]
    \draw[->] (0, 0, 0) -- (1, 0, 0) node[shift={(.2, .1, 0)}] {$x$};
    \draw[->] (0, 0, 0) -- (0, 1, 0) node[shift={(.2, .2, 0)}] {$y$};
    \draw[->] (0, 0, 0) -- (0, 0, 1) node[shift={(0, .2, .2)}] {$z$};
  \end{scope}

  % the vectors
  \draw[arrows={-Latex}] (0, 0, 0) -- (\ax, \ay, \az)
  node[pos=.7, left] {$\vec{a}$};
  \draw[arrows={-Latex}] (0, 0, 0) -- (\bx, \by, \bz)
  node[pos=.7, above] {$\vec{b}$};
  \draw (0, 0, 0) -- (\cx, \cy, \cz)
  node[pos=.7, above right] {$\vec{a}\times\vec{b}$};

  % Gram Schmidt on the vectors
  \begin{scope}[color=orange!80, line width=.4pt]
    \draw[->] (0, 0, 0) -- (\ux, \uy, \uz) coordinate (U);
    \path (\bx/\bn, \by/\bn, \bz/\bn) coordinate (V);
    \draw[->] (0, 0, 0) -- (\vx, \vy, \vz);
    % \draw[->] (0, 0, 0) -- (\wx, \wy, \wz);
  \end{scope}

  % the arc
  \draw[->, very thin] (0, 0, 0) [arc from=U towards V]; 

  % cross product inside the spring
  \draw[white, opacity=.7, line width=3pt]
  (0, 0, 0) -- (${(\N -1)*\wl}*(\wx, \wy, \wz)$) coordinate (seen);

  % the spring
  \foreach \j [parse=true, evaluate=\j as \s using {(\j -1)/\nbPoints*360},
  evaluate=\j as \t using {\j/\nbPoints*360}]
  in {1, ..., \N*\nbPoints}{%
    \tikzmath{%
      \x1 = \r*cos(\s)*\ux +\r*sin(\s)*\vx +(\j -1)/\nbPoints*\wl*\wx;
      \y1 = \r*cos(\s)*\uy +\r*sin(\s)*\vy +(\j -1)/\nbPoints*\wl*\wy;
      \z1 = \r*cos(\s)*\uz +\r*sin(\s)*\vz +(\j -1)/\nbPoints*\wl*\wz;
      \x2 = \r*cos(\t)*\ux +\r*sin(\t)*\vx +\j/\nbPoints*\wl*\wx;
      \y2 = \r*cos(\t)*\uy +\r*sin(\t)*\vy +\j/\nbPoints*\wl*\wy;
      \z2 = \r*cos(\t)*\uz +\r*sin(\t)*\vz +\j/\nbPoints*\wl*\wz;
    }
    \draw[blue, preaction={draw=white, opacity=.9, line width=2pt}]
    (\x1, \y1, \z1) -- (\x2, \y2, \z2);
  }

  % the cross product over the spring
  \draw[arrows={-Latex}, preaction={draw=white, opacity=.9, line width=2pt}]
  (seen) -- (\cx, \cy, \cz);
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .