我使用以下代码在圆内创建三角形,效果非常好。有人能告诉我哪里可以学习改编此代码,例如创建双角规则或循环四边形吗?
\documentclass[tikz,margin=2mm,5pt]{standalone}
\usetikzlibrary {angles,quotes}
\usetikzlibrary{calc,positioning}
\pgfmathsetseed{\pdfuniformdeviate 10000000}
\usepackage{scrextend}
\changefontsizes[10pt]{5pt}
\pgfdeclarelayer{back}
\pgfdeclarelayer{front}
\pgfsetlayers{back,main,front}
\begin{document}
\foreach \p in {{A/2,B/2,C/4,D/5},{A/2,B/3,C/4,D/6,E/9}}{
\begin{tikzpicture}
\pgfmathsetmacro\r{2cm} \pgfmathsetmacro\ld{3mm}
\foreach \l/\v[evaluate=\v as \s using \s + \v,remember=\s as \s (initially 0),
remember=\l as \ls,remember=\v as \lv] in \p{}
\pgfmathsetmacro\unit{360/\s} \pgfmathsetmacro\ai{rnd*360}
\fill circle(1pt) coordinate (I); \draw circle(\r pt);
\draw (\ai:\r pt)
\foreach \l/\v[evaluate=\v as \s using \psum + \v, remember=\s as \psum (initially 0)]
in \p {-- ({\unit*\psum+\ai}:\r pt) coordinate (\l)} -- cycle;
\foreach \l/\v in \p {
\draw (I) -- (\l); \fill (\l) circle (1pt);
\node at ($(I)!\r pt+\ld pt!(\l)$) {$\l$};
}
\node[circle,inner sep=0.1pt] at ($(I) + (\ai:3mm)$) {$O$}; %labeled O But Referenced I
\foreach \l/\v[remember=\l as \pl (initially \ls),remember=\v as \pv (initially \lv)]
in \p {\node at ($(I)!\r pt+\ld pt!($(\pl)!.5!(\l)$)$) {\pv};}
\end{tikzpicture}
}
\end{document}
我不知道这是否超出了本网站的权限,我只是想寻求有关在哪里学习的帮助(但显然任何帮助都会很好)。谢谢
答案1
您的代码:
- 包含错误,因此我们无法测试它;
- 非常——在我看来没有必要——复杂且不清楚(我必须承认,我迷失在其中);
- 不完全清楚,你的代码应该产生什么。
- 如果您的代码需要在(任何)三角形周围绘制圆圈,那么可以用更简单的方法来完成:
- 首先画圆,
- 然后在圆上定义三个(随机)点作为三角形角的坐标
- 在定义的坐标之间画线。
\documentclass[border=3.141592=12mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning,
quotes}
\pgfmathsetseed{\pdfuniformdeviate 10000000}
\begin{document}
\begin{tikzpicture}[
trig format=rad,
dot/.style = {circle, fill, inner sep=1pt, outer sep=0pt},
ang/.style = {draw=red, <->,
angle radius = 3mm,
angle eccentricity=1.2,
}
]
\pgfmathsetmacro{\r}{2}
\pgfmathsetmacro{\R}{\r+0.3}
% circle
\draw (0,0) coordinate (O) circle[radius=\r];
% triangles' corners coordinates and labels
\foreach \c/\l in {rand/A, rand/B, rand/C} % define random coefficients
% for calculations of triangle's
% corners coordinates on circle
% and define corners names
{
\pgfmathsetmacro{\C}{2*pi*\c} % calculate triangle coordinates
\node (\l) [dot] at (\C:\r) {}; % draw dots at triangle corners
\draw[-Stealth, gray, very thin] % draw arrows from circle center
% to triangle's corners,
% if not needed, just delete this line
(0,0) -- (\l);
\path (\l) -- (\C:\R) node {\l}; % define corners labels coordinates,
% they are in direction of vector
% from circle origin to dot node
}
% triangle
\draw[cyan]
(A) -- (B) -- (C) -- (A); % draw trangle
\end{tikzpicture}
\end{document}
一个随机的结果是(每次编译后都不同,这是你想要的吗?):
答案2
另一个(我希望)教学示例:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1.5]
% rotate (six time) a square around hi center
\foreach \i in {15,30,...,90}
\filldraw[blue!60!brown,line width=1pt,rotate around={\i:(4,0)}]
(0,0)--(4,4)--(8,0)--(4,-4)--(0,0);
% fix a circular zone where to place the Euler picture
\begin{scope}
\path [clip] (4,0) circle (2.9);
\node at (4,0) () {\includegraphics[width=10cm]{Euler.png}};
\end{scope}
%the circle atound the picture
\draw[white,line width=4pt] (4,0) circle(2.9);
%some text on top snd on bottom of the picture
\node[white] at (4,3.15) () {\LARGE \bfseries L. Euler};
\node[white] at (4,-3.2) () {\huge \bfseries $e^{i\pi}+1=0$};
\end{tikzpicture}
\end{document}
输出:
答案3
再举两个例子:
\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc,snakes}
\usetikzlibrary{ decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=.6]
%muretto
\filldraw[gray!60] (0.25,.25)--(0,0)--(11.75,0)--(12,.25);
\filldraw[gray] (0,0) rectangle (11.75,-.5);
\filldraw[gray!40] (11.75,0)--(11.75,-.5)--(12,-.25)--(12,.25);
% lance
\foreach \i in {1,1.5,...,6}
\draw[line width=3pt,-latex] (\i,0.1)--(\i,\i-.1);
\foreach \i in {.5,1,...,5}
\draw[line width=3pt,-latex] (\i+6,0.1)--(\i+6,5.9-\i);
\end{tikzpicture}
\vspace{3cm}
\begin{tikzpicture}[scale=1.1]
\filldraw[snake=snake,blue,line width=1pt]
(0,0)--(4,4)--(8,0)--(4,-4)--(0,0);
\filldraw[blue] (4,0) circle(3.25);
\shade[ball color=gray!5] (4,0) circle (2);
\foreach \i in {2,2.417,2.824,3.25}
\draw[yellow!30,line width=2.5pt] (4,0) circle(\i);
\node[blue] at (4,0) () {\Huge \bfseries $e^{i\pi}+1=0$};
\filldraw[white] (4,3.5) circle(2pt);
\end{tikzpicture}
\end{document}
输出: