
연습으로 프리즘 [0,2] x [0,4] x [0,6]과 평면 x + y + z = 5의 교차점을 그리려고 합니다.
내 결과는 다음과 같습니다
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[x={(-0.45cm,-0.385cm)},y={(1cm,-0.1cm)},z={(0,1cm)}]
\draw [->] (0,0,0) -- (6,0,0) node [below left] {$x$};
\draw [->] (0,0,0) -- (0,6,0) node [right] {$y$};
\draw [->] (0,0,0) -- (0,0,6) node [right] {$z$};
\filldraw [thick, orange, fill opacity=0.3] (0,0,5) -- (0,4,1) -- (1,4,0) -- (2,3,0) -- (2,0,3) -- cycle;
\filldraw [thick, blue, fill opacity=0.2] (2,3,0) -- (2,0,3) -- (5,0,0) -- cycle;
\filldraw [thick, blue, fill opacity=0.2] (1,4,0) -- (0,5,0) -- (0,4,1) -- cycle;
\filldraw [thick, orange, fill opacity=0.3] (2,3,0) -- (2,0,0) -- (2,0,3) -- cycle;
\filldraw [thick, orange, fill opacity=0.3] (1,4,0) -- (0,4,0) -- (0,4,1) --cycle;
\end{tikzpicture}
\end{document}
지금 몇 가지 질문이 있습니다.
- [0,2] x [0,4] x [0,6]과 같은 쉬운 수학 볼륨을 표현하기 위한 코드가 많은 것 같습니다. 좀 더 효율적으로 그리는 방법이 있나요?
- 교차점을 손으로 계산한 다음 이를 표현해야 합니까? 아니면 직접적인 방법이 있나요?
- 대신
axis
환경과 명령을 사용하여 동일한 결과를 얻으려면 어떻게 해야 합니까 ? 시도해 보았지만 처음이고 축 위치( ) 에 문제가 있고 균일한 색상이 없으며 표면에 그림을 이해하기 어려운 격자가 있고 교차점에 대해서도 동일한 의심이 있습니다. 손으로 계산해야 하나요?\addplot
\draw
\addplot3
view={}{}
colormap
풀 프리즘은 다음과 같습니다.
\draw [fill=orange, fill opacity=0.3] (0,0,6) -- (2,0,6) -- (2,4,6) -- (0,4,6) -- cycle ;
\draw [fill=orange, fill opacity=0.3] (2,0,0) -- (2,0,6) -- (2,4,6) -- (2,4,0) -- cycle ;
\draw [fill=orange, fill opacity=0.3] (2,4,0) -- (0,4,0) -- (0,4,6) -- (2,4,6) -- cycle ;
답변1
무엇을 하든 보다 체계적인 방식으로 3D 뷰를 설치하는 것을 고려해 보십시오. 이를 얻는 가장 좋은 방법은 asymptote
3D에서 교차점을 계산하는 도구가 있는 를 사용하는 것입니다. 를 사용하고 싶다면 pgfplots
를 사용하세요 patch plots
. 그러나 이를 위해서는 교차점을 직접 계산해야 합니다. 이 게시물은 일부를 언급하기 위한 것입니다.실험적인 Ti케이Z 라이브러리이는 또한 3D에서 교차점을 계산할 수 있게 해줍니다.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3dtools}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfdeclarelayer{behind}
\pgfsetlayers{behind,background,main,foreground}
\begin{tikzpicture}[>=stealth,
3d/install view={theta=70,phi=110},
line cap=round,line join=round,
visible/.style={draw,thick,solid},
hidden/.style={draw,very thin,cheating dash},
3d/polyhedron/.cd,fore/.style={visible,fill opacity=0.6},
back/.style={fill opacity=0.6,hidden,3d/polyhedron/complete dashes},
fore layer=foreground,
back layer=background
]
\draw [->] (0,0,0) coordinate (O) -- (6,0,0) coordinate (ex) node [below left] {$x$};
\draw [->] (0,0,0) -- (0,6,0) coordinate (ey) node [right] {$y$};
\draw [->] (0,0,0) -- (0,0,6) coordinate (ez) node [right] {$z$};
\path (5,0,0) coordinate (A) (0,5,0) coordinate (B) (0,0,5) coordinate (C)
(2.5,0,0) coordinate (a) (0,3.5,0) coordinate (b) (0,0,2) coordinate (c) ;
\path[3d/.cd,plane with normal={(ex) through (a) named px},
plane with normal={(ey) through (b) named py},
line through={(A) and (B) named lAB},
line through={(A) and (C) named lAC},
line through={(B) and (C) named lBC}];
\path[3d/intersection of={lAB with px}] coordinate (pABx)
[3d/intersection of={lAB with py}] coordinate (pABy)
[3d/intersection of={lAC with px}] coordinate (pACx)
[3d/intersection of={lBC with py}] coordinate (pBCy);
\pgfmathsetmacro{\mybarycenterA}{barycenter("(A),(pABx),(pACx),(a)")}
\pgfmathsetmacro{\mybarycenterB}{barycenter("(B),(pABy),(pBCy),(b)")}
\tikzset{3d/polyhedron/.cd,O={(\mybarycenterA)},color=blue,
draw face with corners={{(A)},{(pABx)},{(pACx)}},
draw face with corners={{(A)},{(pABx)},{(a)}},
draw face with corners={{(A)},{(a)},{(pACx)}},
O={(\mybarycenterB)},
draw face with corners={{(B)},{(pABy)},{(pBCy)}},
draw face with corners={{(B)},{(pABy)},{(b)}},
draw face with corners={{(B)},{(b)},{(pBCy)}},
color=orange,O={(1,1,1)},
draw face with corners={{(pABx)},{(pACx)},{(C)},{(pBCy)},{(pABy)}},
draw face with corners={{(a)},{(pACx)},{(C)},{(O)}},
draw face with corners={{(b)},{(pBCy)},{(C)},{(O)}},
draw face with corners={{(b)},{(pABy)},{(pABx)},{(a)},{(O)}}
}
\end{tikzpicture}
\end{document}
아직도 많은 노력을 기울이고 있습니다. 그러나 한 가지 이점이 있습니다. 뷰를 변경해도 여전히 올바른 결과를 얻을 수 있다는 것입니다. 예를 들어 3d/install view={theta=70,phi=60},
당신은 얻을 것이다
물론 이는 asymptote
및 patch plot
솔루션에도 적용됩니다(아마도 자동으로 은선을 점선으로 표시할 수 있는 가능성을 제외하고).