来自我的帖子TikZ:通过两点绘制椭圆,我尝试为不同的弧复制该过程,但它没有按预期工作。问题是我不太了解下面的代码。
\draw[postaction = decorate] let
\p0 = ($(B) - (F)$),
\p1 = ($(A) - (B)$)
in (B|-A) ++(\x1, 0) arc(45:135:\x1 and \y0);
在做什么(B|-A)
?为什么要减分。
我正在尝试将(A)连接到(B)。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, decorations.markings, calc, arrows}
\begin{document}
\begin{tikzpicture}[line join = round, line cap = round, >=triangle 45,
every label/.append style = {font = \scriptsize},
dot/.style = {inner sep = +0pt, shape = circle,
draw = black, label = {#1}},
small dot/.style = {minimum size = .05cm, dot = {#1}},
big dot/.style = {minimum size = .1cm, dot = {#1}},
]
\pgfmathsetmacro{\as}{3}
\pgfmathsetmacro{\bs}{2.25}
\pgfmathsetmacro{\c}{sqrt(\as^2 - \bs^2)}
\pgfmathsetmacro{\al}{3.75}
\pgfmathsetmacro{\bl}{sqrt(\al^2 - \c^2)}
\coordinate (O) at (0, 0);
\node[fill = black, big dot = {below left: \(F\)}] (F) at (\c, 0) {};
\path[name path = line1] (\c, 0) -- ++(45:{\as} and \bs);
\path[name path = line2] (\c, 0) -- ++(135:5cm and 5cm);
\path[name path = ell1] (O) ellipse
(\as cm and \bs cm);
\path[name path = ell2] (O) ellipse
(\al cm and \bl cm);
\path[name intersections = {of = line1 and ell1, by = P1}];
\node[fill = black, big dot = {above right: \(A\)}] (A) at (P1) {};
\path[name intersections = {of = line2 and ell2, by = P2}];
\node[fill = black, big dot = {above right: \(B\)}] (B) at (P2) {};
\draw[blue] (F) -- (A);
\draw[red] (F) -- (B) node[scale = .75, fill = white, inner sep = 0cm,
pos = .5] {\(r_B\)};
\begin{scope}[decoration = {markings,
mark = at position 0.5 with {\arrow{>}},
} ]
\draw[postaction = decorate] let
\p0 = ($(B) - (F)$),
\p1 = ($(A) - (B)$)
in (B|-A) ++(\x1, 0) arc(45:135:\x1 and \y0);
\end{scope}
\end{tikzpicture}
\end{document}
编辑2:
按照 Qrrbrbirlbel 的解决方案,我得到了正确的数字,但是我收到了错误并且我无法弄清楚:
ERROR: Undefined control sequence.
--- TeX said ---
\tikz@intersect@namedpaths ...name@f'Circle-\solA
\endcsname {\pgfsyssoftpat...
l.108 {\(\nu_B\)};
--- HELP ---
TeX encountered an unknown command name. You probably misspelled the
name. If this message occurs when a LaTeX command is being processed,
the command is probably in the wrong place---for example, the error
can be produced by an \item command that's not inside a list-making
environment. The error can also be caused by a missing \documentclass
command.
我使用的代码是:
\documentclass[tikz]{standalone}
\usetikzlibrary{intersections, decorations.markings, calc, arrows, backgrounds}
\begin{document}
\tikzset{circle with radius/.style = {shape = circle, inner sep = 0pt,
outer sep = 0pt, minimum size = {2 * (#1)}}}
\begin{tikzpicture}[line join = round, line cap = round, >=triangle 45,
every label/.append style = {font = \scriptsize},
dot/.style = {inner sep = +0pt, shape = circle,
draw = black, label = {#1}},
small dot/.style = {minimum size = .05cm, dot = {#1}},
big dot/.style = {minimum size = .1cm, dot = {#1}},
]
\pgfmathsetmacro{\as}{3}
\pgfmathsetmacro{\bs}{2.25}
\pgfmathsetmacro{\c}{sqrt(\as^2 - \bs^2)}
\pgfmathsetmacro{\al}{3.75}
\pgfmathsetmacro{\bl}{2.9}
\pgfmathsetmacro{\cl}{sqrt(\al^2 - \bl^2)}
\pgfmathsetmacro{\xs}{abs(\c - \cl)}
\coordinate (O) at (0, 0);
\node[fill = black, big dot = {below left: \(F\)}] (F) at (\c, 0) {};
\path[name path global = line1] (\c, 0) -- ++(60:{\as} and \bs);
\path[name path global = line2] (\c, 0) -- ++(150:6cm);
\begin{scope}[decoration = {markings,
mark = at position 0.25 with {\arrow{>}},
mark = at position 0.375 with {\node[draw, shape = circle,
inner sep = .08cm, fill = white, scale = .75] {\(1\)};},
mark = at position 0.75 with {\arrow{>}},
} ]
\draw[postaction = decorate, name path global = ell1, blue] (O) ellipse
(\as cm and \bs cm);
\end{scope}
\begin{scope}[decoration = {markings,
mark = at position 0.25 with {\arrow{>}},
mark = at position 0.45 with {\node[draw, shape = circle,
inner sep = .08cm, fill = white, scale = .75] {\(2\)};},
mark = at position 0.75 with {\arrow{>}},
},
on background layer]
\draw[postaction = decorate, name path global = ell2, red] (-\xs, 0)
ellipse (\al cm and \bl cm);
\end{scope}
\path[name intersections = {of = line1 and ell1, by = P1}];
\node[fill = black, big dot = {right: \(A\)}] (A) at (P1) {};
\path[name intersections = {of = line2 and ell2, by = P2}];
\node[fill = black, big dot = {above: \(B\)}] (B) at (P2) {};
\draw[blue] (F) -- (A);
\draw[red] (F) -- (B) node[scale = .75, fill = white, inner sep = 0cm,
pos = .5] {\(r_B\)};
\begin{scope}[on background layer]
\draw[dashed, -latex] ($(-\al , 0) - (1, 0)$) -- ($(\al, 0) + (.5, 0)$)
coordinate (P3);
\draw[dashed, -latex] ($(F) - (0, 3)$) -- ($(F) + (0, 3)$);
\end{scope}
\begin{scope}[declare function = {doubleA = 7cm;}]
\begin{pgfinterruptboundingbox}
\path let
\p1 = ($(A) - (F)$),
\p2 = ($(B) - (F)$),
\n1 = {veclen(\x1, \y1)},
\n2 = {veclen(\x2, \y2)}
in
(A) node[name path global = aCircle, circle with radius = doubleA-\n1] {}
(B) node[name path global = bCircle, circle with radius = doubleA-\n2] {}
(F) node[name path global = fCircle, circle with radius = .5 * doubleA]
{};
\tikzset{name intersections = {of = aCircle and bCircle, name = F',
}}
\foreach \solA in {1, 2} {
\path ($(F)!.5!(F'-\solA)$) coordinate (C'-\solA)
($(C'-\solA)!doubleA/2!(F)$) coordinate (xDir-\solA)
(F'-\solA) node[name path global = f'Circle-\solA,
circle with radius = .5 * doubleA] {};
} %!?
\foreach \solA in {1, 2} { %!?
\path[name intersections = {of = fCircle and f'Circle-\solA,
by = {yDir-\solA}}]
($(xDir-\solA)-(C'-\solA)$) coordinate (xDir'-\solA)
($(yDir-\solA)-(C'-\solA)$) coordinate (yDir'-\solA)
;
}
\end{pgfinterruptboundingbox}
\foreach \solA in {1, 2}
\draw[x = (xDir'-\solA), y = (yDir'-\solA)] (C'-\solA) circle [radius = 1];
\end{scope}
\draw[on background layer, red] let
\p0 = (F),
\p1 = (B),
\p2 = (P3),
\n1 = {atan2(\x1 - \x0, \y1 - \y0)},
\n2 = {atan2(\x2 - \x0, \y2 - \y0)},
\n3 = {.75cm},
\n4 = {(\n2 + \n1) / 2}
in (F) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
node[font = \tiny, fill = white, inner sep = 0cm] at ([shift = (F)] \n4:\n3)
{\(\nu_B\)};
\draw[blue] let
\p0 = (F),
\p1 = (A),
\p2 = (P3),
\n1 = {atan2(\x1 - \x0, \y1 - \y0)},
\n2 = {atan2(\x2 - \x0, \y2 - \y0)},
\n3 = {.5cm},
\n4 = {(\n2 + \n1) / 2}
in (F) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
node[font = \tiny, fill = white, inner sep = 0cm] at
([shift = (F)] \n4:.75cm) {\(\nu_A\)};
\end{tikzpicture}
\end{document}
答案1
这里有一个想法,可以得到一个焦点F
经过点A
和的椭圆B
。我冒昧地假设了
2A= 7 厘米
,其中A是椭圆长轴的长度。
根据我记得的关于椭圆的信息,这也是椭圆上一个点与两个焦点之间的距离之和。我们可以用这个来得到两个可能的焦点F'1和F'2。
为了在 TikZ 中做到这一点,我使用calc
语法let … in
来找到给定焦点和点之间的长度,然后我在这些点周围放置节点,并使用这两个点的其余部分A。这intersection cs
有助于找到焦点。椭圆弧的中心就在这两个焦点的中间,我们发现C “”。
从这个中心我们可以找到X,大轴指向的点(也是X旋转椭圆的轴);再次calc
来救援:($(C')!doubleA/2!(F)$)
。
现在我们可以做一些有趣的计算A以及线性偏心率b,小轴的长度,但这是数学 PGF 不能没有帮助。但如果我没记错的话,坐标是小轴指向与两个焦点距离相等的点;即A。那么,让我们画出圆圈F和F'并intersection cs
再次使用。
该坐标X和是xDir
在下面的 TikZ 解决方案中,和被定义yDir
。我们可以使用它们来安装一个局部坐标系,该坐标系的轴恰好与椭圆的轴相同。半径为 1 的圆就是我们搜索的椭圆(或您寻找其部分的整个圆弧)。
由于圆形辅助节点确实改变了边界框,我将这些计算放在pgfinterruptboundingbox
环境中并将向量保存在xDir'
和中yDir'
。
然后可以简单地绘制一个椭圆
\draw[x=(xDir'),y=(yDir')] (C') circle [radius=1];
我在这里使用了intersection cs
,因为它更容易维护(并且你可以在一个路径上完成所有操作。使用intersections
库也可以实现同样的效果。
C'-2
但是,出于某种原因,当您想要命名节点路径并在同一个循环中找到它的交点时,TikZ 会弄乱第二个中心 () 的位置(注释掉!?
带有标记的行)。但是,将其分成两个循环将产生正确的结果:
代码(intersections
库)
\begin{scope}[declare function={doubleA=7cm;}]
\begin{pgfinterruptboundingbox}
\path let \p1=($(A)-(F)$), \p2=($(B)-(F)$), \n1={veclen(\x1,\y1)},\n2={veclen(\x2,\y2)} in
(A) node[name path=aCircle, circle with radius=doubleA-\n1] {}
(B) node[name path=bCircle, circle with radius=doubleA-\n2] {}
(F) node[name path=fCircle, circle with radius=.5*doubleA] {};
\tikzset{name intersections={of=aCircle and bCircle,name=F',by={[big dot=below:$F'_1$],[big dot=below:$F'_2$]}}}
\foreach \solA in {1,2} {
\path ($(F)!.5!(F'-\solA)$) coordinate[big dot=$C'_\solA$] (C'-\solA)
($(C'-\solA)!doubleA/2!(F)$) coordinate[big dot=right:$x_\solA$] (xDir-\solA)
(F'-\solA) node[name path global=f'Circle-\solA, circle with radius=.5*doubleA] {};
} %!?
\foreach \solA in {1,2} { %!?
\path[name intersections={of=fCircle and f'Circle-\solA,by={[big dot=above right:$y_\solA$]yDir-\solA}}]
($(xDir-\solA)-(C'-\solA)$) coordinate (xDir'-\solA)
($(yDir-\solA)-(C'-\solA)$) coordinate (yDir'-\solA)
;
}
\end{pgfinterruptboundingbox}
\foreach \solA in {1,2}
\draw[x=(xDir'-\solA),y=(yDir'-\solA)] (C'-\solA) circle [radius=1];
\end{scope}
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{intersections, decorations.markings, calc, arrows}
\tikzset{circle with radius/.style={shape=circle, inner sep=+0pt, outer sep=+0pt, minimum size={2*(#1)}}}
\begin{document}
\begin{tikzpicture}[line join = round, line cap = round, >=triangle 45,
every label/.append style = {font = \scriptsize},
dot/.style = {inner sep = +0pt, shape = circle, draw = black, label = {#1}},
small dot/.style = {minimum size = .05cm, dot = {#1}},
big dot/.style = {minimum size = .1cm, dot = {#1}},
]
\pgfmathsetmacro{\as}{3} \pgfmathsetmacro{\bs}{2.25}
\pgfmathsetmacro{\c}{sqrt(\as^2 - \bs^2)}
\pgfmathsetmacro{\al}{3.75}
\pgfmathsetmacro{\bl}{sqrt(\al^2 - \c^2)}
\coordinate (O) at (0,0); \node[fill = black, big dot = {below left: \(F\)}] (F) at (\c, 0) {};
\path[name path = line1] (\c, 0) -- ++(45:{\as} and \bs);
\path[name path = line2] (\c, 0) -- ++(135:5cm and 5cm);
\path[name path = ell1] (O) ellipse (\as cm and \bs cm);
\path[name path = ell2] (O) ellipse (\al cm and \bl cm);
\path[name intersections = {of = line1 and ell1, by = P1}];
\node[fill = black, big dot = {above right: \(A\)}] (A) at (P1) {};
\path[name intersections = {of = line2 and ell2, by = P2}];
\node[fill = black, big dot = {above right: \(B\)}] (B) at (P2) {};
\draw[blue] (F) -- (A);
\draw[red] (F) -- (B) node[scale = .75, fill = white, inner sep = 0cm, pos = .5] {\(r_B\)};
\begin{scope}[declare function={doubleA=7cm;}]
\foreach \solA in {1,2} {
\begin{pgfinterruptboundingbox}
\path let \p1=($(A)-(F)$), \p2=($(B)-(F)$), \n1={veclen(\x1,\y1)},\n2={veclen(\x2,\y2)} in
(A) node[circle with radius=doubleA-\n1] (aCircle) {}
(B) node[circle with radius=doubleA-\n2] (bCircle) {}
(intersection cs: first node=aCircle, second node=bCircle, solution=\solA) coordinate[big dot=below:$F'_\solA$] (F')
($(F)!.5!(F')$) coordinate[big dot=$C'_\solA$] (C')% the center of the arc
($(C')!doubleA/2!(F)$) coordinate[big dot=right:$x_\solA$] (xDir)
(F) node[circle with radius=.5*doubleA] (fCircle) {}
(F') node[circle with radius=.5*doubleA] (f'Circle) {}
(intersection cs: first node=fCircle, second node=f'Circle, solution=1) coordinate[big dot=above right:$y_\solA$] (yDir)
($(xDir)-(C')$) coordinate (xDir')
($(yDir)-(C')$) coordinate (yDir')
;
\end{pgfinterruptboundingbox}
\draw[x=(xDir'),y=(yDir')] (C') circle [radius=1];
}
\end{scope}
\end{tikzpicture}
\end{document}