我想保存路径上的坐标,以便进一步变形并生成更多路径。目前,我有一个解决方案,decorations.markings
该解决方案似乎几乎可行,但到目前为止,只有坐标计数器在增加。
这是当前生成的图片:
我尝试保存坐标的路径从代表并以圆圈结束,代表(相应函数的图像)。
问题末尾将提供完整的源代码。
在第 11 行到第 30 行,您可以找到坐标计数器的声明和初始化,以及用于保存坐标的tikzset
sstyle
和s。为了方便起见,我将在这里重复它们:code
\newcounter{coordinateindex}
\setcounter{coordinateindex}{0}
\tikzset{
stepcounter/.code={
\stepcounter{coordinateindex}
}
}
\tikzset{
save coordinates/.style={
decoration={markings,
mark=at position 0 with { \coordinate (coordinate\thecoordinateindex); },
mark=between positions 0 and 1 step 0.1 with {
\coordinate[preaction=stepcounter] (coordinate\thecoordinateindex);
}
},
postaction={decorate}
}
}
您可以忽略第一个坐标被保存两次的事实。
在第 159 行,save coordinates
style
应用于路径:
\draw[L1,very thick,save coordinates] (FarEndX1) arc[start angle=180,end angle=160,x radius=100, y radius = 10] coordinate(Img1);
再次,如何在 Tikz 中保存沿路径选定数量的坐标?我在 3.1.9.a 版的 Tikz&PGF 手册中没有找到答案。
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary {decorations.markings}
\begin{document}
\begin{tikzpicture}
\newcounter{coordinateindex}
\setcounter{coordinateindex}{0}
\tikzset{
stepcounter/.code={
\stepcounter{coordinateindex}
}
}
\tikzset{
save coordinates/.style={
decoration={markings,
mark=at position 0 with { \coordinate (coordinate\thecoordinateindex); },
mark=between positions 0 and 1 step 0.1 with {
\coordinate[preaction=stepcounter] (coordinate\thecoordinateindex);
}
},
postaction={decorate}
}
}
\definecolor{L1}{HTML}{ECD9ED}
\definecolor{L2}{HTML}{C7DAC4}
\definecolor{L3}{HTML}{E4B1AD}
\definecolor{L1L2}{HTML}{EF3A43}
\definecolor{L1L3}{HTML}{B7CA54}
\definecolor{L2L3}{HTML}{4C4B6B}
\definecolor{L1L2L3}{HTML}{FBC405}
\newlength{\smallradius}
\setlength{\smallradius}{1cm}
\coordinate (X1) at (0.5,0.75);
\newcommand{\uppercircle}{(X1) circle(\smallradius)};
\path [name path=upper circle] \uppercircle;
\coordinate(X2) at (0,0);
\newcommand{\leftlowercircle}{(X2) circle(\smallradius)};
\path [name path=left lower circle] \leftlowercircle;
\coordinate(X3) at (1,0);
\newcommand{\rightlowercircle}{(X3) circle(\smallradius)};
\path [name path=right lower circle] \rightlowercircle;
% Point of median (X1--Mx1) in the triangle (X1--X2--X3) on the side (X2--X3)
\coordinate (Mx1) at ($(X2)!.5!(X3)$);
\path [name path= median x1] (X1)--(Mx1);
% Point of median (X2--Mx2) in the triangle (X1--X2--X3) on the side (X1--X3)
\coordinate (Mx2) at ($(X1)!.5!(X3)$);
\path [name path= median x2] (X2)--(Mx2);
% Point of median (X3--Mx3) in the triangle (X1--X2--X3) on the side (X1--X2)
\coordinate (Mx3) at ($(X1)!.5!(X2)$);
\path [name path= median x3] (X3)--(Mx3);
% Centroid of the triangle (X1--X2--X3) and, more importantly, the center of the circumscribed circle of the circles (X1,1), (X2,1), and (X3,1)
\path [name intersections={of=median x1 and median x2,by=X1X2X3}];
\newlength{\bigradius}
\newlength{\bigdiameter}
\setlength{\bigradius}{2cm}
\setlength{\bigdiameter}{2\bigradius}
% Line width options: "line width=<dimension>", and abbreviations "ultra thin" for 0.1pt, "very thin" for 0.2pt, "thin" for 0.4pt (the default width), "semithick" for 0.6pt, "thick" for 0.8pt, "very thick" for 1.2pt, "ultra thick" for 1.6pt.
\newlength{\contourthickness}
\setlength{\contourthickness}{1.2pt}
\newcommand{\boundingbox}{($(X1X2X3) - (\bigradius,\bigradius)$) rectangle ($(X1X2X3) + (\bigradius,\bigradius)$)}
\path [name intersections={of=upper circle and left lower circle,by={FarEndX1X2,LowerRightEndX1X2X3}}];
\path [name intersections={of=upper circle and right lower circle,by={FarEndX1X3,LowerLeftEndX1X2X3}}];
\path [name intersections={of=left lower circle and right lower circle,by={UpperEndX1X2X3,FarEndX2X3}}];
\coordinate(FarEndX1) at ($(X1)-(Mx1)+(Mx1)!\smallradius!(X1X2X3)$);
\coordinate(FarEndX1LeftContourStart) at ($(FarEndX1)-(X1X2X3)+(X1X2X3)!\contourthickness!90:(FarEndX1)$);
\coordinate(FarEndX1RightContourStart) at ($(FarEndX1)-(X1X2X3)+(X1X2X3)!\contourthickness!270:(FarEndX1)$);
\coordinate(FarEndX2) at ($(X2)-(Mx2)+(Mx2)!\smallradius!(X1X2X3)$);
\coordinate(FarEndX3) at ($(X3)-(Mx3)+(Mx3)!\smallradius!(X1X2X3)$);
% Upper greater petal
\scope
\clip \boundingbox
\leftlowercircle
\rightlowercircle;
\fill[color=L1] \uppercircle;
\endscope
% Left greater petal
\scope
\clip \boundingbox
\uppercircle
\rightlowercircle;
\fill[color=L2] \leftlowercircle;
\endscope
% Right greater petal
\scope
\clip \boundingbox
\uppercircle
\leftlowercircle;
\fill[color=L3] \rightlowercircle;
\endscope
% Left smaller petal
\scope
\clip \boundingbox
\rightlowercircle;
\clip \leftlowercircle;
\fill[color=L1L2] \uppercircle;
\endscope
% Right smaller petal
\scope
\clip \boundingbox
\leftlowercircle;
\clip \uppercircle;
\fill[color=L1L3] \rightlowercircle;
\endscope
% Lower smaller petal
\scope
\clip \boundingbox
\uppercircle;
\clip \leftlowercircle;
\fill[color=L2L3] \rightlowercircle;
\endscope
% Center
\scope
\clip \uppercircle;
\clip \leftlowercircle;
\clip \rightlowercircle;
\fill[color=L1L2L3] \boundingbox;
\endscope
% outline
\draw \uppercircle
\leftlowercircle
\rightlowercircle;
\node[draw, circle, minimum size= \bigdiameter, label=below:$X_1 \times X_2 \times X_3$] at (X1X2X3) {};
% Solutions from upper greater petal
% TODO: consider using loop since FarEndX1LeftContourStart and FarEndX1RightContourStart are intersections of circles (X1,1) and (FarEndX1, delta)
\draw[black,very thin] (FarEndX1LeftContourStart) arc[start angle=180,end angle=160,x radius=100, y radius = 10];
\draw[black,very thin] (FarEndX1RightContourStart) arc[start angle=180,end angle=160,x radius=100, y radius = 10];
\draw[L1,very thick,save coordinates] (FarEndX1) arc[start angle=180,end angle=160,x radius=100, y radius = 10] coordinate(Img1);
% Image (as in set theory) of the first function
\fill[color=white] (Img1) circle (1);
\node[draw, circle, color=black, minimum size=2cm, label=below:{$[(x_1,x_2,x_3) \mapsto x_1-2x_2-x_3]^{\rightarrow}$} ] at (Img1) {};
\draw[fill] (FarEndX2) circle[radius=2pt];
\draw[fill] (FarEndX3) circle[radius=2pt];
\draw[fill] (UpperEndX1X2X3) circle[radius=2pt];
\draw[fill] (LowerLeftEndX1X2X3) circle[radius=2pt];
%\foreach \i in {1,2,...,\thecoordinateindex}
% \draw[fill] (coordinate\i) circle[radius=2pt];
\end{tikzpicture}
\end{document}
答案1
(注意:当您写入时\coordinate[preaction=stepcounter] ...
,preaction
根本不会使用该键。因此stepcounter
不会调用该代码。)
而要\coordinate[preaction=stepcounter]...
使用\coordinate[stepcounter]...
。
\documentclass[12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary {decorations.markings}
\begin{document}
\begin{tikzpicture}
\newcounter{coordinateindex}
\setcounter{coordinateindex}{0}
\tikzset{
stepcounter/.code={
\stepcounter{coordinateindex}
}
}
\tikzset{
save coordinates/.style={
decoration={markings,
mark=at position 0 with { \coordinate (coordinate\thecoordinateindex); },
mark=between positions 0 and 1 step 0.1 with {
\coordinate[stepcounter] (coordinate\thecoordinateindex);
}
},
postaction={decorate}
}
}
\definecolor{L1}{HTML}{ECD9ED}
\definecolor{L2}{HTML}{C7DAC4}
\definecolor{L3}{HTML}{E4B1AD}
\definecolor{L1L2}{HTML}{EF3A43}
\definecolor{L1L3}{HTML}{B7CA54}
\definecolor{L2L3}{HTML}{4C4B6B}
\definecolor{L1L2L3}{HTML}{FBC405}
\newlength{\smallradius}
\setlength{\smallradius}{1cm}
\coordinate (X1) at (0.5,0.75);
\newcommand{\uppercircle}{(X1) circle(\smallradius)};
\path [name path=upper circle] \uppercircle;
\coordinate(X2) at (0,0);
\newcommand{\leftlowercircle}{(X2) circle(\smallradius)};
\path [name path=left lower circle] \leftlowercircle;
\coordinate(X3) at (1,0);
\newcommand{\rightlowercircle}{(X3) circle(\smallradius)};
\path [name path=right lower circle] \rightlowercircle;
% Point of median (X1--Mx1) in the triangle (X1--X2--X3) on the side (X2--X3)
\coordinate (Mx1) at ($(X2)!.5!(X3)$);
\path [name path= median x1] (X1)--(Mx1);
% Point of median (X2--Mx2) in the triangle (X1--X2--X3) on the side (X1--X3)
\coordinate (Mx2) at ($(X1)!.5!(X3)$);
\path [name path= median x2] (X2)--(Mx2);
% Point of median (X3--Mx3) in the triangle (X1--X2--X3) on the side (X1--X2)
\coordinate (Mx3) at ($(X1)!.5!(X2)$);
\path [name path= median x3] (X3)--(Mx3);
% Centroid of the triangle (X1--X2--X3) and, more importantly, the center of the circumscribed circle of the circles (X1,1), (X2,1), and (X3,1)
\path [name intersections={of=median x1 and median x2,by=X1X2X3}];
\newlength{\bigradius}
\newlength{\bigdiameter}
\setlength{\bigradius}{2cm}
\setlength{\bigdiameter}{2\bigradius}
% Line width options: "line width=<dimension>", and abbreviations "ultra thin" for 0.1pt, "very thin" for 0.2pt, "thin" for 0.4pt (the default width), "semithick" for 0.6pt, "thick" for 0.8pt, "very thick" for 1.2pt, "ultra thick" for 1.6pt.
\newlength{\contourthickness}
\setlength{\contourthickness}{1.2pt}
\newcommand{\boundingbox}{($(X1X2X3) - (\bigradius,\bigradius)$) rectangle ($(X1X2X3) + (\bigradius,\bigradius)$)}
\path [name intersections={of=upper circle and left lower circle,by={FarEndX1X2,LowerRightEndX1X2X3}}];
\path [name intersections={of=upper circle and right lower circle,by={FarEndX1X3,LowerLeftEndX1X2X3}}];
\path [name intersections={of=left lower circle and right lower circle,by={UpperEndX1X2X3,FarEndX2X3}}];
\coordinate(FarEndX1) at ($(X1)-(Mx1)+(Mx1)!\smallradius!(X1X2X3)$);
\coordinate(FarEndX1LeftContourStart) at ($(FarEndX1)-(X1X2X3)+(X1X2X3)!\contourthickness!90:(FarEndX1)$);
\coordinate(FarEndX1RightContourStart) at ($(FarEndX1)-(X1X2X3)+(X1X2X3)!\contourthickness!270:(FarEndX1)$);
\coordinate(FarEndX2) at ($(X2)-(Mx2)+(Mx2)!\smallradius!(X1X2X3)$);
\coordinate(FarEndX3) at ($(X3)-(Mx3)+(Mx3)!\smallradius!(X1X2X3)$);
% Upper greater petal
\scope
\clip \boundingbox
\leftlowercircle
\rightlowercircle;
\fill[color=L1] \uppercircle;
\endscope
% Left greater petal
\scope
\clip \boundingbox
\uppercircle
\rightlowercircle;
\fill[color=L2] \leftlowercircle;
\endscope
% Right greater petal
\scope
\clip \boundingbox
\uppercircle
\leftlowercircle;
\fill[color=L3] \rightlowercircle;
\endscope
% Left smaller petal
\scope
\clip \boundingbox
\rightlowercircle;
\clip \leftlowercircle;
\fill[color=L1L2] \uppercircle;
\endscope
% Right smaller petal
\scope
\clip \boundingbox
\leftlowercircle;
\clip \uppercircle;
\fill[color=L1L3] \rightlowercircle;
\endscope
% Lower smaller petal
\scope
\clip \boundingbox
\uppercircle;
\clip \leftlowercircle;
\fill[color=L2L3] \rightlowercircle;
\endscope
% Center
\scope
\clip \uppercircle;
\clip \leftlowercircle;
\clip \rightlowercircle;
\fill[color=L1L2L3] \boundingbox;
\endscope
% outline
\draw \uppercircle
\leftlowercircle
\rightlowercircle;
\node[draw, circle, minimum size= \bigdiameter, label=below:$X_1 \times X_2 \times X_3$] at (X1X2X3) {};
% Solutions from upper greater petal
% TODO: consider using loop since FarEndX1LeftContourStart and FarEndX1RightContourStart are intersections of circles (X1,1) and (FarEndX1, delta)
\draw[black,very thin] (FarEndX1LeftContourStart) arc[start angle=180,end angle=160,x radius=100, y radius = 10];
\draw[black,very thin] (FarEndX1RightContourStart) arc[start angle=180,end angle=160,x radius=100, y radius = 10];
\draw[L1,very thick,save coordinates] (FarEndX1) arc[start angle=180,end angle=160,x radius=100, y radius = 10] coordinate(Img1);
% Image (as in set theory) of the first function
\fill[color=white] (Img1) circle (1);
\node[draw, circle, color=black, minimum size=2cm, label=below:{$[(x_1,x_2,x_3) \mapsto x_1-2x_2-x_3]^{\rightarrow}$} ] at (Img1) {};
\draw[fill] (FarEndX2) circle[radius=2pt];
\draw[fill] (FarEndX3) circle[radius=2pt];
\draw[fill] (UpperEndX1X2X3) circle[radius=2pt];
\draw[fill] (LowerLeftEndX1X2X3) circle[radius=2pt];
\foreach \i in {1,2,...,\thecoordinateindex}
\draw[fill] (coordinate\i) circle[radius=2pt];
\end{tikzpicture}
\end{document}