绘制三维角度

绘制三维角度

我正在使用以下代码生成圆锥摆的草图。

\usetikzlibrary{angles, quotes}

\pgfdeclarelayer{foreground}
\pgfsetlayers{main,foreground}

\tdplotsetmaincoords{80}{10}
\begin{tikzpicture}[tdplot_main_coords,scale=3.14]
\coordinate (O) at (0,0,0);
\coordinate (A) at ({cos(deg(-45))},{sin(deg(-45))},0);
\coordinate (B) at (0,0,2);

% Body and top
\begin{pgfonlayer}{foreground}
    \draw[fill] (A) circle (1.5pt);
    \draw[fill=gray] (B) circle (0.5pt);
    \draw[->] (B)+(-240:0.25) arc (-240:80:0.25);
\end{pgfonlayer}

% circular path
\draw[dashed] plot[variable=\t, samples=100] ( {cos(deg(\t))}, {sin(deg(\t))}, 0);

% rope
\tikzstyle{rope}=[brown!20!black,double=brown!70!black,double distance=0.5,line width=0.3] %very thick
\draw[rope] (A)--(B) node[midway, right]{$\ell$};

% sketches
\draw (A)--(O) node[midway, xshift=-5, yshift=-3]{$r$};
\draw (O)--(B) node[midway,left]{$h$};
\pic[scale=3][draw, "$\theta$", angle eccentricity=1.15] {angle = O--B--A};

\end{tikzpicture}

结果如下:

在此处输入图片描述

尽管使用了 3d 图,但 theta 角是屏幕平面 2d 角。如何将其定位为 3d 角?此外,如何添加 90 度角 AOB 的草图?我发现只有这个例子但我发现它令人困惑的地方多于实用性。

答案1

我会直接画圆弧。首先你需要获得它,但如果你了解r和,这很容易l。最后,要绘制它,你只需更改画布即可。

像这样:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\pgfdeclarelayer{foreground}
\pgfsetlayers{main,foreground}

\tdplotsetmaincoords{80}{10}

\begin{document}
\begin{tikzpicture}[tdplot_main_coords,scale=3.14]
% dimensions and coordinates
\def\a{-58} % angle for A point
\def\r{1} 
\def\h{2}
\pgfmathsetmacro\t{atan(\r/\h)} % theta angle
\coordinate (O) at (0,0,0);
\coordinate (A) at ({\r*cos(\a)},{\r*sin(\a)},0);
\coordinate (B) at (0,0,\h);
% Body and top
\begin{pgfonlayer}{foreground}
    \draw[fill] (A) circle (1.5pt);
    \draw[fill=gray] (B) circle (0.5pt);
    \draw[->] (B)+(-240:0.25) arc (-240:80:0.25);
\end{pgfonlayer}
% circular path
\draw[dashed] (0,0,0) circle (1);
% angle
\def\ar{0.5} % angle radius
%\draw[rotate around z=\a,canvas is xz plane at y=0,red] (B) circle (\ar); % <-- uncomment this if you want
\draw[rotate around z=\a,canvas is xz plane at y=0]
    (B) + (0,-\ar) arc (-90:-90+\t:\ar) node [midway,below] {$\theta$};
% rope
\tikzstyle{rope}=[brown!20!black,double=brown!70!black,double distance=0.5,line width=0.3] %very thick
\draw[rope] (A)--(B) node[midway, right]{$\ell$};
% sketches
\draw (A)--(O) node[midway, xshift=-5, yshift=-3]{$r$};
\draw (O)--(B) node[midway,left]{$h$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

PS:我对您的代码做了一些更改:

  1. 我添加了几个参数。这样很容易进行更改。
  2. 不需要转换为,deg因为三角函数(在 pgf 中)以度为单位。
  3. 底圆可以直接画成圆形。
  4. 如果您最后绘制前景层中的内容(无论如何我都会保留它们),则不需要图层。

相关内容