我想通过圆弧连接点(s)
和(t)
线。你能帮我实现吗?!我试过这种方法,\draw (s) arc (t);
但错了!简单地说,我需要正确的圆弧,但不能延伸到与定义的路径重合的第一和第二条线,称为血腥圆弧。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{rotating}
\usetikzlibrary{calc,intersections}
\tikzset{
HH/.style={thick}}
\def\scalefactor{2}
\begin{document}
\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (0,0) grid (7,5);
\path[red,thick,name path= bloody arc]
([shift={(0:3)}]2,1) arc (0:90:3);
\draw[HH,name path=first line] (2,1)--(5,2);
\draw[HH,name path=second line] (2,1)--(6,5);
\path[red,name intersections={of=first line and bloody arc, by=s}];
\path[red,name intersections={of=second line and bloody arc, by=t}];
\draw[HH] (s)--(t);
% \draw (s) arc (t);
\end{tikzpicture}
\end{document}
答案1
使用 tkz-euclide
这个问题的可接受答案在 TikZ 中绘制由三点定义的圆弧的最简单方法是什么?演示如何使用中心和两个点绘制圆弧,这正是您要实现的。但是它使用的tkz-euclide
包目前仅以法语记录,尽管据说将来会发布英语手册。
\tkzDrawArc
这是修改后的代码,使用from绘制圆弧tkz-euclide
。另外,请注意,圆弧与原始线条略有重叠,因为交点位于线条的中心。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{calc,intersections}
\tikzset{HH/.style={thick}}
\def\scalefactor{2}
\begin{document}
\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (0,0) grid (7,5);
\path[draw, red,thick,name path= bloody arc]
([shift={(0:3)}]2,1) arc (0:90:3);
\draw[HH,name path=first line] (2,1)--(5,2);
\draw[HH,name path=second line] (2,1)--(6,5);
\path[red,name intersections={of=first line and bloody arc, by=s}];
\path[red,name intersections={of=second line and bloody arc, by=t}];
\draw[HH] (s)--(t);
\path (2,1) coordinate (center); % Where the two lines intersect
\tkzDrawArc[HH,color=black](center,s)(t) % Draw arc counterclockwise from (s) to (t).
\end{tikzpicture}
\end{document}
使用剪辑
或者,如果您不想使用tkz-euclide
,您可以使用clip
路径将弧线限制在两条线之间的区域。遗憾的是,您无法在剪切路径上指定任何其他选项,因此您必须两次提供线条的坐标:一次用于剪切,一次用于实际绘制两条线。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\tikzset{HH/.style={thick}}
\def\scalefactor{2}
\begin{document}
\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (0,0) grid (7,5);
\begin{scope}
\clip (6,5) -- (2,1) -- (5,2); % Only for clipping
\path[red,draw,thick,name path= bloody arc]
([shift={(0:3)}]2,1) arc (0:90:3);
\end{scope}
\draw[HH] (6,5) -- (2,1)--(5,2); % Actually drawing the lines
\end{tikzpicture}
\end{document}
答案2
您还可以使用该calc
库:
\documentclass[tikz, border=5]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\tikzset{HH/.style={thick}}
\def\scalefactor{2}
\begin{document}
\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (1,0) grid (7,5);
\draw[red,thick, name path=bloody arc] ([shift={(0:3)}]2,1) arc (0:90:3);
\draw[HH, name path=first line] (2,1)--(5,2);
\draw[HH, name path=second line] (2,1)--(6,5);
\path[red,name intersections={of=first line and bloody arc, by=s}];
\path[red,name intersections={of=second line and bloody arc, by=t}];
\coordinate (u) at (2,1);
\draw [green] let \p1=($(s)-(u)$),\p2=($(t)-(u)$),\n1={atan2(\y1,\x1)},
\n2={atan2(\x2,\y2)} in (s) arc (\n1:\n2:3);
\end{tikzpicture}
\end{document}
但是这里有一个circular arc around
“路径”,我认为它能正确地完成任务,但为了提高速度使用了一些内部命令。
\documentclass[tikz, border=5]{standalone}
\usetikzlibrary{calc,intersections}
\makeatletter
\tikzset{%
circular arc around/.style={
to path={%
\pgfextra{%
\tikz@scan@one@point\pgf@process#1%
\pgf@xa=-\pgf@x\pgf@ya=-\pgf@y
\pgf@xb=-\pgf@x\pgf@yb=-\pgf@y
\tikz@scan@one@point\pgf@process(\tikztostart)%
\advance\pgf@xa by\pgf@x%
\advance\pgf@ya by\pgf@y%
\tikz@scan@one@point\pgf@process(\tikztotarget)%
\advance\pgf@xb by\pgf@x%
\advance\pgf@yb by\pgf@y%
\pgfmathveclen{\pgf@xa}{\pgf@ya}\let\tikz@radius=\pgfmathresult%
\pgfmathatantwo{\the\pgf@ya}{\the\pgf@xa}%
\pgfmathMod@{\pgfmathresult}{360}%
\let\tikz@angle@a=\pgfmathresult%
\pgfmathatantwo{\the\pgf@yb}{\the\pgf@xb}%
\pgfmathMod@{\pgfmathresult}{360}%
\let\tikz@angle@b=\pgfmathresult%
\edef\tikz@to@arc@path{ arc(\tikz@angle@a:\tikz@angle@b:\tikz@radius pt) }\show\tikz@to@arc@path
} \tikz@to@arc@path
}
}
}
\begin{document}
\begin{tikzpicture}[scale=1/2]
\draw [help lines] (0,0) grid (8,8);
\coordinate (o) at (4,4);
\tikzset{shift=(o)}
\foreach \i in {0.5,1,...,3.5}
\draw [very thick] (o) circle [radius=\i];
\foreach \i [evaluate={\a=rnd*45+\i;\b=\a+rnd*20+30;}] in {0,90,180,270}{
\coordinate (p) at (\a:4);
\coordinate (q) at (\b:4);
\fill [fill opacity=0.25] (o) -- (p) to [circular arc around=(o)] (q) -- cycle;
\foreach \c [count=\r from 1] in {red, yellow, pink, green, orange, purple, blue}{
\coordinate (s) at ($(o)!\r*0.5cm!(p)$);
\coordinate (t) at ($(o)!\r*0.5cm!(q)$);
\draw [very thick,densely dotted, \c] (s) to [circular arc around=(o)] (t);
}
}
\end{tikzpicture}
\end{document}
答案3
如果您已经知道之间的交点bloody arc
,first/second line
您可以重复bloody arc
,但clip
使用适当的矩形。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{rotating}
\usetikzlibrary{calc,intersections}
\tikzset{
HH/.style={thick}}
\def\scalefactor{2}
\begin{document}
\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (0,0) grid (7,5);
\draw[red,thick,name path= bloody arc]
([shift={(0:3)}]2,1) arc (0:90:3);
\draw[HH,name path=first line] (2,1)--(5,2);
\draw[HH,name path=second line] (2,1)--(6,5);
\path[red,name intersections={of=first line and bloody arc, by=s}];
\path[red,name intersections={of=second line and bloody arc, by=t}];
\draw[HH] (s)--(t);
\begin{scope}
\clip (s) rectangle (t);
\draw[green,thick,name path= bloody arc]
([shift={(0:3)}]2,1) arc (0:90:3);
\end{scope}
% \draw (s) arc (t);
\end{tikzpicture}
\end{document}