我需要在 TikX 中画一个半圆,起始于 (x1, y1),结束于 (x2, y2),假设该圆以 (cx, cy) 为中心,半径为 r。
例如:
(x1,y1)=(0.25598,0.8256)
(x2,y2)=(0.3870,0.7221)
(cx,cy)=(0.5,1)
r = 0.3
大多数例子都使用角度而不是点。
答案1
借助海科·奥伯迪克:
\documentclass{standalone}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (2.5598,8.256);
\coordinate (B) at (3.870,7.221);
\coordinate (C) at ($(A)!.5!(B)$);
\draw[fill=red] (A) circle [radius=2pt];
\draw[fill=blue] (B) circle [radius=2pt];
\draw (A) -- (B);
\pgfmathanglebetweenpoints{\pgfpointanchor{C}{center}}{\pgfpointanchor{A}{center}}
\let\StartAngle\pgfmathresult
\pgfmathanglebetweenpoints{\pgfpointanchor{C}{center}}{\pgfpointanchor{B}{center}}
\let\EndAngle\pgfmathresult
\draw[fill=green] (C) circle [radius=2pt];
\draw (A) let \p1 = ($(C) - (A)$),
\n1 = {veclen(\x1, \y1)}
in
arc [start angle=\StartAngle, end angle=\EndAngle, radius=\n1];
\end{tikzpicture}
\end{document}
答案2
角度可以通过以下方式计算\pgfmathanglebetweenpoints
:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (c) at (.5, 1);
\coordinate (p1) at (.25598, .8256);
\coordinate (p2) at (.3870, .7221);
\pgfmathanglebetweenpoints{\pgfpointanchor{c}{center}}{\pgfpointanchor{p1}{center}}
\let\StartAngle\pgfmathresult
\pgfmathanglebetweenpoints{\pgfpointanchor{c}{center}}{\pgfpointanchor{p2}{center}}
\let\EndAngle\pgfmathresult
\draw (p1) arc[start angle=\StartAngle, end angle=\EndAngle, radius=.3];
\fill[radius=.5pt, red] (p2) circle[] (p1) circle[] (c) circle[];
\end{tikzpicture}
\end{document}