![如何用 tikz 创建交叉产品?](https://linux22.com/image/331385/%E5%A6%82%E4%BD%95%E7%94%A8%20tikz%20%E5%88%9B%E5%BB%BA%E4%BA%A4%E5%8F%89%E4%BA%A7%E5%93%81%EF%BC%9F.png)
答案1
这至少是一个起点:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[line width=.7pt,x={(1,0)}, y={(0,1)}, z={(-0.5,-0.5)}]
\coordinate (O) at (0,0,0);
\coordinate (Ax) at (3,0,0);
\coordinate (Ay) at (0,3,0);
\coordinate (Az) at (0,0,3);
\coordinate (A) at (3,3,3);
\coordinate (AO) at (3,0,3);
% Draw axes
\foreach \c/\l/\p in {{4.5,0,0}/x/right, {0,4.5,0}/y/above, {0,0,4.5}/z/below left}{
\draw (O) -- +(\c) node[\p] {$\l$};
}
% Draw vectors
\foreach \c/\l/\p in {Ax/$A_{x}$/above, Ay/$A_{y}$/left, Az/$A_{z}$/above left}{
\draw[->,thick] (O) -- +(\c) node[pos=0.7,\p] {\l};
}
\draw[->] (O) -- node[pos=0.7,above left] {$\vec{A}$} (A);
% Draw helping lines
\draw[help lines,dashed] (Az) -- ++(Ax) -- (Ax) (O) -- (AO) -- (A) -- (Ay);
\end{tikzpicture}
\end{document}
它通过在“纸张空间”中定义单位向量来利用 TikZ 内置的伪 3D 功能。
答案2
在你的绘图上,我看到的只是分解的向量。当你想得到斜基向量的余基时,你需要叉积。
我使用 tikz-3dplot,并创建了宏来获取交叉积。使用它,当两个向量由球面坐标指定时,可以很容易地获取和绘制它们的交叉积
% takes two points as {r}{anglefromz}{anglefromx} and calculates cross product of their location vectors
\newcommand{\tdcrossproduct}[7]{%
%
\tdplotsinandcos{\firstsinthetavec}{\firstcosthetavec}{#2}%
\tdplotsinandcos{\firstsinphivec}{\firstcosphivec}{#3}%
\def\firstx{ #1 * \firstsinthetavec * \firstcosphivec }%
\def\firsty{ #1 * \firstsinthetavec * \firstsinphivec }%
\def\firstz{ #1 * \firstcosthetavec }%
%
\tdplotsinandcos{\secondsinthetavec}{\secondcosthetavec}{#5}%
\tdplotsinandcos{\secondsinphivec}{\secondcosphivec}{#6}%
\def\secondx{ #4 * \secondsinthetavec * \secondcosphivec }%
\def\secondy{ #4 * \secondsinthetavec * \secondsinphivec }%
\def\secondz{ #4 * \secondcosthetavec }%
%
\def\crossz{ \firstx * \secondy - \firsty * \secondx }%
\def\crossx{ \firsty * \secondz - \firstz * \secondy }%
\def\crossy{ \firstz * \secondx - \firstx * \secondz }%
\coordinate (#7) at (\crossx, \crossy, \crossz);%
}
结果如下
完整代码
\documentclass[11pt,twoside]{book}
\usepackage{geometry}
\geometry{papersize={150mm,200mm}}
\geometry{tmargin=1.5cm,bmargin=1.5cm,lmargin=1.5cm,rmargin=1.5cm}
\usepackage{xcolor}
\usepackage{bm}
\usepackage[e]{esvect}
\usepackage{tikz}
\usepackage{tikz-3dplot} % it needs tikz-3dplot.sty in same folder
\usetikzlibrary{calc}
\usetikzlibrary{arrows,arrows.meta}
\usetikzlibrary{decorations.markings,decorations.pathmorphing}
\makeatletter
\newcommand*\dotp{\mathpalette\dotp@{.5}}
\newcommand*\dotp@[2]{\mathbin{\vcenter{\hbox{\scalebox{#2}{$\m@th#1\bullet$}}}}}
\makeatother
\newcommand\dotdotp{\dotp\hspace{-0.16em}\dotp\hspace{0.20em}}
\usepackage{nicefrac}
\pagestyle{empty}
\begin{document}
% takes two points as {r}{anglefromz}{anglefromx} and calculates cross product of their location vectors
\newcommand{\tdcrossproduct}[7]{%
%
\tdplotsinandcos{\firstsinthetavec}{\firstcosthetavec}{#2}%
\tdplotsinandcos{\firstsinphivec}{\firstcosphivec}{#3}%
\def\firstx{ #1 * \firstsinthetavec * \firstcosphivec }%
\def\firsty{ #1 * \firstsinthetavec * \firstsinphivec }%
\def\firstz{ #1 * \firstcosthetavec }%
%
\tdplotsinandcos{\secondsinthetavec}{\secondcosthetavec}{#5}%
\tdplotsinandcos{\secondsinphivec}{\secondcosphivec}{#6}%
\def\secondx{ #4 * \secondsinthetavec * \secondcosphivec }%
\def\secondy{ #4 * \secondsinthetavec * \secondsinphivec }%
\def\secondz{ #4 * \secondcosthetavec }%
%
\def\crossz{ \firstx * \secondy - \firsty * \secondx }%
\def\crossx{ \firsty * \secondz - \firstz * \secondy }%
\def\crossy{ \firstz * \secondx - \firstx * \secondz }%
\coordinate (#7) at (\crossx, \crossy, \crossz);%
}
% calculates dot product of location vectors of two points
\newcommand{\tddotproduct}[7]{%
%
\tdplotsinandcos{\firstsinthetavec}{\firstcosthetavec}{#2}%
\tdplotsinandcos{\firstsinphivec}{\firstcosphivec}{#3}%
\def\firstx{ #1 * \firstsinthetavec * \firstcosphivec }%
\def\firsty{ #1 * \firstsinthetavec * \firstsinphivec }%
\def\firstz{ #1 * \firstcosthetavec }%
%
\tdplotsinandcos{\secondsinthetavec}{\secondcosthetavec}{#5}%
\tdplotsinandcos{\secondsinphivec}{\secondcosphivec}{#6}%
\def\secondx{ #4 * \secondsinthetavec * \secondcosphivec }%
\def\secondy{ #4 * \secondsinthetavec * \secondsinphivec }%
\def\secondz{ #4 * \secondcosthetavec }%
%
\pgfmathsetmacro{#7}{ \firstx * \secondx + \firsty * \secondy + \firstz * \secondz }%
}
% takes three points as {r}{anglefromz}{anglefromx} and calculates triple product r1 × r2 • r3 of their location vectors
% the result is placed into \LastThreeDTripleProduct
\newcommand{\tdtripleproduct}[9]{%
%
\tdplotsinandcos{\firstsinthetavec}{\firstcosthetavec}{#2}%
\tdplotsinandcos{\firstsinphivec}{\firstcosphivec}{#3}%
\def\firstx{ #1 * \firstsinthetavec * \firstcosphivec }%
\def\firsty{ #1 * \firstsinthetavec * \firstsinphivec }%
\def\firstz{ #1 * \firstcosthetavec }%
%
\tdplotsinandcos{\secondsinthetavec}{\secondcosthetavec}{#5}%
\tdplotsinandcos{\secondsinphivec}{\secondcosphivec}{#6}%
\def\secondx{ #4 * \secondsinthetavec * \secondcosphivec }%
\def\secondy{ #4 * \secondsinthetavec * \secondsinphivec }%
\def\secondz{ #4 * \secondcosthetavec }%
%
\tdplotsinandcos{\thirdsinthetavec}{\thirdcosthetavec}{#8}%
\tdplotsinandcos{\thirdsinphivec}{\thirdcosphivec}{#9}%
\def\thirdx{ #7 * \thirdsinthetavec * \thirdcosphivec }%
\def\thirdy{ #7 * \thirdsinthetavec * \thirdsinphivec }%
\def\thirdz{ #7 * \thirdcosthetavec }%
%
\def\crossz{ \firstx * \secondy - \firsty * \secondx }%
\def\crossx{ \firsty * \secondz - \firstz * \secondy }%
\def\crossy{ \firstz * \secondx - \firstx * \secondz }%
%
\def\LastThreeDTripleProduct{ \crossx * \thirdx + \crossy * \thirdy + \crossz * \thirdz }%
}
\begin{center}
\tdplotsetmaincoords{40}{110} % orientation of 3D axes
% vectors of basis
\pgfmathsetmacro{\firstlength}{1}
\pgfmathsetmacro{\firstanglefromz}{90} % first and second are xy plane
\pgfmathsetmacro{\firstanglefromx}{0} % first is just x
\pgfmathsetmacro{\secondlength}{1}
\pgfmathsetmacro{\secondanglefromz}{90} % first and second are xy plane
\pgfmathsetmacro{\secondanglefromx}{66} % but second is not orthogonal to first
\pgfmathsetmacro{\thirdlength}{1}
\pgfmathsetmacro{\thirdanglefromz}{-10}
\pgfmathsetmacro{\thirdanglefromx}{55}
% some vector
\pgfmathsetmacro{\lengthofvector}{3.2}
\pgfmathsetmacro{\vectoranglefromz}{28}
\pgfmathsetmacro{\vectoranglefromx}{55}
\begin{tikzpicture}[scale=3.2, tdplot_main_coords] % tdplot_main_coords style to use 3dplot
\coordinate (O) at (0,0,0);
% define axes
\tdplotsetcoord{A1}{\firstlength}{\firstanglefromz}{\firstanglefromx}
\tdplotsetcoord{A2}{\secondlength}{\secondanglefromz}{\secondanglefromx}
\tdplotsetcoord{A3}{\thirdlength}{\thirdanglefromz}{\thirdanglefromx}
% define vector
\tdplotsetcoord{V}{\lengthofvector}{\vectoranglefromz}{\vectoranglefromx} % {length}{angle from z}{angle from x}
% draw components of vector
\coordinate (ParallelToThird) at ($ (V) - (A3) $);
\coordinate (VcomponentXY) at (intersection of V--ParallelToThird and O--Vxy);
\draw [line width=0.4pt, dotted, color=black] (O) -- (VcomponentXY); % projection on first & second vectors’ plane
\coordinate (ParallelToSecond) at ($ (VcomponentXY) - (A2xy) $);
\coordinate (ParallelToFirst) at ($ (VcomponentXY) - (A1xy) $);
\coordinate (Vcomponent1) at (intersection of VcomponentXY--ParallelToSecond and O--A1);
\coordinate (Vcomponent2) at (intersection of VcomponentXY--ParallelToFirst and O--A2);
\draw [line width=0.4pt, dotted, color=black] (V) -- (VcomponentXY);
\draw [line width=0.4pt, dotted, color=black] (VcomponentXY) -- (Vcomponent1);
\draw [line width=0.4pt, dotted, color=black] (VcomponentXY) -- (Vcomponent2);
% draw parallelepiped
\coordinate (onPlane23) at ($ (Vcomponent2) + (V) - (VcomponentXY) $);
\draw [line width=0.4pt, dotted, color=black] (Vcomponent2) -- (onPlane23);
\draw [line width=0.4pt, dotted, color=black] (V) -- (onPlane23);
\coordinate (onPlane13) at ($ (Vcomponent1) + (V) - (VcomponentXY) $);
\draw [line width=0.4pt, dotted, color=black] (Vcomponent1) -- (onPlane13);
\draw [line width=0.4pt, dotted, color=black] (V) -- (onPlane13);
\coordinate (onAxis3) at ($ (V) - (VcomponentXY) $);
\draw [line width=0.4pt, dotted, color=black] (O) -- (onAxis3);
\draw [line width=0.4pt, dotted, color=black] (onPlane13) -- (onAxis3);
\draw [line width=0.4pt, dotted, color=black] (onPlane23) -- (onAxis3);
\draw [line width=0.4pt, dotted, color=black] (O) -- (onPlane13);
\draw [line width=0.4pt, dotted, color=black] (O) -- (onPlane23);
\draw [color=black, line width=1.6pt, line cap=round, dash pattern=on 0pt off 1.6\pgflinewidth,
-{Stealth[round, length=4mm, width=2.4mm]}]
(O) -- (Vcomponent1)
node[pos=0.52, above, xshift=-1.2em, fill=white, shape=circle, inner sep=1pt] {${v^1 \hspace{-0.1ex} \bm{a}_1}$};
\draw [color=black, line width=1.6pt, line cap=round, dash pattern=on 0pt off 1.6\pgflinewidth,
-{Stealth[round, length=4mm, width=2.4mm]}]
(Vcomponent1) -- (VcomponentXY)
node[pos=0.5, below, xshift=-0.5em, yshift=0.1em, shape=circle, fill=white, inner sep=0pt] {${v^2 \hspace{-0.1ex} \bm{a}_2}$};
\draw [color=black, line width=1.6pt, line cap=round, dash pattern=on 0pt off 1.6\pgflinewidth,
-{Stealth[round, length=4mm, width=2.4mm]}]
(VcomponentXY) -- (V)
node[pos=0.52, above right, xshift=0.5em, shape=circle, fill=white, inner sep=1pt] {${v^3 \hspace{-0.1ex} \bm{a}_3}$};
% square root of Gramian matrix’ determinant is a1 × a2 • a3
\tdtripleproduct%
{\firstlength}{\firstanglefromz}{\firstanglefromx}%
{\secondlength}{\secondanglefromz}{\secondanglefromx}%
{\thirdlength}{\thirdanglefromz}{\thirdanglefromx}
\pgfmathsetmacro{\sqrtDetGramian}{\LastThreeDTripleProduct}
\pgfmathsetmacro{\inverseOfSqrtDetGramian}{1 / \sqrtDetGramian}
\node[fill=white!50, inner sep=0pt, outer sep=4pt] at (0,0,-2.8)
{$\begin{array}{c}\bm{a}_1 \hspace{-0.4ex} \times \hspace{-0.3ex} \bm{a}_2 \dotp \hspace{0.1ex} \bm{a}_3 \hspace{-0.2ex} = \hspace{-0.2ex} \sqrt{\hspace{-0.36ex}\mathstrut{\textsl{g}}} \hspace{0.1ex} = \hspace{-0.2ex} \sqrtDetGramian \\[0.25em]
\displaystyle \nicefrac{\scalebox{0.95}{$1$}}{\hspace{-0.25ex}\sqrt{\hspace{-0.2ex}\scalebox{0.96}{$\mathstrut{\textsl{g}}$}}} \hspace{0.1ex} = \hspace{-0.2ex} \inverseOfSqrtDetGramian\end{array}$};
% calculate and draw vectors of cobasis
\tdcrossproduct{\firstlength}{\firstanglefromz}{\firstanglefromx}%
{\secondlength}{\secondanglefromz}{\secondanglefromx}%
{cross23}
\draw [line width=1.25pt, orange, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (cross23)
node[pos=0.7, above right, outer sep=2pt] {$\bm{a}_1 \hspace{-0.4ex} \times \hspace{-0.3ex} \bm{a}_2$};
\coordinate (coA3) at ($ \inverseOfSqrtDetGramian*(cross23) $);
\draw [line width=0.4pt, red] (O) -- ($ 1.02*(coA3) $);
\draw [line width=1.25pt, red, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (coA3)
node[pos=0.8, above right, outer sep=2pt] {${\bm{a}}^3$};
\tdcrossproduct{\thirdlength}{\thirdanglefromz}{\thirdanglefromx}%
{\firstlength}{\firstanglefromz}{\firstanglefromx}%
{cross31}
\draw [line width=1.25pt, orange, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (cross31)
node[pos=0.7, above, outer sep=4pt] {$\bm{a}_3 \hspace{-0.4ex} \times \hspace{-0.3ex} \bm{a}_1$};
\coordinate (coA2) at ($ \inverseOfSqrtDetGramian*(cross31) $);
\draw [line width=0.4pt, red] (O) -- ($ 1.02*(coA2) $);
\draw [line width=1.25pt, red, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (coA2)
node[pos=0.92, above, shape=circle, fill=white, inner sep=1pt, outer sep=4pt] {${\bm{a}}^2$};
\tdcrossproduct{\secondlength}{\secondanglefromz}{\secondanglefromx}%
{\thirdlength}{\thirdanglefromz}{\thirdanglefromx}%
{cross23}
\draw [line width=1.25pt, orange, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (cross23)
node[pos=0.65, above left, outer sep=-1pt] {$\bm{a}_2 \hspace{-0.4ex} \times \hspace{-0.3ex} \bm{a}_3$};
\coordinate (coA1) at ($ \inverseOfSqrtDetGramian*(cross23) $);
\draw [line width=0.4pt, red] (O) -- ($ 1.02*(coA1) $);
\draw [line width=1.25pt, red, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (coA1)
node[pos=0.96, above, outer sep=5pt] {${\bm{a}}^1$};
% draw axes and vectors of basis
\draw [line width=0.4pt, blue] (O) -- ($ 1.21*(A1) $);
\draw [line width=1.25pt, blue, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (A1)
node[pos=0.9, below right, shape=circle, fill=white, inner sep=1pt, outer sep=5pt] {${\bm{a}}_1$};
\draw [line width=0.4pt, blue] (O) -- ($ 1.88*(A2) $);
\draw [line width=1.25pt, blue, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (A2)
node[pos=0.95, above right, shape=circle, fill=white, inner sep=1pt, outer sep=4pt] {${\bm{a}}_2$};
\draw [line width=0.4pt, blue] (O) -- ($ 1.25*(A3) $);
\draw [line width=1.25pt, blue, -{Latex[round, length=3.6mm, width=2.4mm]}]
(O) -- (A3)
node[pos=0.75, above left, xshift=-0.5em, shape=circle, fill=white, inner sep=1pt, outer sep=5pt] {${\bm{a}}_3$};
% draw vector
\draw [line width=1.6pt, black, -{Stealth[round, length=5mm, width=2.8mm]}]
(O) -- (V)
node[pos=0.75, above, yshift=0.4em, shape=circle, fill=white, inner sep=1pt, outer sep=4pt]
{\scalebox{1.2}[1.2]{${\bm{v}}$}};
\end{tikzpicture}
\end{center}
\end{document}