我想创建一个自动计算距离(AB)的圆弧。灵感来自 pgf 手册第 58 页。但代码块% \draw (H) ++arc (15:60: $ (A) ! - ! (B) $);
没有太大帮助。
也就是说,我想要一条从 (B) 经过并以 (A) 为圆心的圆弧。有什么想法吗?
这些答案实际上提供了许多有用的信息,但我无法弄清楚。 如何计算 TikZ 中两个坐标之间的距离?和TikZ:在两个坐标之间画一条弧?
\documentclass[b5paper,11pt]{book}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,calc,intersections,through,backgrounds}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.25]%,cap=round,>=latex]
\draw[step=.5cm,gray,very thin] (-2.0cm,-2.0cm) grid (2.cm,2.0cm);
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=right:$C$] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\draw (A) -- node[above] {$g$} (B) -- node[right] {$a$} (C) -- node[below] {$b$} (A);
\filldraw [ color = green!10!white, draw=green!10!black] (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
% \draw (H) ++arc (15:60: $ (A) ! - ! (B) $);
\draw (5:2cm) arc(15:60:2cm);
\end{tikzpicture}
\end{center}
\end{document}
作为最终结果,我想创建类似这样的内容
答案1
首先,您可以使用 calc 库,通过使用语法的角度参数使虚线斜边稍微旋转($(node1)!fraction!angle:(node2)$)
。这意味着路径将从 A 绘制到 B,但随后将旋转angle
度数。
然后,您可以使用let
操作并计算距离和角度。然后您可以使用它来形成一个必须从 经过(B)
并旋转 的圆弧(B)
。
\documentclass[b5paper,11pt]{book}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,calc,intersections,through,backgrounds}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.25]%,cap=round,>=latex]
\draw[step=.5cm,gray!50,very thin] (-2.0cm,-2.0cm) grid (2.cm,2.0cm);
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\draw (A) -- node[above] {$g$} (B) -- node[right] {$a$} (C) -- node[below] {$b$} (A);
\filldraw [fill = green!10!white,
draw=green!10!black] (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\draw[dashed] (A)-- ($ (A)!1!-10:(B)$) |- (A);
\draw let % We initiate a let operation inside a path
\p1=($(B)-(A)$), % Declare a vector from A to B
\n1={veclen(\x1,\y1)}, % Compute it's length, let's call it "l"
\n2={atan2(\x1,\y1)} % Compute it's angle with respect to A, say theta
in % finish off the \p and \n register declaration
(A) ++(\n2-15:\n1) % Move from A to a point in polar form (theta-15:l)
arc (\n2-15:\n2+15:\n1) % Draw an arc from that point that covers
% 30 degrees with a start angle of theta-15
(A) ++(5mm,0) arc (0:\n2:5mm) % goes back to A and moves horizontally
% to start an arc theta angle
(A) node at ++(\n2/2:7mm) {$\theta$}; % goes again to (A) and places label
\end{tikzpicture}
\end{center}
\end{document}
答案2
这是一份有多种可能性的好工作tkz-euclide
。
最好是第一个\draw[dashed] (A)-- ($ (A)!1!-10:(B)$) |- (C);
(C 而不是 A)用tkz-euclide
标记表示直角
\tkzMarkRightAngle[fill=green!20](A,C,B)
我们可以用 得到圆弧\tkzCompasss[color = blue,delta = 15](A,B)
。我们在 B 前后 15 度处画一个以 A 为圆心、经过 B 的圆弧
\documentclass[11pt]{article}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{decorations.markings,calc,intersections,through,backgrounds}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.25]
\draw[step=.5cm,gray!50,very thin] (-2.0cm,-2.0cm) grid (2.cm,2.0cm);
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\draw (A) -- node[above](g) {$g$} (B)
-- node[right] {$a$} (C)
-- node[below] {$b$} (A);
\tkzMarkRightAngle[fill=green!20](A,C,B)
\draw[dashed] (A)-- ($ (A)!1!-10:(B)$) |- (C);
% \tkzCompasss[color = orange,length = 2](A,B)
\tkzCompasss[color = blue,delta = 15](A,B)
% \tkzDrawArc[delta=15](A,B)(B)
% \tkzCalcLength[cm](A,B)\tkzGetLength{rAB}
% \node [above=0.5cm,font=\small] at (g) { \rAB cm};
\end{tikzpicture}
\end{center}
\end{document}
和
\tkzCompasss[color = orange,length = 2](A,B)
我定义了弧的长度
另一种可能性是使用更通用的宏\tkzDrawArc
\tkzDrawArc[delta=15](A,B)(B)
这是宏的特殊用法,因为我画了一个以 A 为中心从 B 到 B 的圆弧,但我定义delta = 15
要延长该圆弧。
现在每个宏都会计算长度 AB。可以使用以下命令知道该长度:
\tkzCalcLength[cm](A,B)\tkzGetLength{rAB}
\node [above=0.5cm,font=\small] at (g) { \rAB cm};
答案3
使用 PSTricks:
方法 1(使用曲线横坐标)
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\addtopsstyle{gridstyle}{gridlabels=0pt,griddots=0}
\begin{document}
\begin{pspicture}[showgrid](-2,-2)(2,2)
\pstGeonode[PosAngle={180,45,-90}]
(-1.5,-1){A}
(1.5,1){B}
(1.5,-1){C}
\pstRightAngle[RightAngleSize=0.2,fillstyle=solid,fillcolor=green!50]{A}{C}{B}
\pstArcOAB[arcsepB=-1,arcsepA=-2.5]{A}{B}{B}
\pstCurvAbsNode[CurvAbsNeg=true,PointName=none]{A}{B}{D}{\pstDistVal{.75}}
\psline[linestyle=dashed](A)(D)(D|C)(C)
\psset{shortput=nab,labelsep=-3pt}
\ncline{A}{B}^{$g$}
\ncline{B}{C}^{$a$}
\ncline{C}{A}^{$b$}
\end{pspicture}
\end{document}
方法 2(使用 PostScriptPyth2
运算符)
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\addtopsstyle{gridstyle}{gridlabels=0pt,griddots=0}
\psset{saveNodeCoors}
\begin{document}
\begin{pspicture}[showgrid](-2,-2)(2,2)
\pstGeonode[PosAngle={180,45,-90}]
(-1.5,-1){A}
(1.5,1){B}
(1.5,-1){C}
\pstRightAngle[RightAngleSize=0.2,fillstyle=solid,fillcolor=green!50]{A}{C}{B}
\pstVerb{/Dist {N-A.x N-A.y N-B.x N-B.y Pyth2} def}%
\pnode[A](!Dist 21 PtoC){D}\psdots(D)
\psarc[origin={A},arcsep=-1](A){!Dist}{(D)}{(B)}
\psline[linestyle=dashed](A)(D)(D|C)(C)
\psset{shortput=nab,labelsep=-3pt}
\ncline{A}{B}^{$g$}
\ncline{B}{C}^{$a$}
\ncline{C}{A}^{$b$}
\end{pspicture}
\end{document}
方法 3(旋转)
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\addtopsstyle{gridstyle}{gridlabels=0pt,griddots=0}
\begin{document}
\begin{pspicture}[showgrid](-2,-2)(2,2)
\pstGeonode[PosAngle={180,45,-90}]
(-1.5,-1){A}
(1.5,1){B}
(1.5,-1){C}
\pstRightAngle[RightAngleSize=0.2,fillstyle=solid,fillcolor=green!50]{A}{C}{B}
\pstRotation[PointName=none,RotAngle=-12]{A}{B}[D]
\pstArcOAB[arcsep=-1]{A}{D}{B}
\psline[linestyle=dashed](A)(D)(D|C)(C)
\psset{shortput=nab,labelsep=-3pt}
\ncline{A}{B}^{$g$}
\ncline{B}{C}^{$a$}
\ncline{C}{A}^{$b$}
\end{pspicture}
\end{document}
方法 4(有交集)
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\addtopsstyle{gridstyle}{gridlabels=0pt,griddots=0}
\begin{document}
\begin{pspicture}[showgrid](-2,-2)(2,2)
\pstGeonode[PosAngle={180,45,-90}]
(-1.5,-1){A}
(1.5,1){B}
(1.5,-1){C}
\pstRightAngle[RightAngleSize=0.2,fillstyle=solid,fillcolor=green!50]{A}{C}{B}
\pnode[A](1;21){D'}
\pstInterLC{A}{D'}{A}{B}{E}{D}% E is not used but we have to provide a name for it!
\pstArcOAB[arcsep=-1]{A}{D}{B}
\psline[linestyle=dashed](A)(D)(D|C)(C)
\psset{shortput=nab,labelsep=-3pt}
\ncline{A}{B}^{$g$}
\ncline{B}{C}^{$a$}
\ncline{C}{A}^{$b$}
\end{pspicture}
\end{document}
红色警报:为了简单起见,我将给D
定方法中的节点留得稍有不同。使它们相同并不难。