我想创建一个命令,使用 4 个参数绘制希波克拉底的月牙形:两个圆弧的边 A 和 B 以及圆心 K 和 L。我的命令有 8 个参数,但我认为它需要简化。
\documentclass[a4paper,11pt]{article}
\usepackage[no-math,cm-default]{fontspec}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setmainfont[Mapping=tex-text,Numbers=Lining,Scale=1.0]{Times New Roman}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\newcommand{\miniskos}[8]{
\tkzDefPoint(#1){#3}
\tkzDefPoint(#2){#4}
\tkzDefLine[mediator](#3,#4) \tkzGetPoints{a}{b}
\tkzDefPointWith[linear,K=#6](a,b) \tkzGetPoint{#5}
\tkzDefLine[perpendicular=through #5,%
K=#8](#3,#4)\tkzGetPoint{#7}
\tkzDrawArc(#5,#3)(#4)
\tkzDrawArc(#7,#3)(#4)
}
\begin{document}
\begin{tikzpicture}
\miniskos{0,1}{1,2}{A}{B}{K}{.3}{L}{.5}
\tkzDrawPoints(A,B,K,L)
\end{tikzpicture}
\end{document}
另外,我希望有填充两个圆弧之间的区域的选项,但我不知道如何用命令来做到这一点。
编辑 月牙形是两个圆弧之间的区域。
答案1
使用您的代码,理论上您只需要两个点,A
和B
。第一个解决方案与您的代码有关,第二个解决方案是显示希波克拉底的月牙形。
OP 的代码
代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\newcommand{\mnskos}[3][blue!10]{%
\tkzDefPoint(#2){A}
\tkzDefPoint(#3){B}
\tkzDefLine[mediator](A,B) \tkzGetPoints{a}{b}
\tkzDefPointWith[linear,K=.3](a,b) \tkzGetPoint{K}
\tkzDefLine[perpendicular=through K, K=.5](A,B)\tkzGetPoint{L}
\begin{scope}
\tkzDrawArc[fill=#1](K,A)(B)
\clip (L) rectangle (A-|B);
\tkzFillCircle[fill=white](L,A)
\end{scope}
\tkzDrawArc(L,A)(B)
\tkzDrawPoints(A,B,K,L)
\tkzLabelPoints(A,B,K,L)
}
\begin{document}
\begin{tikzpicture}
\mnskos{0,1}{1.5,2.5}
\end{tikzpicture}
\end{document}
希波克拉底的月亮
代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\newcommand{\mskos}[3][blue!10]{%
\tkzDefPoint(#2){A}
\tkzDefPoint(#3){B}
\tkzDefSquare(A,B) \tkzGetSecondPoint{C}
\tkzDrawAltitude[draw=none](B,C)(A) \tkzGetPoint{O}
\tkzDrawArc[color=black](O,C)(B)
\tkzDefMidPoint(A,B) \tkzGetPoint{D}
%
% this
%\begin{scope}
%\tkzDefSquare(B,A) \tkzGetPoints{c}{d}
%\tkzClipPolygon(A,B,d,c)
%\tkzDrawArc[color=black, #1](D,A)(B)
%\tkzFillCircle[draw=black,fill=white](O,A)
%\end{scope}
%
% or this
\tkzCalcLength[cm](O,A) \tkzGetLength{rAB}
\tkzCalcLength[cm](B,D) \tkzGetLength{rBD}
\filldraw[black, fill=#1] (A)
arc (270:360:\rAB)
node[pos=.5, font=\tiny, below right, inner sep=0, outer sep=0pt] {$e$}
arc (45:-135:\rBD)
node[pos=.5, font=\tiny, below right, inner sep=0, outer sep=0pt] {$f$}
;
%
\tkzDrawSegment[style=dashed](C,O)
\tkzFillPolygon[draw=black,fill=#1](A,B,O)
\tkzDrawPoints[fill=black, size=3pt](A,B,C,D,O)
\tkzLabelPoints[font=\tiny, above](B,C,O)
\tkzLabelPoints[font=\tiny, below](A,D)
}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-2,xmax=2,ymin=0,ymax=3]
\tkzClip
\mskos{0,1}{1.5,2.5}
\end{tikzpicture}
\end{document}
答案2
使用该库时应始终小心,intersections
因为它可能不够准确,但给定两个中心和两个半径(并假设圆相交),以下方法似乎可以正常工作:
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{intersections,calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (1,2);
\begin{scope}[overlay]
\path [name path=A] (A) circle [radius=3];
\path [name path=B] (B) circle [radius=3/2];
\path [name intersections={of=A and B, by={p1,p2}}];
\end{scope}
\draw [dashed] (p1) -- (A) -- (p2);
\draw [dashed] (p1) -- (B) -- (p2);
\fill [red] let
\p1=(A),\p2=(B),\p3=(p1),\p4=(p2),
\n1={veclen(\x3-\x1,\y3-\y1)},
\n2={atan2(\y3-\y1,\x3-\x1)}, \n3={atan2(\y4-\y1,\x4-\x1)},
\n4={veclen(\x3-\x2,\y3-\y2)},
\n5={atan2(\y3-\y2,\x3-\x2)}, \n6={atan2(\y4-\y2,\x4-\x2)} in
($(A)+(\n2:\n1)$) arc (\n2:\n3:\n1) arc(\n6:\n5:\n4) -- cycle;
\foreach \n in {A, B, p1,p2}
\fill (\n) circle [radius=.05];
\end{tikzpicture}
\end{document}