我实际上是在为我的学生重写一本数学教科书。我想向他们展示一个基础不一定是正交的。所以我想用两个不同的基础画两个图形。
我找到了第一张图片的一些代码,但我不知道如何更改它以保持相同的想法但使用不同的基础。这是第一张图片的代码:
\tdplotsetmaincoords{60}{120}
\newcommand{\Prho}{1.2}%
\newcommand{\Ptheta}{55}%
\newcommand{\Pphi}{60}%
\begin{tikzpicture}
[scale=5,
tdplot_main_coords,
axis/.style={->,black,thick},
vector/.style={-stealth,black,ultra thick},
vector guide/.style={dashed,lightgray,thick}]
%standard tikz coordinate definition using x, y, z coords
\coordinate (O) at (0,0,0);
%tikz-3dplot coordinate definition using r, theta, phi coords
\tdplotsetcoord{P}{\Prho}{\Ptheta}{\Pphi}
%draw axes
\draw[axis] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[axis] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[axis] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
%draw a vector from O to P
\draw[vector] (O) -- (P);
\draw[vector] (O) -- (0.3,0,0) node[sloped,midway,above=-0.1cm]{$\tiny\overrightarrow{OI}$} ;
\draw[vector] (O) -- (0,0.3,0) node[sloped,midway,above=-0.1cm]{$\tiny\overrightarrow{OJ}$};
\draw[vector] (O) -- (0,0,0.3) node[sloped,midway,above=-0.1cm]{$\tiny\overrightarrow{OK}$};
%draw guide lines to components
\draw[vector guide] (O) -- (Pxy);
\draw[vector guide] (Pxy) -- (P);
% Compute x,y,z
\pgfmathsetmacro{\PxCoord}{\Prho * sin(\Pphi) * cos(\Ptheta)}%
\pgfmathsetmacro{\PyCoord}{\Prho * sin(\Pphi) * sin(\Ptheta)}%
\pgfmathsetmacro{\PzCoord}{\Prho * cos(\Pphi)}%
\draw[vector guide] (Pxy) -- (Px) node [left, black] {$x_a.\overrightarrow{OI}$};
\draw[vector guide] (Pxy) -- (Py) node [above right, black] {$y_a.\overrightarrow{OJ}$};
\draw[vector guide] (Pyz) -- (Pz) node [left, black] {$z_a.\overrightarrow{OK}$};
\draw[vector guide] (Pxz) -- (Pz);
\draw[vector guide] (Px) -- (Pxz);
\draw[vector guide] (Pyz) -- (Py);
\draw[vector guide] (P) -- (Pxz);
\draw[vector guide] (P) -- (Pyz);
\node[inner sep=1pt,circle,draw,fill] at (Py) {};
\node[inner sep=1pt,circle,draw,fill] at (Px) {};
\node[inner sep=1pt,circle,draw,fill] at (Pz) {};
\end{tikzpicture}
答案1
\documentclass[tikz, border= 1cm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{120}
\newcommand{\Prho}{1.2}%
\newcommand{\Ptheta}{55}%
\newcommand{\Pphi}{60}%
\begin{tikzpicture}
[scale=5,
tdplot_main_coords,
axis/.style={->,black,thick},
vector/.style={-stealth,black,ultra thick},
vector guide/.style={dashed,lightgray,thick},
x={(-1.4cm,-0.4cm)}, y={(-0.1cm,-0.3cm)}, z={(0.1cm,1cm)},
]
%standard tikz coordinate definition using x, y, z coords
\coordinate (O) at (0,0,0);
%tikz-3dplot coordinate definition using r, theta, phi coords
\tdplotsetcoord{P}{\Prho}{\Ptheta}{\Pphi}
%draw axes
\draw[axis] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[axis] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[axis] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
%draw a vector from O to P
\draw[vector] (O) -- (P);
\draw[vector] (O) -- (0.3,0,0) node[sloped,midway,above=-0.1cm]{$\tiny\overrightarrow{OI}$} ;
\draw[vector] (O) -- (0,0.3,0) node[sloped,midway,above=-0.1cm]{$\tiny\overrightarrow{OJ}$};
\draw[vector] (O) -- (0,0,0.3) node[sloped,midway,above=-0.1cm]{$\tiny\overrightarrow{OK}$};
%draw guide lines to components
\draw[vector guide] (O) -- (Pxy);
\draw[vector guide] (Pxy) -- (P);
% Compute x,y,z
\pgfmathsetmacro{\PxCoord}{\Prho * sin(\Pphi) * cos(\Ptheta)}%
\pgfmathsetmacro{\PyCoord}{\Prho * sin(\Pphi) * sin(\Ptheta)}%
\pgfmathsetmacro{\PzCoord}{\Prho * cos(\Pphi)}%
\draw[vector guide] (Pxy) -- (Px) node [left, black] {$x_a.\overrightarrow{OI}$};
\draw[vector guide] (Pxy) -- (Py) node [above right, black] {$y_a.\overrightarrow{OJ}$};
\draw[vector guide] (Pyz) -- (Pz) node [left, black] {$z_a.\overrightarrow{OK}$};
\draw[vector guide] (Pxz) -- (Pz);
\draw[vector guide] (Px) -- (Pxz);
\draw[vector guide] (Pyz) -- (Py);
\draw[vector guide] (P) -- (Pxz);
\draw[vector guide] (P) -- (Pyz);
\node[inner sep=1pt,circle,draw,fill] at (Py) {};
\node[inner sep=1pt,circle,draw,fill] at (Px) {};
\node[inner sep=1pt,circle,draw,fill] at (Pz) {};
\end{tikzpicture}\end{document}