我使用在线 TikZ 生成器绘制了浮桥的三维模型。结果如下:
生成的代码:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
% Defining TikZ-package libraries
% -------------------------------------------
\usetikzlibrary{intersections,
calc,
fit,
angles}
\usetikzlibrary{arrows.meta,
patterns,
pgfplots.fillbetween}
% -------------------------------------------
% Adjust pgfplots package
% -------------------------------------------
\pgfplotsset{compat=1.17} % Always used with pgfplots-package.
\pgfdeclarelayer{ft} % Front layer.
\pgfdeclarelayer{bg} % Background layer.
\pgfsetlayers{bg,main,ft} % Set of all the layers. Main is defined as standard.
% -------------------------------------------
\begin{document}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,321); %set diagram left start at 0, and has height of 321
%Shape: Can [id:dp5717673127119256]
\draw (512.96,68.1) -- (530.61,117.73) .. controls (535.48,131.43) and (439.8,177.96) .. (316.9,221.65) .. controls (194,265.34) and (90.42,289.65) .. (85.55,275.94) -- (67.91,226.31) .. controls (63.04,212.61) and (158.72,166.08) .. (281.61,122.39) .. controls (404.51,78.7) and (508.09,54.4) .. (512.96,68.1) .. controls (517.84,81.8) and (422.16,128.33) .. (299.26,172.02) .. controls (176.36,215.71) and (72.78,240.02) .. (67.91,226.31) ;
%Shape: Axis 2D [id:dp10413797801144087]
\draw (272.9,157.55) -- (367.95,126.49)(254.45,68.9) -- (285.51,163.95) (359.75,123.91) -- (367.95,126.49) -- (362.85,133.41) (251.87,77.11) -- (254.45,68.9) -- (261.37,74) ;
%Straight Lines [id:da8625336310449667]
\draw (269.41,152.45) -- (351.17,165.12) ;
\draw [shift={(353.14,165.43)}, rotate = 188.81] [color={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.75] (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29) ;
%Curve Lines [id:da48312758037302217]
\draw (258.14,103.43) .. controls (282.27,99.57) and (271.94,80.81) .. (252.31,95.68) ;
\draw [shift={(250.14,97.43)}, rotate = 319.4] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle ;
%Curve Lines [id:da5961405573248826]
\draw (329,133.43) .. controls (327.05,111) and (364.08,159.88) .. (334.41,144.72) ;
\draw [shift={(332,143.43)}, rotate = 389.2] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle ;
%Curve Lines [id:da970701558271948]
\draw (321.14,157.43) .. controls (331.87,143.78) and (281.89,154.84) .. (311.69,163.75) ;
\draw [shift={(314.14,164.43)}, rotate = 194.48] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle ;
% Text Node
\draw (373.6,122.38) node [anchor=north west][inner sep=0.75pt] [rotate=-341.32] [align=left] {{\small surge}};
% Text Node
\draw (325,104) node [anchor=north west][inner sep=0.75pt] [align=left] {{\small \textcolor[rgb]{0.82,0.01,0.11}{roll}}};
% Text Node
\draw (334.94,166.59) node [anchor=north west][inner sep=0.75pt] [font=\small,rotate=-11.44] [align=left] {{\small sway}};
% Text Node
\draw (227.61,54.51) node [anchor=north west][inner sep=0.75pt] [rotate=-343.32] [align=left] {{\small heave}};
% Text Node
\draw (275.96,93.09) node [anchor=north west][inner sep=0.75pt] [rotate=-334.26] [align=left] {{\small \textcolor[rgb]{0.82,0.01,0.11}{yaw}}};
% Text Node
\draw (289.21,177.95) node [anchor=north west][inner sep=0.75pt] [font=\small,rotate=-338.93] [align=left] {{\small \textcolor[rgb]{0.82,0.01,0.11}{pitch}}};
% Text Node
\draw (365.69,108.23) node [anchor=north west][inner sep=0.75pt] [rotate=-340.94] [align=left] {x*};
% Text Node
\draw (355,153) node [anchor=north west][inner sep=0.75pt] [align=left] {y*};
% Text Node
\draw (262.82,61.85) node [anchor=north west][inner sep=0.75pt] [rotate=-341.17] [align=left] {z*};
\end{tikzpicture}
\end{document}
虽然这个图形可能足以满足我的目的,但我想做一些小的调整,并且能够使用 TikZ 从头开始生成这个图形。
我怎样才能创建三维椭圆、轴以及围绕它们的弯曲箭头?
答案1
这是有可能的。它不完全是你的透视图,而是等距透视图,这样更容易绘制(特别是圆柱体)。你可以使用canvas is ... plane at ...
tikz 3d 库中的选项,这样你就可以绘制椭圆和箭头弧(滚动、俯仰和偏航)。
\documentclass[border=2mm]{standalone}
\usepackage {tikz}
\usetikzlibrary{3d} % for 'canvas is...' options
\usetikzlibrary{babel} % there are some issues with tikz and some babel packages
% isometric axes
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zy{sqrt(2/3)}
% styles
\tikzset%
{%
axis/.style={thick,-latex},
axis node/.style={transform shape,right,midway,sloped,xshift=0.6cm},
arc arrow/.style={magenta,midway,right},
}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,% isometric axes:
x={(\xx cm,\xy cm)},y={(\xx cm,-\xy cm)},z={(0 cm,\zy cm)},%
rotate=10] % but rotated 10 degrees anticlockwise
% definitions
\def\r{3.5} % cylinder radius
\def\h{1} % cylinder height
\def\lr{0.25} % little radius for the arrow arcs
% axes
\draw[axis] (0,0,0) -- (0.5*\r,0,0) node [axis node] {$\mathrm{x}^*$ surge};
\draw[axis] (0,0,0) -- (0,0.5*\r,0) node [axis node] {$\mathrm{y}^*$ sway};
\draw[axis] (0,0,0) -- (0,0,\r) node [transform shape,above] {$\mathrm{z}^*$ heave};
% cylinder
\draw (0,0) circle (\r);
\draw (45:\r) --++ (0,0,-\h) arc (45:225:\r) --++ (0,0,\h);
% roll, pitch and yaw arrows
\draw[canvas is xy plane at z=0.5*\r ,->] (180:\lr) arc (180:-90:\lr) node [arc arrow] {yaw};
\draw[canvas is xz plane at y=0.25*\r,->] (-90:\lr) arc (-90:180:\lr) node [arc arrow,pos=1,left] {pitch};
\draw[canvas is yz plane at x=0.25*\r,->] (180:\lr) arc (180:-90:\lr) node [arc arrow] {roll};
\end{tikzpicture}
\end{document}
编辑:浮桥需要椭圆形截面。如前所述,在等距透视图中(以及任何其他透视图中)绘制切线母线将非常困难。我提供了一种解决方法,绘制椭圆形而不是椭圆形。我遵循等距椭圆形的方法(可以是任何其他椭圆形,这里的透视并不重要,因为我在水平面上绘制 2d 椭圆形)。为了更好地了解我使用的方法,您可以取消注释代码中的菱形线。这样,切线再次位于圆之间,并且很容易确定切点。
我添加了 tikz 库,calc
因为我需要计算几个坐标。我还像在 OP 解决方案中一样更改了轴。
\documentclass[border=2mm]{standalone}
\usepackage {tikz}
\usetikzlibrary{3d} % for 'canvas is...' options
\usetikzlibrary{babel} % there are some issues with tikz and some babel packages
\usetikzlibrary{calc} % computes coordinates
% isometric axes
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zy{sqrt(2/3)}
% styles
\tikzset%
{%
axis/.style={thick,-latex},
axis node/.style={transform shape,right,midway,sloped,xshift=0.6cm},
arc arrow/.style={magenta,midway,right},
}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,% isometric axes:
x={(\xx cm,-\xy cm)},y={(\xx cm,\xy cm)},z={(0 cm,\zy cm)},%
rotate=10] % but rotated 10 degrees anticlockwise
% definitions
\def\r{3.5} % cylinder radius
\def\h{1} % cylinder height
\def\lr{0.25} % little radius for the arrow arcs
% axes
\draw[axis] (0,0,0) -- (0.5*\r,0,0) node [axis node] {$\mathrm{x}^*$ surge};
\draw[axis] (0,0,0) -- (0,0.5*\r,0) node [axis node] {$\mathrm{y}^*$ sway};
\draw[axis] (0,0,0) -- (0,0,\r) node [transform shape,above] {$\mathrm{z}^*$ heave};
% pontoon
\def\l{4} % rhombus semi-lenght (the rhombus is circumscribed to the pontoon, see below)
\begin{scope}[canvas is xy plane at z=0]
\coordinate (A) at ({sqrt(3)*\l},0);
\coordinate (B) at (0,\l);
\coordinate (C) at ({-sqrt(3)*\l},0);
\coordinate (D) at (0,-\l);
\coordinate (P) at ($(A)!0.5!(B)$); % only needed in the rhombus
\coordinate (Q) at ($(B)!0.5!(C)$); % only needed in the rhombus
\coordinate (R) at ($(C)!0.5!(D)$); % only needed in the rhombus
\coordinate (S) at ($(D)!0.5!(A)$);
\coordinate (T) at ($1/3*(A)+1/3*(B)+1/3*(D)+(45:{\l/sqrt(3)})$);
\draw (S) arc (-60: 60:{\l/sqrt(3)}) arc ( 60:120:{sqrt(3)*\l})
arc (120:240:{\l/sqrt(3)}) arc (240:300:{sqrt(3)*\l});
\end{scope}
\draw (T) --++ (0,0,-\h) arc (45:-60:{\l/sqrt(3)}) arc (-60:-120:{sqrt(3)*\l}) arc (-120:-135:{\l/sqrt(3)}) --++ (0,0,\h);
% rhombus (uncomment to see)
%\draw[red] (A) -- (B) -- (C) -- (D) -- cycle;
%\draw[red] (P) -- (D) -- (Q);
%\draw[red] (R) -- (B) -- (S);
% roll, pitch and yaw arrows
\draw[canvas is xy plane at z=0.5*\r ,->] (180:\lr) arc (180:-90:\lr) node [arc arrow] {yaw};
\draw[canvas is xz plane at y=0.25*\r,->] (180:\lr) arc (180:-90:\lr) node [arc arrow,yshift=-2mm]{pitch};
\draw[canvas is yz plane at x=0.25*\r,->] (-90:\lr) arc (-90:180:\lr) node [arc arrow,pos=1,left] {roll};
\end{tikzpicture}
\end{document}
我认为,如果使用垂直 z 轴,图片会看起来更好。要获得此功能,只需在选项rotate=10
中删除tikzpicture
。您将获得此功能。
答案2
Juan,我对你提出的解决方案做了一些修改。我用椭圆形替换了圆形,并在绘图中使用了图层。我得到了与我想要实现的结果类似的结果:但是,正如你提到的,切线母线还没有完全到位。此外,轴系统似乎有点倾斜。不过我不太清楚如何解决这个问题。
代码:
\documentclass[border=2mm]{standalone}
\usepackage {tikz}
\usetikzlibrary{3d} % for 'canvas is...' options
\usetikzlibrary{babel} % there are some issues with tikz and some babel packages
% Adjust pgfplots package
% -------------------------------------------
\pgfdeclarelayer{ft} % Front layer.
\pgfdeclarelayer{bg} % Background layer.
\pgfsetlayers{bg,main,ft} % Set of all the layers. Main is defined as standard.
% -------------------------------------------
\pgfsetlayers{bg,main,ft}
% isometric axes
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zy{sqrt(2/3)}
% styles
\tikzset%
{%
axis/.style={thick,-latex},
axis node/.style={transform shape,right,midway,sloped,xshift=0.6cm},
arc arrow/.style={magenta,midway,right},
}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,% isometric axes:
x={(\xx cm,\xy cm)},y={(\xx cm,-\xy cm)},z={(0 cm,\zy cm)},%
rotate=10] % but rotated 10 degrees anticlockwise
% definitions
\def\r{3.5} % cylinder radius
\def\h{1} % cylinder height
\def\lr{0.25} % little radius for the arrow arcs
\begin{pgfonlayer}{ft}
% axes
\draw[axis] (0,0,0) -- (0,0.5*\r,0) node [axis node] {$\mathrm{x}^*$ surge};
\draw[axis] (0,0,0) -- (0.5*\r,0,0) node [axis node] {$\mathrm{y}^*$ sway};
\draw[axis] (0,0,0) -- (0,0,\r) node [transform shape,above] {$\mathrm{z}^*$ heave};
% roll, pitch and yaw arrows
\draw[canvas is xy plane at z=0.5*\r ,->] (180:\lr) arc (180:-90:\lr) node [arc arrow] {yaw};
\draw[canvas is xz plane at y=0.25*\r,->] (-90:\lr) arc (-90:180:\lr) node [arc arrow,pos=1,left] {roll};
\draw[canvas is yz plane at x=0.25*\r,->] (180:\lr) arc (180:-90:\lr) node [arc arrow] {pitch};
\end{pgfonlayer}
% cylinder
\draw [fill=white] (0,0) ellipse [x radius=3, y radius=6];
\begin{pgfonlayer}{bg}
\draw (0,0,-\h) ellipse [x radius=3, y radius=6];
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
对最后的部分有什么建议吗?