![在 TikZ 上围绕其边缘旋转平面](https://linux22.com/image/466223/%E5%9C%A8%20TikZ%20%E4%B8%8A%E5%9B%B4%E7%BB%95%E5%85%B6%E8%BE%B9%E7%BC%98%E6%97%8B%E8%BD%AC%E5%B9%B3%E9%9D%A2.png)
我正在尝试绕其边缘 AB 旋转右侧的红色平面,问题实际上是关于绕任意路径旋转任何物体,我知道命令rotate around
,并且可以使用它绕任意点或轴旋转,我实际上用它尝试绕图中的点 C 进行两次旋转,失败的结果是绿色平面,预期结果是具有 AD 边缘的对角平面和 xz 平面上的红色平面,我已经按照老方法绘制了它们。
我知道tikz-3dplot
和perspective
包以及canvas is x1x2 at x3=cte
可以用作选项的语法,但我并没有真正成功地使用它们来实现我想要的结果。
\documentclass{standalone}
\usepackage{tikz, amsmath, amsfonts, amssymb}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}%[canvas is zy plane at x=10]
\coordinate (O) at (0,0,0);
\coordinate (C) at (3,0,1.5);
\coordinate (D) at ($3*({(1-cos(45))},{cos(45)},1)$);
\coordinate (A) at (3,0,3);
\coordinate (B) at (3,0,0);
%XYZ axis
\draw[->] (O) -- (5,0,0) node[right] {x};
\draw[->] (O) -- (0,5,0) node[above] {y};
\draw[->] (O) -- (0,0,5.5) node[left] {z};
%Attempted point of rotation
\filldraw (C) circle (2.5pt) node[below right] {C};
%Red right plane
\filldraw[red, opacity=.5, rotate around={0:(C)}] (3,0,3) --++(0,0,-3) --++(0,3,0) node[right, midway, text opacity=1, black] {3} --++(0,0,3) -- cycle;
%Blue top plane
\filldraw[blue, opacity=.5] (0,3,3) --++(0,0,-3) --++(3,0,0) node[midway, above, text opacity=1] {3} --++(0,0,3) -- cycle;
%Cube's diagonal plane
\draw[fill=gray, opacity=.25, text = black] (3,0,3) --++(0,0,-3) --++(-3,3,0) --++(0,0,3) -- cycle;
%Actual rotation 1
\filldraw[purple, opacity=.4] (3,0,3) --++(0,0,-3) --++($cos(45)*(-3,3,0)$) --++(0,0,3) -- cycle;
%Actual rotation 2
\filldraw[purple, opacity=.5] (3,0,3) --++(0,0,-3) --++(-3,0,0) --++(0,0,3) -- cycle;
%Segment AD
\draw[very thick] (A) -- (D) node [left] {D};
%Failed rotation 1
\filldraw[green, opacity=.25, rotate around={45:(C)}] (3,0,3) --++(0,0,-3) --++(0,3,0) --++(0,0,3) -- cycle;
%Failed rotation 2
\filldraw[green, opacity=.25, rotate around={90:(C)}] (3,0,3) --++(0,0,-3) --++(0,3,0) --++(0,0,3) -- cycle;
%Intended axis of rotation
\draw[very thick] (A) node[below] {A} -- (B) node[above right] {B};
\node at (4,4,0) {
$
\bigl|\overline{AD}\bigr| = 3
$
};
\end{tikzpicture}
\end{document}
答案1
欢迎来到 TeX.SE。
我只画了四个矩形和轴,作为示例,我希望这足够了。
canvas is...
您可以使用库中的选项在与 XY、XZ 和 YZ 平行的平面上绘制矩形(如您所述)3d
。例如,红色的:
\filldraw[red,opacity=0.5,canvas is yz plane at x=3] (0,0) rectangle (3,3);
对于其他平面,您必须移动原点,然后围绕(新)z 轴旋转,最后将画布设置为(新)xz 平面。由于这是针对两个平面的,因此可以按以下方式完成scope
:
\begin{scope}[shift={(3,0,0)},rotate around z=135,canvas is xz plane at y=0]
...
\end{scope}
最后,对于灰色平面,您可以制作一个可选的比例:xscale={sqrt(2)}
。
完整示例:
\documentclass[tikz,border=1.618mm]{standalone}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}
%XYZ axis
\draw[->] (0,0,0) -- (5,0,0) node[right] {x};
\draw[->] (0,0,0) -- (0,5,0) node[above] {y};
\draw[->] (0,0,0) -- (0,0,5.5) node[left] {z};
% Rotations
\begin{scope}[shift={(3,0,0)},rotate around z=135,canvas is xz plane at y=0]
%Cube's diagonal plane
\draw[fill=gray,opacity=0.25,xscale={sqrt(2)}] (0,0) rectangle (3,3);
%Cube's diagonal plane (more usual alternative)
% \draw[fill=gray,opacity=0.25] (0,0) rectangle ({3*sqrt(2)},3);
%Actual rotation
\draw[fill=purple,opacity=0.4] (0,0) rectangle (3,3);
\end{scope}
%Red right plane
\filldraw[red,opacity=0.5,canvas is yz plane at x=3] (0,0) rectangle (3,3);
%Blue top plane
\filldraw[blue,opacity=0.5,canvas is xz plane at y=3] (0,0) rectangle (3,3);
\end{tikzpicture}
\end{document}
答案2
这是一个使用 Asymptote 的简单方法。在 3D 中,我们可以通过 定义一个平面 P(平行四边形)ABCD P=plane(B-A,D-A,A)
,然后使用变换t=rotate(45,A,B)
(绕 A--B 旋转 45 度)得到t*P
。
此 3D 变换t
可用于任何 3D 路径。这是 3D Asymptote 相对于3d
TikZ 库的优势。
// http://asymptote.ualberta.ca/
import three;
import graph3;
unitsize(1cm);
// obliqueX, obliqueY, obliqueZ or any others
//currentprojection=oblique;
currentprojection=orthographic(1.5,1,3,up=Y);
triple A=(3,0,3), B=(3,0,0);
real a=Cos(45); // cosine in degrees
triple D=3*(1-a,a,1);
// the plane with the edges A--B and A--D
path3 P=plane(B-A,D-A,A);
draw(P,red);
draw(surface(P),red+opacity(.2));
// t rotates around A--B any path3 with 45 degrees
transform3 t=rotate(45,A,B);
draw(t*P,blue);
draw(surface(t*P),blue+opacity(.2));
label("$A$",A,SW);
label("$B$",B,NE);
label("$D$",D,W);
axes3("$x$","$y$","$z$",min=O,max=(5,5,5),Arrow3);