
我使用tikz-3dplot
並且希望rectangle
和grid
類似的物件與圖形的其餘部分一起旋轉。然而,它們的繪製方式就好像它們是二維的一樣。如何強制rectangle
在旋轉座標中繪製 a ?
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{patterns, arrows, matrix, positioning, decorations.markings, arrows.meta, decorations.pathreplacing}
\usepackage{tikz-3dplot}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\tdplotsetmaincoords{70}{110}
\def\mycolor{blue}
\begin{tikzpicture}[scale=1, tdplot_main_coords, axis/.style={->,\mycolor,thick}]
\def\latnum{8}
\def\lonnum{8}
\draw[axis] (0,0,0) -- (\latnum+1,0,0) node[anchor=north east]{\huge $lat$};
\draw[axis] (0,0,0) -- (0,\lonnum+1,0) node[anchor=north west]{\huge $lon$};
\fill [orange] (\latnum-2,\lonnum-2,0) rectangle (2,2,0);
\end{tikzpicture}
\end{document}
答案1
這是一個非常有趣的問題。
我們期望以下幾行是等效的。但他們不是。
\draw[red](0,0)rectangle(1,1);
\draw[blue](0,0)--(1,0)--(1,1)--(0,1)--cycle;
這rectangle
由Ti處理kZ 由以下幾行(tikz.code.tex
第 3140-3148 行
\pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}% \tikz@path@lineto{\pgfqpoint{\pgf@xa}{\tikz@lasty}}% \tikz@path@lineto{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}% \tikz@path@lineto{\pgfqpoint{\tikz@lastx}{\pgf@ya}}% \pgfpathclose% \pgfpathmoveto{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}%
在此級別,PGF 無法辨識圖形的 3D 結構,因此矩形以 2D 方式繪製在畫布上。
這是非常諷刺的事:如果你\usetikzlibrary{3d}
寫
\draw[canvas is xy plane at z=0](0,0)rectangle(1,1)circle(1);
\draw[canvas is yz plane at x=0](0,0)rectangle(1,1)circle(1);
\draw[canvas is zx plane at y=0](0,0)rectangle(1,1)circle(1);
然後正確繪製了三個圓形,並正確繪製了三個矩形中的兩個。錯誤的是 xy 平面上的那個。
這被固定在繪製 3D 矩形。