根据这里的答案我怎样才能自动纠正这张图片中的点 A 和 B?,我尝试用球体
\documentclass[tikz,border=1mm, 12 pt]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{70}{50}
\begin{tikzpicture}[scale=1,tdplot_main_coords,declare function={R=25*sqrt(78)*(1/52);r=7*sqrt(3)*(1/3);
alpha1(\th,\ph,\b)=\ph-asin(cot(\th)*tan(\b));%
alpha2(\th,\ph,\b)=-180+\ph+asin(cot(\th)*tan(\b));%
beta1(\th,\ph,\a)=90+atan(cot(\th)/sin(\a-\ph));%
beta2(\th,\ph,\a)=270+atan(cot(\th)/sin(\a-\ph));%
}]
\path
coordinate (O) at (0,0,0)
coordinate (A) at (-3/2, {-13*sqrt(3)*(1/6)}, 0)
coordinate (B) at (3/2, {-13*sqrt(3)*(1/6)}, 0)
coordinate (C) at (4, {(1/3)*sqrt(3)}, 0)
coordinate (S) at (0, 0, {(1/3)*sqrt(78)})
coordinate (T) at (0, 0, {-23*sqrt(78)*(1/156)});
\begin{scope}[tdplot_screen_coords, on background layer]
\draw[thick] (T) circle (R);
\end{scope}
\begin{scope}[canvas is xy plane at z={0}]
\draw[dashed] (O) circle (r);
\draw[thick] ({alpha1(\tdplotmaintheta,\tdplotmainphi,{atan(r/R)})}:r) arc({alpha1(\tdplotmaintheta,\tdplotmainphi,{atan(r/R)})}: {alpha2(\tdplotmaintheta,\tdplotmainphi,{atan(r/R)})}:r) ;
\end{scope}
\begin{scope}[on background layer]
\foreach \v/\position in {T/above,O/below,A/below,B/below,C/below,S/right} {
\draw[draw =black, fill=black] (\v) circle (1.2pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\foreach \X in {A,B,C,O} \draw[dashed] (\X) -- (S);
\draw[dashed] (A) -- (B) -- (C) -- cycle;
\end{tikzpicture}
\end{document}
结果不正确。如何使用此方法自动修复?
我用了另外一种方法。
\documentclass[tikz,border=1mm, 12 pt]{standalone}
\usepackage{fouriernc}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{70}{50}
\begin{tikzpicture}[scale=1,tdplot_main_coords,declare function={R=25*sqrt(78)*(1/52);r=7*sqrt(3)*(1/3);}]
\path
coordinate (O) at (0,0,0)
coordinate (A) at (-3/2, {-13*sqrt(3)*(1/6)}, 0)
coordinate (B) at (3/2, {-13*sqrt(3)*(1/6)}, 0)
coordinate (C) at (4, {(1/3)*sqrt(3)}, 0)
coordinate (S) at (0, 0, {(1/3)*sqrt(78)})
coordinate (T) at (0, 0, {-23*sqrt(78)*(1/156)});
\begin{scope}[tdplot_screen_coords, on background layer]
\draw[thick] (T) circle (R);
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw[dashed] (\tdplotmainphi:r) arc(\tdplotmainphi:\tdplotmainphi+180:r);
\draw[thick] (\tdplotmainphi:r) arc(\tdplotmainphi:\tdplotmainphi-180:r)
;
\end{scope}
\foreach \v/\position in {T/above,O/below,A/below,B/below,C/right,S/right} {
\draw[draw =black, fill=black] (\v) circle (1.2pt) node [\position=0.2mm] {$\v$};
}
\foreach \X in {A,B,C,O} \draw[dashed] (\X) -- (S);
\draw[dashed] (A) -- (B) -- (C) -- cycle;
\end{tikzpicture}
\end{document}
答案1
链接的答案很好用,它对你的问题的应用也很好。让我从输出中重构你正在做的事情。你画一个球体,中心在T
,它是不是原点和原点所在xy
平面上的一个圆。圆的纬度是多少?它是不是 atan(r/R)
,而纬度由 给出atan(T_z/r)
,其中T_z
是z
的分量T
。根据惯例,这里我们需要一个减号,这就是为什么 中有一个减号\pgfmathsetmacro{\myel}{-atan(23*sqrt(78)*(1/156)/r)}
。这很可能就是Janis Lazovskis 的评论想告诉我们。如果你在这里问我,这个可以改变。(惯例是这样的,其他答案中不需要减号。)总的来说,在我看来这很好用。
\documentclass[tikz,border=1mm, 12 pt]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{70}{50}
\begin{tikzpicture}[scale=1,tdplot_main_coords,declare function={R=25*sqrt(78)*(1/52);r=7*sqrt(3)*(1/3);
alpha1(\th,\ph,\b)=\ph-asin(cot(\th)*tan(\b));%
alpha2(\th,\ph,\b)=-180+\ph+asin(cot(\th)*tan(\b));%
beta1(\th,\ph,\a)=90+atan(cot(\th)/sin(\a-\ph));%
beta2(\th,\ph,\a)=270+atan(cot(\th)/sin(\a-\ph));%
}]
\path
coordinate (O) at (0,0,0)
coordinate (A) at (-3/2, {-13*sqrt(3)*(1/6)}, 0)
coordinate (B) at (3/2, {-13*sqrt(3)*(1/6)}, 0)
coordinate (C) at (4, {(1/3)*sqrt(3)}, 0)
coordinate (S) at (0, 0, {(1/3)*sqrt(78)})
coordinate (T) at (0, 0, {-23*sqrt(78)*(1/156)});
\begin{scope}[tdplot_screen_coords, on background layer]
\draw[thick] (T) circle (R);
\end{scope}
\begin{scope}[canvas is xy plane at z={0}]
\draw[dashed] (O) circle (r);
\pgfmathsetmacro{\myel}{-atan(23*sqrt(78)*(1/156)/r)}
\typeout{\myel}
\draw[thick] ({alpha1(\tdplotmaintheta,\tdplotmainphi,{\myel})}:r)
arc({alpha1(\tdplotmaintheta,\tdplotmainphi,{\myel})}:
{alpha2(\tdplotmaintheta,\tdplotmainphi,{\myel})}:r) ;
\end{scope}
\begin{scope}[on background layer]
\foreach \v/\position in {T/above,O/below,A/below,B/below,C/below,S/right} {
\draw[draw =black, fill=black] (\v) circle (1.2pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\foreach \X in {A,B,C,O} \draw[dashed] (\X) -- (S);
\draw[dashed] (A) -- (B) -- (C) -- cycle;
\end{tikzpicture}
\end{document}
一个可能更优雅的解决方案是重新定义alpha1
和,alpha2
以便处理减号,并T
使用代码提取的 z 分量。
\documentclass[tikz,border=1mm, 12 pt]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\makeatletter
% retrieves the 3D coordinates
\def\RawCoord(#1){\csname tikz@dcl@coord@#1\endcsname}%
\def\scalprod#1=#2.#3;{%
\edef\coordA{\RawCoord#2}%
\edef\coordB{\RawCoord#3}%
\pgfmathsetmacro\pgfutil@tmpa{scalarproduct({\coordA},{\coordB})}
\edef#1{\pgfutil@tmpa}}%
\makeatother
\newcommand{\spaux}[6]{(#1)*(#4)+(#2)*(#5)+(#3)*(#6)}
\pgfmathdeclarefunction{scalarproduct}{2}{% scalar product of two 3-vectors
\begingroup%
\pgfmathparse{\spaux#1#2}%
\pgfmathsmuggle\pgfmathresult\endgroup}
\begin{document}
\tdplotsetmaincoords{70}{50}
\begin{tikzpicture}[scale=1,tdplot_main_coords,declare function={R=25*sqrt(78)*(1/52);r=7*sqrt(3)*(1/3);
alpha1(\th,\ph,\b)=\ph+asin(cot(\th)*tan(\b));%
alpha2(\th,\ph,\b)=-180+\ph-asin(cot(\th)*tan(\b));%
beta1(\th,\ph,\a)=90+atan(cot(\th)/sin(\a-\ph));%
beta2(\th,\ph,\a)=270+atan(cot(\th)/sin(\a-\ph));%
}]
\path (0,0,0) coordinate (O)
(-3/2, {-13*sqrt(3)*(1/6)}, 0) coordinate (A)
(3/2, {-13*sqrt(3)*(1/6)}, 0) coordinate (B)
(4, {(1/3)*sqrt(3)}, 0) coordinate (C)
(0, 0, {(1/3)*sqrt(78)}) coordinate (S)
(0, 0, {-23*sqrt(78)*(1/156)}) coordinate (T)
(0,0,1) coordinate(Z);
\begin{scope}[tdplot_screen_coords, on background layer]
\draw[thick] (T) circle (R);
\end{scope}
\begin{scope}[canvas is xy plane at z={0}]
\draw[dashed] (O) circle (r);
\scalprod\myz=(T).(Z); % z component of T
\pgfmathsetmacro{\myel}{atan(-1*\myz/r)}
\draw[thick] ({alpha1(\tdplotmaintheta,\tdplotmainphi,{\myel})}:r)
arc({alpha1(\tdplotmaintheta,\tdplotmainphi,{\myel})}:
{alpha2(\tdplotmaintheta,\tdplotmainphi,{\myel})}:r) ;
\end{scope}
\begin{scope}[on background layer]
\foreach \v/\position in {T/above,O/below,A/below,B/below,C/below,S/right} {
\draw[draw =black, fill=black] (\v) circle (1.2pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\foreach \X in {A,B,C,O} \draw[dashed] (\X) -- (S);
\draw[dashed] (A) -- (B) -- (C) -- cycle;
\end{tikzpicture}
\end{document}