Tikz:使用兩點指定圓半徑,無需 Euclid 包

Tikz:使用兩點指定圓半徑,無需 Euclid 包

我用\coordinatea 和 b 定義兩個點。然後我嘗試繪製圓心為 a,半徑為 ab 的圓。我嘗試了3次,請看下面的程式碼

  1. 有點幼稚,行不通
  2. 使用https://tex.stackexchange.com/a/58287,不起作用
  3. 使用https://tex.stackexchange.com/a/38500這會產生一個半徑很大的圓。

有沒有辦法讓這三者中的任何一個都發揮作用?最簡單的越好。

\documentclass{article}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{calc,patterns,angles,quotes,intersections}

\makeatletter
\def\calcLength(#1,#2)#3{%
\pgfpointdiff{\pgfpointanchor{#1}{center}}%
             {\pgfpointanchor{#2}{center}}%
\pgf@xa=\pgf@x%
\pgf@ya=\pgf@y%
\FPeval\@temp@a{\pgfmath@tonumber{\pgf@xa}}%
\FPeval\@temp@b{\pgfmath@tonumber{\pgf@ya}}%
\FPeval\@temp@sum{(\@temp@a*\@temp@a+\@temp@b*\@temp@b)}%
\FProot{\FPMathLen}{\@temp@sum}{2}%
\FPround\FPMathLen\FPMathLen5\relax
\global\expandafter\edef\csname #3\endcsname{\FPMathLen}
}
\makeatother

\begin{document}

Attempt 1:

\begin{center}
\begin{tikzpicture}[]
\coordinate (a) at (0,0);
\coordinate (b) at (1.3,1.5);
\draw (a) circle (2);
\draw (a) circle ($(b)-(a)$);
\end{tikzpicture}
\end{center}

Attempt 2:

\begin{center}
\begin{tikzpicture}[]
\coordinate (a) at (0,0);
\coordinate (b) at (1.3,1.5);
\draw (a) circle (2);
% https://tex.stackexchange.com/a/58287
\draw 
  let
  \p1 = (a),
  \p2 = (b),
  \n1 = {veclen((\x2-\x1),(\y2-\y1))}
(a) circle ({\n1});
\end{tikzpicture}
\end{center}

Attempt 3:

\begin{center}
\begin{tikzpicture}[]
\coordinate (a) at (0,0);
\coordinate (b) at (1.3,1.5);
\draw (a) circle (2);
% https://tex.stackexchange.com/a/38500
\calcLength(a,b){mylen}
\draw (a) circle (\mylen);
\end{tikzpicture}
\end{center}


\end{document}

答案1

第一次嘗試稍加修改就可以了。如果您添加缺少的內容,第二個也可以工作in(並且人們可能想切換到現代語法circle[radius=<radius>])。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

Attempt 1 slightly modified:

\begin{center}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1.3,1.5);
\draw let \p1=($(b)-(a)$),\n1={veclen(\x1,\y1)} in (a) circle[radius=\n1] ;
\end{tikzpicture}
\end{center}


\begin{center}
\begin{tikzpicture}[]
\coordinate (a) at (0,0);
\coordinate (b) at (1.3,1.5);
% https://tex.stackexchange.com/a/58287
\draw 
  let
  \p1 = (a),
  \p2 = (b),
  \n1 = {veclen((\x2-\x1),(\y2-\y1))} in 
(a) circle[radius={\n1}];
\end{tikzpicture}
\end{center}

\end{document}

答案2

使用 tikzlibrary through,可以輕鬆完成:

\node [draw] at (a) [circle through={(b)}] {};

在此輸入影像描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (-2,-2) grid (2,2);
\node[circle,fill=red,inner sep=1pt] (a) at (0,0){a};
\node[circle,fill=red,inner sep=1pt] (b) at (1.3,1.5){b};

\node [draw,thick] at (a) [circle through={(b)}] {};
\end{tikzpicture}
\end{document}

相關內容