Skip to content

Instantly share code, notes, and snippets.

@dohyunkim
Last active December 17, 2025 03:06
Show Gist options
  • Select an option

  • Save dohyunkim/1768aaeda7678b379e2a8b312475fffb to your computer and use it in GitHub Desktop.

Select an option

Save dohyunkim/1768aaeda7678b379e2a8b312475fffb to your computer and use it in GitHub Desktop.
\documentclass{article}
\usepackage{luamplib}
\begin{document}
\mpfig % version 0.3 2025/12/16 21:00
u:=100; % 그리기 용도. 계산만 하려면 1.
path A, B; numeric ra, rb; pair ca, cb;
cb = (1u,9u+rb);
ca = (1u,9u-rb-ra);
ra = 1u;
rb = u/4;
A = fullcircle scaled 2ra shifted ca;
B = fullcircle scaled 2rb shifted cb;
draw A; draw B;
% See \emph{Drawing with Metapost} by Toby Thurston, \S 9.12. (texdoc drawing-with-metapost)
path C, H; numeric t;
C = fullcircle scaled 2(ra-rb) shifted ca;
H = halfcircle zscaled (cb-ca) shifted 1/2[ca,cb];
(t , whatever) = C intersectiontimes H ;
show point t of A, point t of B;
draw point t of A -- point t of B withpen pencircle scaled 1 withcolor red;
\endmpfig
\newpage
\mpfig % version 0.2
draw A; draw B;
% 닮음꼴의 중심 z0를 구한다. 두 원의 같은 지점을 잇는 선들의 교점.
z0 = whatever[point 2 of A, point 2 of B] = whatever[point 4 of A, point 4 of B];
% 또는 z0를 알아내는 계산을 수행할 수도 있다.
% numeric d;
% d / ra = abs(ca-cb) / (ra-rb) ;
% z0 = d * unitvector(cb-ca) shifted ca ;
% z0에서 원A, B의 중심까지 거리을 지름으로 하는 반원을 각각 그린다.
% 반대편 접선을 구하려면 각각 ca-z0, cb-z0.
path ta,tb;
ta = halfcircle zscaled (z0-ca) shifted 1/2[z0,ca];
tb = halfcircle zscaled (z0-cb) shifted 1/2[z0,cb];
% 원 A, B와 새로운 원이 만나는 점을 각각 구한다.
z2 = ta intersectionpoint A;
z1 = tb intersectionpoint B;
show z2,z1;
draw z2--z1 withpen pencircle scaled 1 withcolor red;
\endmpfig
\newpage
\mpfig % version 0.1
draw A; draw B;
vardef f (expr t) =
pair va, vb;
va = direction t of A;
vb = point t of A - point t of B;
if angle va * angle vb < 0 :
angle va < angle -vb
else :
angle va < angle vb
fi
enddef;
tolerance := 0.001;
t := solve f(2,4);
show point t of A, point t of B;
draw point t of A -- point t of B withpen pencircle scaled 1 withcolor red;
\endmpfig
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment