如何将文本投影到平面上?

如何将文本投影到平面上?

我想给人一种印象,即下面示例中的文字“切片”写在立方体切片上。最好的解决方案是什么?倾斜文字?

输出

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}

    \def\sliceZ{0.8}
    \def\side{2}

    % draw slice
    \filldraw[color=gray!40] (0,\sliceZ,0) -- (0,\sliceZ,\side) -- (\side,\sliceZ,\side) -- (\side,\sliceZ,0) -- cycle;
    \draw[dashed] (0,\sliceZ,0) -- (0,\sliceZ,\side) -- (\side,\sliceZ,\side) -- (\side,\sliceZ,0) -- cycle;

    % draw cube
    \draw (\side,0,0) -- (\side,\side,0) node[midway,right] {axial} -- (0,\side,0);
    \draw (0,0,\side) -- (\side,0,\side) node[midway,below] {lateral} -- (\side,\side,\side) -- (0,\side,\side) -- (0,0,\side);
    \draw (\side,0,0) -- (\side,0,\side) node[midway,below right] {temporal};
    \draw (\side,\side,0) -- (\side,\side,\side);
    \draw (0,\side,0) -- (0,\side,\side);

    \node at (1,\sliceZ,1) {slice};
\end{tikzpicture}

\end{document}

答案1

运行xelatex

\documentclass{article}
\usepackage{pst-solides3d}
\begin{document}

\psset{viewpoint=50 20 30 rtp2xyz,Decran=50}
\begin{pspicture}[solidmemory](-4,-4)(6,5)
\psset{unit=0.5}
\psSolid[object=plan,action=draw**,definition=equation,args={[0 0 1 0]},
         base=-4 4 -4 4,fillcolor=black!15,fillstyle=solid,name=P0]
\psProjection[object=texte,fontsize=100,linecolor=red,text=slice,phi=90,plan=P0]
\psSolid[object=cube,a=8,action=draw,name=A,linecolor=red]
\psSolid[object=plan,action=none,definition=solidface,args=A 4,name=P1]
\psProjection[object=texte,fontsize=50,text=lateral,phi=-90,plan=P1](-5,0)
\psSolid[object=plan,action=none,definition=equation,args={[1 0 0 4]},name=P2]
\psProjection[object=texte,fontsize=50,text=axial,phi=90,plan=P2](0,7)
\psSolid[object=plan,action=none,definition=equation,args={[1 0 0 0]},name=P3]
\psProjection[object=texte,action=draw,fontsize=50,text=temporal,phi=90,plan=P3](4,8)
%\axesIIID(4,4,0)(10,10,10)
\end{pspicture}

\end{document}

您可以将视图更改为您需要的任何内容(视点的第二个参数是 phi:

在此处输入图片描述

\psProjection将其对象放在定义的平面上,其中心位于平面定义的 (x,y) 坐标上。如果没有,则为 (0,0),即平面的原点。

答案2

另一种解决方案。节点的放置取决于坐标系。使用此方法,您无需做任何事情即可获得文本的精确放置。投影在选项中“包含”,因为您指定了要使用的平面。

备注:如果您不想缩放文本,通常最好避免这种修改,但在这里您将文本投影到平面上,因此...要仅针对文本删除缩放,可以scale=.25在之前添加transform shape。也许可以避免rotate=-90

更新 : 添加切片平面

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}     
\usetikzlibrary{3d}

\begin{document}

  \begin{tikzpicture}
    [x={(-0.5cm,-0.5cm)}, y={(1cm,0cm)}, z={(0cm,1cm)}, 
    scale=4,fill opacity=0.80,very thin,rounded corners=3mm,double,every node/.append style={transform shape}]
\newcommand\drawface{\draw[fill=gray!10,double] (-1,-1) rectangle (1,1)}

       % face #1
        \begin{scope}[canvas is yz plane at x=-1]
            \drawface;
            \node[magenta]  {Magenta};
        \end{scope}
        % face #2
        \begin{scope}[canvas is yx plane at z=-1]
           \drawface;
           \node[violet,yscale=-1] {Violet};
        \end{scope} 

        % face #3
        \begin{scope}[canvas is zx plane at y=-1]
           \drawface;
           \node[green,rotate=-90] {Green};
        \end{scope}

    % face #slice
    \begin{scope}[canvas is yx plane at z=-0.25]
    \draw[fill=gray!10,double,rounded corners=1mm] (-1,-1) rectangle (1,1);
       \node[black,yscale=-1,opacity=.8] {Slice};
    \end{scope}

        % face #4
        \begin{scope}[canvas is zx plane at y=1]
           \drawface;
           \node[orange,rotate=-90] {Orange};
        \end{scope}
        % face #5
        \begin{scope}[canvas is yx plane at z=1]
          \drawface;
          \node[blue,yscale=-1] {Blue};
      \end{scope}
        % face #6
      \begin{scope}[canvas is yz plane at x=1]
        \drawface;
        \node[red]  {Red};
      \end{scope}

\end{tikzpicture}
\end{document}  

在此处输入图片描述

答案3

编辑:感谢 Toscho,我更新了这个答案以使用该cm选项。这会手动将坐标系应用于节点文本的画布。

您可以使用xslant。在这种情况下,倾斜度必须设置为的正切,90-Z其中Z是“z 向量”的角度。在下面的示例中,我在环境的开头明确说明了xy和向量,以帮助说明我的意思。此外,为了获得最大的准确性,文本也必须在平面上缩放(这里的缩放有点混乱)。zscopey

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}

\def\zlength{-0.5cm}

\foreach \zangle [count=\i from 0] in {15,20,...,80}{

\begin{scope}[shift={({mod(\i,2)*4cm},{-floor(\i/2)*4cm})}, 
    x=(0:1cm), y=(90:1cm),z=(\zangle:\zlength)]

    \def\sliceZ{0.8}
    \def\side{2}

    % draw slice
    \filldraw[color=gray!40] (0,\sliceZ,0) -- (0,\sliceZ,\side) -- 
    (\side,\sliceZ,\side) -- (\side,\sliceZ,0) -- cycle;
    \draw[dashed] (0,\sliceZ,0) -- (0,\sliceZ,\side) -- 
    (\side,\sliceZ,\side) 
    -- (\side,\sliceZ,0) -- cycle;

    % draw cube
    \draw (\side,0,0) -- (\side,\side,0) node[midway,right] {axial} -- 
    (0,\side,0);
    \draw (0,0,\side) -- (\side,0,\side) node[midway,below] {lateral} -- 
    (\side,\side,\side) -- (0,\side,\side) -- (0,0,\side);
    \draw (\side,0,0) -- (\side,0,\side) node[midway,below right] 
    {temporal};
    \draw (\side,\side,0) -- (\side,\side,\side);
    \draw (0,\side,0) -- (0,\side,\side);

    % The long way.
    %\node [xslant=tan(90-\zangle), 
    %   yscale=height("slice")/abs(\zlength)*sin(\zangle)]
    %   at (1,\sliceZ,1) {slice};

    % The much better way.
    \node[cm={1,0,cos(\zangle),sin(\zangle),(0,0)}] at (1,\sliceZ,1){slice};

\end{scope}
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容