根据这里的问题 知道圆心和半径位于平面上,如何画圆?
当我输入以下行时,我无法得到结果
\draw[blue,thick,circle in plane with normal={{\mynormal} with radius {\RAHK} around (I')}];
我怎样才能得到结果?
\documentclass[border=1mm,tikz,12pt]{standalone}
\usepackage{fouriernc}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,backgrounds,angles}
\usepackage{tkz-euclide,amsmath}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\makeatletter
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
\stepcounter{smuggle}%
\expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
\aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
\smuggleone{#2}%
\ifnum#1>1
\aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
\fi
}
\makeatother
\def\parsecoord(#1,#2,#3)>(#4,#5,#6){%
\def#4{#1}%
\def#5{#2}%
\def#6{#3}%
\smuggle{#4}%
\smuggle{#5}%
\smuggle{#6}%
}
\def\SPTD(#1,#2,#3).(#4,#5,#6){((#1)*(#4)+1*(#2)*(#5)+1*(#3)*(#6))}
\def\VPTD(#1,#2,#3)x(#4,#5,#6){((#2)*(#6)-1*(#3)*(#5),(#3)*(#4)-1*(#1)*(#6),(#1)*(#5)-1*(#2)*(#4))}
\def\VecMinus(#1,#2,#3)-(#4,#5,#6){(#1-1*(#4),#2-1*(#5),#3-1*(#6))}
\def\VecAdd(#1,#2,#3)+(#4,#5,#6){(#1+1*(#4),#2+1*(#5),#3+1*(#6))}
\newcommand{\RotationAnglesForPlaneWithNormal}[5]{%\typeout{N=(#1,#2,#3)}
\foreach \XS in {1,-1}
{\foreach \YS in {1,-1}
{\pgfmathsetmacro{\mybeta}{\XS*acos(#3)}
\pgfmathsetmacro{\myalpha}{\YS*acos(#1/sin(\mybeta))}
\pgfmathsetmacro{\ntest}{abs(cos(\myalpha)*sin(\mybeta)-#1)%
+abs(sin(\myalpha)*sin(\mybeta)-#2)+abs(cos(\mybeta)-#3)}
\ifdim\ntest pt<0.1pt
\xdef#4{\myalpha}
\xdef#5{\mybeta}
\fi
}}
}
\tikzset{circle in plane with normal/.style args={#1 with radius #2 around #3}{
/utils/exec={\edef\temp{\noexpand\parsecoord#1>(\noexpand\myNx,\noexpand\myNy,\noexpand\myNz)}
\temp
\pgfmathsetmacro{\myNx}{\myNx}
\pgfmathsetmacro{\myNy}{\myNy}
\pgfmathsetmacro{\myNz}{\myNz}
\pgfmathsetmacro{\myNormalization}{sqrt(pow(\myNx,2)+pow(\myNy,2)+pow(\myNz,2))}
\pgfmathsetmacro{\myNx}{\myNx/\myNormalization}
\pgfmathsetmacro{\myNy}{\myNy/\myNormalization}
\pgfmathsetmacro{\myNz}{\myNz/\myNormalization}
% compute the rotation angles that transform us in the corresponding plabe
\RotationAnglesForPlaneWithNormal{\myNx}{\myNy}{\myNz}{\tmpalpha}{\tmpbeta}
%\typeout{N=(\myNx,\myNy,\myNz),alpha=\tmpalpha,beta=\tmpbeta,r=#2,#3}
\tdplotsetrotatedcoords{\tmpalpha}{\tmpbeta}{0}},
insert path={[tdplot_rotated_coords,canvas is xy plane at z=0,transform shape]
#3 circle[radius=#2]}
}}
\tikzset{reverseclip/.style={insert path={(current bounding box.south west)rectangle
(current bounding box.north east)} }}
\begin{document}
\tdplotsetmaincoords{70}{90}
\begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
\pgfmathsetmacro\a{5}
\pgfmathsetmacro\R{1/2*\a}
\pgfmathsetmacro\h{\a}
\pgfmathsetmacro\angB{-30}
\def\r{1/2*\a}
\pgfmathsetmacro\RAHK{1/2*sqrt(\h^2*\a^2/(\a^2+\h^2))}
\pgfmathsetmacro\RBHKC{sqrt((4*sin(\angB)*\R*\a^3-4*\h^2*sin(\angB)*\R*\a+4*\R^2*\a^2+4*\R^2*\h^2+\a^4+\a^2*\h^2)/(4*\R^2+4*\a*\R*sin(\angB)+\a^2+4*\h^2))}
\typeout{\RAHK,\RBHKC}
\coordinate (A) at (0,0,0) ;
\coordinate (C) at (0,\a,0);
\coordinate (B) at ({ \R*cos(\angB)}, {\a/2 + \R*sin(\angB)},0);
\coordinate (S) at (0,0,\h);
\coordinate (O) at ($ (A)!0.5!(C) $);
\coordinate (H) at ({4*\h*\h*\R*cos(\angB)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)}, {2*\h*\h*(2*\R*sin(\angB)+\a)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)}, {\h*(4*\R^2+4*\a*\R*sin(\angB)+\a*\a)/(4*\R*\R+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)});
\coordinate (K) at (0, {\h*\h*\a/(\a*\a+\h*\h)}, {\h*\a*\a/(\a*\a+\h*\h)});
\coordinate (I') at ($(K)!0.5!(A) $);
\coordinate (I) at ($(C)!0.5!(H) $);
\foreach \v/\position in { B/below,C/right,A/left,S/above,K/above,H/right,O/below} {\draw[draw =black, fill=black] (\v) circle (1.3pt) node [\position=0.2mm] {$\v$};
}
\draw[thick] (S) -- (A) (S) -- (B) (S) -- (C) (A) -- (B) -- (C) (A) -- (H) -- (K) ;
\draw[dashed] (A) -- (K) (A) --(C) ;
\parsecoord(0,0,0)>(\myAx,\myAy,\myAz)
\parsecoord({4*\h*\h*\R*cos(\angB)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)}, {2*\h*\h*(2*\R*sin(\angB)+\a)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)}, {\h*(4*\R^2+4*\a*\R*sin(\angB)+\a*\a)/(4*\R*\R+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)})>(\myHx,\myHy,\myHz)
\parsecoord(0, {\h*\h*\a/(\a*\a+\h*\h)}, {\h*\a*\a/(\a*\a+\h*\h)})>(\myKx,\myKy,\myKz)
\def\mynormal{\VPTD({\myHx-\myAx},{\myHy-\myAy},{\myHz-\myAz})x({\myKx-\myAx},{\myKy-\myAy},{\myKz-\myAz})}
\edef\temp{\noexpand\parsecoord\mynormal>(\noexpand\myNx,\noexpand\myNy,\noexpand\myNz)}
\draw[blue,thick,circle in plane with normal={{\mynormal} with radius {\RAHK} around (I')}];
\end{tikzpicture}
\end{document}
答案1
问题是由额外的{
和}
你有
\parsecoord({4*\h*\h*\R*cos(\angB)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)}, {2*\h*\h*(2*\R*sin(\angB)+\a)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)}, {\h*(4*\R^2+4*\a*\R*sin(\angB)+\a*\a)/(4*\R*\R+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)})>(\myHx,\myHy,\myHz)
\parsecoord(0, {\h*\h*\a/(\a*\a+\h*\h)}, {\h*\a*\a/(\a*\a+\h*\h)})>(\myKx,\myKy,\myKz)
如果你移除它们,你会得到
\documentclass[border=1mm,tikz,12pt]{standalone}
\usepackage{fouriernc}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds,angles}
\makeatletter
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
\stepcounter{smuggle}%
\expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
\aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
\smuggleone{#2}%
\ifnum#1>1
\aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
\fi
}
\makeatother
\def\parsecoord(#1,#2,#3)>(#4,#5,#6){%
\def#4{#1}%
\def#5{#2}%
\def#6{#3}%
\smuggle{#4}%
\smuggle{#5}%
\smuggle{#6}%
}
\def\SPTD(#1,#2,#3).(#4,#5,#6){((#1)*(#4)+1*(#2)*(#5)+1*(#3)*(#6))}
\def\VPTD(#1,#2,#3)x(#4,#5,#6){((#2)*(#6)-1*(#3)*(#5),(#3)*(#4)-1*(#1)*(#6),(#1)*(#5)-1*(#2)*(#4))}
\def\VecMinus(#1,#2,#3)-(#4,#5,#6){(#1-1*(#4),#2-1*(#5),#3-1*(#6))}
\def\VecAdd(#1,#2,#3)+(#4,#5,#6){(#1+1*(#4),#2+1*(#5),#3+1*(#6))}
\newcommand{\RotationAnglesForPlaneWithNormal}[5]{%\typeout{N=(#1,#2,#3)}
\foreach \XS in {1,-1}
{\foreach \YS in {1,-1}
{\pgfmathsetmacro{\mybeta}{\XS*acos(#3)}
\pgfmathsetmacro{\myalpha}{\YS*acos(#1/sin(\mybeta))}
\pgfmathsetmacro{\ntest}{abs(cos(\myalpha)*sin(\mybeta)-#1)%
+abs(sin(\myalpha)*sin(\mybeta)-#2)+abs(cos(\mybeta)-#3)}
\ifdim\ntest pt<0.1pt
\xdef#4{\myalpha}
\xdef#5{\mybeta}
\fi
}}
}
\tikzset{circle in plane with normal/.style args={#1 with radius #2 around #3}{
/utils/exec={\edef\temp{\noexpand\parsecoord#1>(\noexpand\myNx,\noexpand\myNy,\noexpand\myNz)}
\temp
\pgfmathsetmacro{\myNx}{\myNx}
\pgfmathsetmacro{\myNy}{\myNy}
\pgfmathsetmacro{\myNz}{\myNz}
\pgfmathsetmacro{\myNormalization}{sqrt(pow(\myNx,2)+pow(\myNy,2)+pow(\myNz,2))}
\pgfmathsetmacro{\myNx}{\myNx/\myNormalization}
\pgfmathsetmacro{\myNy}{\myNy/\myNormalization}
\pgfmathsetmacro{\myNz}{\myNz/\myNormalization}
% compute the rotation angles that transform us in the corresponding plabe
\RotationAnglesForPlaneWithNormal{\myNx}{\myNy}{\myNz}{\tmpalpha}{\tmpbeta}
%\typeout{N=(\myNx,\myNy,\myNz),alpha=\tmpalpha,beta=\tmpbeta,r=#2,#3}
\tdplotsetrotatedcoords{\tmpalpha}{\tmpbeta}{0}},
insert path={[tdplot_rotated_coords,canvas is xy plane at z=0,transform shape]
#3 circle[radius=#2]}
}}
\tikzset{reverseclip/.style={insert path={(current bounding box.south west)rectangle
(current bounding box.north east)} }}
\begin{document}
\tdplotsetmaincoords{70}{90}
\begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
\pgfmathsetmacro\a{5}
\pgfmathsetmacro\R{1/2*\a}
\pgfmathsetmacro\h{\a}
\pgfmathsetmacro\angB{-30}
\def\r{1/2*\a}
\pgfmathsetmacro\RAHK{1/2*sqrt(\h^2*\a^2/(\a^2+\h^2))}
\pgfmathsetmacro\RBHKC{sqrt((4*sin(\angB)*\R*\a^3-4*\h^2*sin(\angB)*\R*\a+4*\R^2*\a^2+4*\R^2*\h^2+\a^4+\a^2*\h^2)/(4*\R^2+4*\a*\R*sin(\angB)+\a^2+4*\h^2))}
%\typeout{\RAHK,\RBHKC}
\coordinate (A) at (0,0,0) ;
\coordinate (C) at (0,\a,0);
\coordinate (B) at ({ \R*cos(\angB)}, {\a/2 + \R*sin(\angB)},0);
\coordinate (S) at (0,0,\h);
\coordinate (O) at ($ (A)!0.5!(C) $);
\coordinate (H) at ({4*\h*\h*\R*cos(\angB)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)}, {2*\h*\h*(2*\R*sin(\angB)+\a)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)}, {\h*(4*\R^2+4*\a*\R*sin(\angB)+\a*\a)/(4*\R*\R+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h)});
\coordinate (K) at (0, {\h*\h*\a/(\a*\a+\h*\h)}, {\h*\a*\a/(\a*\a+\h*\h)});
\coordinate (I') at ($(K)!0.5!(A) $);
\coordinate (I) at ($(C)!0.5!(H) $);
\foreach \v/\position in { B/below,C/right,A/left,S/above,K/above,H/right,O/below} {\draw[draw =black, fill=black] (\v) circle (1.3pt) node [\position=0.2mm] {$\v$};
}
\draw[thick] (S) -- (A) (S) -- (B) (S) -- (C) (A) -- (B) -- (C) (A) -- (H) -- (K) ;
\draw[dashed] (A) -- (K) (A) --(C) ;
\parsecoord(0,0,0)>(\myAx,\myAy,\myAz)
\parsecoord(4*\h*\h*\R*cos(\angB)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h), 2*\h*\h*(2*\R*sin(\angB)+\a)/(4*\R^2+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h), \h*(4*\R^2+4*\a*\R*sin(\angB)+\a*\a)/(4*\R*\R+4*\a*\R*sin(\angB)+\a*\a+4*\h*\h))>(\myHx,\myHy,\myHz)
\parsecoord(0, \h*\h*\a/(\a*\a+\h*\h), \h*\a*\a/(\a*\a+\h*\h))>(\myKx,\myKy,\myKz)
\def\mynormal{\VPTD({\myHx-\myAx},{\myHy-\myAy},{\myHz-\myAz})x({\myKx-\myAx},{\myKy-\myAy},{\myKz-\myAz})}
\draw[blue,thick,circle in plane with normal={{\mynormal} with radius {\RAHK} around (I')}];
\end{tikzpicture}
\end{document}