% https://ask.latexstudio.net/ask/question/18066.html
\documentclass{standalone}
\usepackage[3d]{luadraw}
\usepackage[svgnames]{xcolor}
\usepackage{fourier-otf}
\begin{document}
\begin{luadraw}{name=cylinder_sphere}
local ld = luadraw
local pt3d = ld.pt3d
local M, Mc, Origin, vecK = pt3d.M, pt3d.Mc, pt3d.Origin, pt3d.vecK
local g = ld.graph3d:new{
window3d = {-5,5,-5,5,-5,5},
window = {-5,5,-5,5},
-- adjust2d = true,
viewdir = {0,80} -- should be fixed
}
require 'luadraw_spherical'
local sM = ld.sM
ld.Hiddenlines = true;ld.Hiddenlinestyle = "dashed"
g:Define_sphere{ color = "", edgewidth=10, edgecolor="black" }
local h = 2
local O1,O2 = M(0,0,h),M(0,0,-h)
local r = math.sqrt(3^2-h^2)
local A,B = Mc(r,140*ld.deg,h), Mc(r,45*ld.deg,-h)
g:DScircle({Origin,vecK});g:DScircle({O1,vecK},{width=8});g:DScircle({O2,vecK},{width=8})
g:Dcylinder(O1,r,O2,{color="violet!75", edgestyle="noline",hiddenstyle="noline"}) -- hide the frustum border and hidden lines
local M1, N1, M2, N2 = table.unpack(g:Cylinder_tangency(O1, r, O2)) -- get the tangency points of the cylinder
g:DSpolyline({{M1,M2},{N1,N2}},{width=8}) -- draw the
--
g:Dspherical()
g:Dangle3d(A,O1,O2,0.3,"very thick")
g:Dpolyline3d({B,Origin,A,O1,O2},"blue,dashed,thick")
g:Dballdots3d({Origin,O1,O2,A,B},"red",0.75)
g:Dlabel3d(
"$O$",Origin,{pos="W"},
"$h$",O2/4,{},
"$O_1$",O1,{},
"$O_2$",O2,{},
"$A$",A,{pos="NE"},
"$B$",B,{pos="SE"},
"$r$",(O1+A)/2,{pos="S",node_options="text=red"},
"$h/2$",O1/2,{pos="W"},
"$R$",3*A/5,{pos="E"}
)
g:Show()
\end{luadraw}
\end{document}