我正在尝试创建一个函数,给定两条路径,绘制出它们所有共同切线。
更具体地说,我试图绘制两个椭圆的公切线,以便它看起来像圆锥或圆柱的投影视图。像这样:
我尝试过的:我在这里关注了另一篇文章,给定一个点绘制路径的切线,这样,我可以手动选择第二条路径上看起来像切线的点,但是我怎样才能自动并真正正确地做到这一点? 我不太熟悉运算whatever
符或 MetaFontsolve
宏,但我想我可以将它们用作答案。
函数主体如下:
pair T,V,X,Y; path P,W;
P:=fullcircle scaled 100; W:=fullcircle scaled 200 shifted (400,100);
T:= point 2.5 of W; %Hand picked point on path W
V:= point 6 of W; %Hand picked point on path W
draw P withpen pencircle scaled 10;
draw W withpen pencircle scaled 10;
vardef f(expr t) = angle direction t of P - angle (T - point t of P) < eps enddef;
X = point solve f (11, 10) of P;
Y = point solve f (9, 14.5) of P;
draw X -- T withpen pencircle scaled 5 withcolor red;
draw Y -- V withpen pencircle scaled 5 withcolor red;
这就导致了上述结果。
编辑:为了更清楚起见,我正在寻找通用曲线不仅仅是圆形,例如:
答案1
我不认为任意贝塞尔曲线的切线从几何角度来看非常简单。但这里有一个玩具示例,可以作为起点。
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
path a, b;
a = origin .. (40, 20) .. (80, -30) .. (50, -60);
b = (50, 90) .. (90, 50) .. (200, 20) .. (240, 50);
for t = 0 step 1/64 until length a:
numeric u; u = directiontime direction t of a of b;
if u > 0:
numeric aa;
aa = abs(angle direction t of a - angle (point u of b - point t of a));
if aa < 1:
draw point t of a -- point u of b withcolor 3/4 red;
fi
fi
endfor
drawarrow a;
drawarrow b;
endfig;
\end{mplibcode}
\end{document}
编译此文件lualatex
可获得如下 PDF: