在 3D 中穿越特定平面

在 3D 中穿越特定平面

我正在(x,y,z)笛卡尔坐标系中创建 tikz 图形。我正在使用 定义某个平面中的对象(我的 WE 中的圆)\tikzset{xyplane/.style={canvas is yx plane at z=#1}}。我注意到它不适用于标记某个点的十字(yz我的 WE 中的十字始终在平面中)。我担心我的技能不足以定义,cross/.style因此它会在特定平面上渲染十字。这可能吗?

梅威瑟:

\documentclass[a4paper,fleqn,leqno]{article}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{arrows.meta,decorations.markings,shapes.misc,3d}
\DeclareMathSizes{12}{12}{6}{12}
\tikzset{cross/.style={cross out,draw=black,minimum size=2*(#1-\pgflinewidth),inner sep=0pt,outer sep=0pt},cross/.default={3pt}}
\tikzset{xyplane/.style={canvas is yx plane at z=#1,very thin}}
\tikzset{xzplane/.style={canvas is zx plane at y=#1,very thin}}
\tikzset{yzplane/.style={canvas is zy plane at x=#1,very thin}}
\begin{document}
\begin{tikzpicture}[cm={-1,-1,1,0,(0,0)},x=3.85mm,z=-1cm]
\def\Sx{0} \def\Sy{0} \def\Sz{2}
\pgfmathsetmacro\Sρ{"sqrt((\Sx)^(2)+(\Sy)^(2)+(\Sz)^(2))"}
\pgfmathsetmacro\Sθ{ifthenelse(\Sx==0&&\Sy==0&&\Sz==0,0,"acos(\Sz/(sqrt((\Sx)^(2)+(\Sy)^(2)+(\Sz)^(2))))")}
\pgfmathsetmacro\SΦ{ifthenelse(\Sx==0&&\Sy==0,0,ifthenelse(\Sy<0,"-acos(\Sx/(sqrt((\Sx)^(2)+(\Sy)^(2))))","acos(\Sx/(sqrt((\Sx)^(2)+(\Sy)^(2))))"))}
\tdplotsetcoord{S}{\Sρ}{\Sθ}{\SΦ}
\draw[xyplane=\Sz,color=black,semithick] (S) circle (2cm) node[cross] {};
\draw[dashdotted,color=black] ($(S)-(0,0,2.5)$) -- ($(S)+(0,0,2.5)$) node[anchor=south,color=black] {$o$};
\end{tikzpicture}
\end{document}

答案1

令人惊讶的是,有一个非常简单的方法可以做到这一点。添加transform shape到您的cross/.style的“X“而不是左边”X“。 (我设置cross/.default={6pt}得更大。)

认为X只不过是连接矩形节点角的线。所以剩下的问题就是对节点应用当前变换.然后它就变得没那么神奇了。

编辑

根据要求,这是一个 MWE

\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{arrows.meta,shapes.misc}

\tikzset{cross/.style={cross out,draw,minimum size=2*(#1-\pgflinewidth),inner sep=0pt,outer sep=0pt},cross/.default={6pt}}
\tikzset{xyplane/.style={canvas is yx plane at z=#1,very thin}}
\tikzset{xzplane/.style={canvas is zx plane at y=#1,very thin}}
\tikzset{yzplane/.style={canvas is zy plane at x=#1,very thin}}
\begin{document}
    \begin{tikzpicture}[cm={-1,-1,1,0,(0,0)},x=3.85mm,z=-1cm]
        \def\Sx{0} \def\Sy{0} \def\Sz{2}
        \pgfmathsetmacro\Sρ{"sqrt((\Sx)^(2)+(\Sy)^(2)+(\Sz)^(2))"}
        \pgfmathsetmacro\Sθ{ifthenelse(\Sx==0&&\Sy==0&&\Sz==0,0,"acos(\Sz/(sqrt((\Sx)^(2)+(\Sy)^(2)+(\Sz)^(2))))")}
        \pgfmathsetmacro\SΦ{ifthenelse(\Sx==0&&\Sy==0,0,ifthenelse(\Sy<0,"-acos(\Sx/(sqrt((\Sx)^(2)+(\Sy)^(2))))","acos(\Sx/(sqrt((\Sx)^(2)+(\Sy)^(2))))"))}
        \tdplotsetcoord{S}{\Sρ}{\Sθ}{\SΦ}
        \draw[xyplane=\Sz,color=black,semithick](S)circle(2cm)node[cross]{};
        \draw[dashdotted,color=black]($(S)-(0,0,2.5)$)--($(S)+(0,0,2.5)$)node[anchor=south,color=black]{$o$};
    \end{tikzpicture}
    \begin{tikzpicture}[cm={-1,-1,1,0,(0,0)},x=3.85mm,z=-1cm]
        \def\Sx{0} \def\Sy{0} \def\Sz{2}
        \pgfmathsetmacro\Sρ{"sqrt((\Sx)^(2)+(\Sy)^(2)+(\Sz)^(2))"}
        \pgfmathsetmacro\Sθ{ifthenelse(\Sx==0&&\Sy==0&&\Sz==0,0,"acos(\Sz/(sqrt((\Sx)^(2)+(\Sy)^(2)+(\Sz)^(2))))")}
        \pgfmathsetmacro\SΦ{ifthenelse(\Sx==0&&\Sy==0,0,ifthenelse(\Sy<0,"-acos(\Sx/(sqrt((\Sx)^(2)+(\Sy)^(2))))","acos(\Sx/(sqrt((\Sx)^(2)+(\Sy)^(2))))"))}
        \tdplotsetcoord{S}{\Sρ}{\Sθ}{\SΦ}
        %\draw[xyplane=\Sz,color=black,semithick](S)circle(2cm)node[cross]{};
        \draw[xyplane=\Sz,color=black,semithick](S)circle(2cm)node[transform shape,cross]{};
        \draw[dashdotted,color=black]($(S)-(0,0,2.5)$)--($(S)+(0,0,2.5)$)node[anchor=south,color=black]{$o$};
    \end{tikzpicture}
\end{document}

相关内容