3

I'm trying to make a function that given 2 paths would draw all the lines that are common tangents of them.

More specifically I was trying to draw the common tangent of 2 ellipses so that it would look like a projected view of a cone or a cylinder. Something like this:

enter image description here

What I've tried: I followed another post here that given a point drew the tangent of a path, With that, I can manually pick a point on the second path that looks like the tangent, but how can I do it automatically and actually correct? I'm not very familiar with the whatever operator or the MetaFont solve macro but I think I could use them as an answer.

The body of the function would have something like this:

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;

Which led to the result above.

Edit: To make myself more clear, I'm looking for the tangent of a generic curve and not only circles, example:

enter image description here

1 Answers1

5

I don't think tangents to arbitrary Bezier curves is very easy geometrically. But here is a toy example that might provide a starting point.

\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}

Compile this with lualatex to get a PDF that looks like this:

enter image description here

Thruston
  • 42,268
  • Perfect!!! I imagined that it would have to be done by brute force I'm just not familiar with MetaPost syntax! Btw thanks for the answer in the other post, it helped me ask this one properly! – Thiago Brawerman Aug 30 '23 at 22:01
  • One other thing, I'm very new here, do I have to close this question now that it has been answered? and how do I do this lol? – Thiago Brawerman Aug 30 '23 at 22:04
  • Welcome to Tex.SE. You might like to read this. Particularly the third bullet. – Thruston Aug 30 '23 at 22:25