Skip to content

Come posso disegnare correttamente questi coni senza che la base superi le linee?

Il nostro gruppo di scrittura ha cercato a lungo di risolvere le tue ricerche, ti diamo le risposte in modo che il nostro desiderio sia di essere molto utile.

Soluzione:

Non è troppo difficile calcolare l'angolo di intersezione a partire dai vostri input.

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
begin{document}
begin{tikzpicture}[fill opacity=0.2,text opacity=1]
    defh{2}
    defr{2}
    defp{0.5}
    % compute the aspect of the cylinder/cone
    pgfmathsetmacro{mytheta}{atan2(p,r)}
    % compute the critical angle at which the mantle intersects the base
    pgfmathsetmacro{alphacrit}{90-acos(p/h)}%
    % lower cone
    path (0,h) + (-alphacrit:r cm and p cm) coordinate (br)
    (0,h) + (180+alphacrit:r cm and p cm) coordinate (bl);
    draw[left color=gray!50!black, right color=gray!50!black, middle color=gray!50,
      line width = 0.6pt] 
      (bl) arc[start angle=180+alphacrit,end angle=360-alphacrit,
        x radius=r*1cm,y radius=p*1cm]
     -- (0,0) -- cycle;
    % cylinder base
    fill[gray] (0,h) circle[x radius=r,y radius=p];
    draw[dashed,line width = 0.6pt] (r,h) 
    arc[start angle=0,end angle=180,x radius=r*1cm,y radius=p*1cm];
    fill[fill=black,fill opacity=1] (0,h) circle[radius=1.2pt];
    % cylinder mantle
    draw[line width = 0.6pt,left color=gray!50!black, right
        color=gray!50!black, middle color=gray!50]
     (r,h) arc[start angle=0,end angle=-180,x radius=r*1cm,y radius=p*1cm]
     -- (-r,3*h)  arc[start angle=180,end angle=360,x radius=r*1cm,y radius=p*1cm] 
     -- cycle;
    % cylinder top
    fill[gray] (0,3*h) circle[x radius=r,y radius=p];
    draw[dashed,line width = 0.6pt] (r,3*h) 
     arc[start angle=0,end angle=180,x radius=r*1cm,y radius=p*1cm];
    fill[fill=black,fill opacity=1] (0,3*h) circle[radius=1.2pt];
    % upper cone
    path (0,3*h) + (alphacrit:r cm and p cm) coordinate (tr)
    (0,3*h) + (180-alphacrit:r cm and p cm) coordinate (tl);
    draw[left color=gray!50!black, right color=gray!50!black, middle color=gray!50,
      line width = 0.6pt] 
      (tl) arc[start angle=180-alphacrit,end angle=360+alphacrit,
      x radius=r*1cm,y radius=p*1cm]
     -- (0,4*h) -- cycle;
    % annotations 
    draw[|-|] (r+0.3,0) -- node[right] {$1.5$} (r+0.3,h);
    draw[|-|] (-r-0.3,h) -- node[left] {$3.0$} (-r-0.3,3*h);
    draw[|-|] (r+0.3,3*h) -- node[right] {$1.5$} (r+0.3,4*h);
    draw[dashed] (0,3*h) -- node[above=-1.5pt] {$1.5$} (r,3*h);
end{tikzpicture}
end{document}

enter image description here

C'è la possibilità che il mio altro post su questo sia sbagliato...

È abbastanza flessibile fare pic con il seguente tipo di pgfkeys (merito di chi? del gatto di Schrodinger?)

tikzset{pics/ZZZZZ/.style={code={
tikzset{ZZZZZ/.cd,#1}
defpv##1{pgfkeysvalueof{/tikz/ZZZZZ/##1}}%
 .....

Questo è il mio primo tentativo. Il codice per pic cylinder è diretto.

begin{tikzpicture}[thick]
path 
(0,0) pic[brown]{cylinder}
(7,0) pic[cyan]{cylinder={major=3,minor=.75,height=4}};
end{tikzpicture}

enter image description here

Per la foto cone, aggiungo la chiave booleana upside down tramite il confronto booleano newififupsidedown con l'impostazione

upside down/.initial=false, % Initially, cylinder is upside
upside down/.is if=upsidedown

enter image description here

begin{tikzpicture}[thick]
path 
(0,0) pic[blue]{cone}
(7,0) pic[red]{cone={major=3,minor=.75,height=2.5,upside down=true}};
end{tikzpicture}

Ecco l'immagine finale.

enter image description here

Il codice completo è il seguente.

documentclass[tikz,border=5mm]{standalone}
begin{document}
%%%%%%%% CYLINDER %%%%%%%%%%%%%%%%%%%%%
tikzset{pics/cylinder/.style={code={
tikzset{cylinder/.cd,#1}
defpv##1{pgfkeysvalueof{/tikz/cylinder/##1}}%
draw[fill=white] 
(pv{major},pv{height})--(pv{major},0) 
arc(0:-180:{pv{major}} and {pv{minor}})
--(-pv{major},pv{height}) 
arc(180:-180:{pv{major}} and {pv{minor}});
draw[dashed] 
(pv{major},0) arc(0:180:{pv{major}} and {pv{minor}});
}},
cylinder/.cd,
major/.initial=1.5,
minor/.initial=.7,
height/.initial=3,
}% end of the pic: cylinder 
%%%%%%%% CONE %%%%%%%%%%%%%%%%%%%%%%%%%
newififupsidedown
tikzset{pics/cone/.style={code={
tikzset{cone/.cd,#1}
defpv##1{pgfkeysvalueof{/tikz/cone/##1}}%
pgfmathsetmacro{t}{asin(pv{minor}/pv{height})}
ifupsidedown
draw 
(-t:{pv{major}} and {pv{minor}})--(0,-pv{height})--(180+t:{pv{major}} and {pv{minor}})
(pv{major},0) arc(0:360:{pv{major}} and {pv{minor}});
else
draw[fill=white] 
(t:{pv{major}} and {pv{minor}})--(0,pv{height})--(180-t:{pv{major}} and {pv{minor}})
arc(180-t:360+t:{pv{major}} and {pv{minor}});
draw[dashed] 
(t:{pv{major}} and {pv{minor}}) arc(t:180-t:{pv{major}} and {pv{minor}});
fi
}},
cone/.cd,
major/.initial=3,
minor/.initial=1,
height/.initial=3,
upside down/.initial=false,
upside down/.is if=upsidedown
} % end of the pic: cone
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
begin{tikzpicture}[thick]
path 
(0,0) pic[brown]{cylinder}
(7,0) pic[cyan]{cylinder={major=3,minor=.75,height=4}}
;
end{tikzpicture}
begin{tikzpicture}[thick]
path 
(0,0) pic[blue]{cone}
(7,0) pic[red]{cone={major=3,minor=.75,height=2.5,upside down=true}}
;
end{tikzpicture}
begin{tikzpicture}
defa{1.5} defb{.5} defhcy{3} defhco{1.5}
path[thick] 
(0,0)
pic{cone={major=a,minor=b,height=hco,upside down=true}}
pic{cylinder={major=a,minor=b,height=hcy}}
(0,3)
pic{cone={major=a,minor=b,height=hco}}
;

% for legends
begin{scope}[magenta,nodes={midway,scale=.8}]
draw[dashed] (a,hcy)--(0,hcy) node[above]{1.5};
draw[|-|] (a+.3,hcy)--+(90:hco) node[right]{1.5};
draw[|-|] (a+.3,0)--+(-90:hco) node[right]{1.5};
draw[|-|] (-a-.3,0)--+(90:hcy) node[left]{3};
fill (0,0) circle(1.5pt) (0,hcy) circle(1.5pt);       
end{scope}
end{tikzpicture}
end{document}

Potete provare questo codice

documentclass[12pt,a4paper,border=2mm]{standalone}
usepackage{tikz, tikz-3dplot}
usetikzlibrary{calc,backgrounds}
usepackage{pgfplots}
begin{document}
    pgfmathsetmacroth{70}
    pgfmathsetmacroaz{70}
    tdplotsetmaincoords{th}{az}
pgfmathsetmacroh{3} %height of cylinder
    pgfmathsetmacroR{3} %radius of base
    pgfmathsetmacrov{h + 3} 
    pgfmathsetmacrot{-h} 
    begin{tikzpicture} [scale=1, tdplot_main_coords, axis/.style={blue,thick}]
        path
    (0,0,0) coordinate (O) 
    (0,0,v) coordinate (B) 
    (0,0,t) coordinate (A);
    pgfmathsetmacrocott{{cot(th)}}
    pgfmathsetmacrofraction{R*cott/(v-h)}
    pgfmathsetmacrofractionTwo{R*cott/t}
    pgfmathsetmacrofraction{fraction<1 ? fraction : 1}
    pgfmathsetmacroangle{{acos(fraction)}}
    pgfmathsetmacroangleTwo{{acos(fractionTwo)}}
    pgfmathsetmacroPhiOne{180+(az-90)+angle}
    pgfmathsetmacroPhiTwo{180+(az-90)-angle}
    pgfmathsetmacroPhiOneBis{180+(az-90)+angleTwo}
    pgfmathsetmacroPhiTwoBis{180+(az-90)-angleTwo}
    pgfmathsetmacrosinPhiOne{{sin(PhiOne)}}
    pgfmathsetmacrocosPhiOne{{cos(PhiOne)}}
    pgfmathsetmacrosinPhiTwo{{sin(PhiTwo)}}
    pgfmathsetmacrocosPhiTwo{{cos(PhiTwo)}}
    pgfmathsetmacrosinPhiOneBis{{sin(PhiOneBis)}}
    pgfmathsetmacrocosPhiOneBis{{cos(PhiOneBis)}}
    pgfmathsetmacrosinPhiTwoBis{{sin(PhiTwoBis)}}
    pgfmathsetmacrocosPhiTwoBis{{cos(PhiTwoBis)}}
    pgfmathsetmacrosinazp{{sin(az-90)}}
    pgfmathsetmacrocosazp{{cos(az-90)}}
    pgfmathsetmacrosinazm{{sin(90-az)}}
    pgfmathsetmacrocosazm{{cos(90-az)}}
    %tdplotdrawarc[tdplot_main_coords,thick]{(O)}{R}{PhiOne}{360+PhiTwo}{anchor=north}{}
        draw[dashed] (tdplotmainphi:R) arc(tdplotmainphi:tdplotmainphi+180:R);

        draw[thick] (tdplotmainphi:R)  arc(tdplotmainphi:tdplotmainphi-180:R);

    tdplotdrawarc[tdplot_main_coords,thick]{(0,0,h)}{R}{PhiOne}{360+PhiTwo}{anchor=north}{}
tdplotdrawarc[tdplot_main_coords,dashed]{(0,0,h)}{R}{PhiTwo}{PhiOne}{anchor=north}{}
draw[thick]  ({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},0 ) -- ({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},h );
    draw[thick]  ({R*cos(tdplotmainphi-180)},{R*sin(tdplotmainphi-180)},0 ) -- ({R*cos(tdplotmainphi-180)},{R*sin(tdplotmainphi-180)},h );
    draw[thick] (B) -- (R*cosPhiOne,R*sinPhiOne,h);
    draw[thick] (B) -- (R*cosPhiTwo,R*sinPhiTwo,h);
    draw[thick] (A) -- (R*cosPhiOneBis,R*sinPhiOneBis,0);
draw[thick] (A) -- (R*cosPhiTwoBis,R*sinPhiTwoBis,0);
    foreach p in {O,B,A}
    draw[fill=black] (p) circle (1pt);
    foreach p/g in {O/-45,B/90,A/-90}
    path (p)+(g:3mm) node{$p$};
    draw[dashed]  (A)--(B)    (-R*sinazm,-R*cosazm,0) -- (-R*sinazp,+R*cosazp,0) ;
    end{tikzpicture}
    end{document} 

enter image description here

Si può provare

documentclass[12pt,a4paper,border=2mm]{standalone}
usepackage{tikz, tikz-3dplot}
usetikzlibrary{calc,backgrounds}
usepackage{pgfplots}
begin{document}
    pgfmathsetmacroth{80}
    pgfmathsetmacroaz{70}
    tdplotsetmaincoords{th}{az}
pgfmathsetmacroh{3} %height of cylinder
    pgfmathsetmacroR{8} %radius of base
    pgfmathsetmacrov{h + 3} 
    pgfmathsetmacrot{-8} 
    begin{tikzpicture} [scale=1, tdplot_main_coords, axis/.style={blue,thick}]
        path
    (0,0,0) coordinate (O) 
    (0,0,v) coordinate (B) 
    (0,0,t) coordinate (A);
    pgfmathsetmacrocott{{cot(th)}}
    pgfmathsetmacrofraction{R*cott/(v-h)}
    pgfmathsetmacrofractionTwo{R*cott/t}
    pgfmathsetmacrofraction{fraction<1 ? fraction : 1}
    pgfmathsetmacroangle{{acos(fraction)}}
    pgfmathsetmacroangleTwo{{acos(fractionTwo)}}
    pgfmathsetmacroPhiOne{180+(az-90)+angle}
    pgfmathsetmacroPhiTwo{180+(az-90)-angle}
    pgfmathsetmacroPhiOneBis{180+(az-90)+angleTwo}
    pgfmathsetmacroPhiTwoBis{180+(az-90)-angleTwo}
    pgfmathsetmacrosinPhiOne{{sin(PhiOne)}}
    pgfmathsetmacrocosPhiOne{{cos(PhiOne)}}
    pgfmathsetmacrosinPhiTwo{{sin(PhiTwo)}}
    pgfmathsetmacrocosPhiTwo{{cos(PhiTwo)}}
    pgfmathsetmacrosinPhiOneBis{{sin(PhiOneBis)}}
    pgfmathsetmacrocosPhiOneBis{{cos(PhiOneBis)}}
    pgfmathsetmacrosinPhiTwoBis{{sin(PhiTwoBis)}}
    pgfmathsetmacrocosPhiTwoBis{{cos(PhiTwoBis)}}
    pgfmathsetmacrosinazp{{sin(az-90)}}
    pgfmathsetmacrocosazp{{cos(az-90)}}
    pgfmathsetmacrosinazm{{sin(90-az)}}
    pgfmathsetmacrocosazm{{cos(90-az)}}
            draw[dashed] (tdplotmainphi:R) arc(tdplotmainphi:tdplotmainphi+180:R);

        draw[thick] (tdplotmainphi:R)  arc(tdplotmainphi:tdplotmainphi-180:R);

    tdplotdrawarc[tdplot_main_coords,thick]{(0,0,h)}{R}{PhiOne}{360+PhiTwo}{anchor=north}{}
tdplotdrawarc[tdplot_main_coords,dashed]{(0,0,h)}{R}{PhiTwo}{PhiOne}{anchor=north}{}
draw[thick]  ({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},0 ) -- ({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},h );
    draw[thick]  ({R*cos(tdplotmainphi-180)},{R*sin(tdplotmainphi-180)},0 ) -- ({R*cos(tdplotmainphi-180)},{R*sin(tdplotmainphi-180)},h );
    draw[thick] (B) -- (R*cosPhiOne,R*sinPhiOne,h);
    draw[thick] (B) -- (R*cosPhiTwo,R*sinPhiTwo,h);
    draw[thick] (A) -- (R*cosPhiOneBis,R*sinPhiOneBis,0);
draw[thick] (A) -- (R*cosPhiTwoBis,R*sinPhiTwoBis,0);
    foreach p in {O,B,A}
    draw[fill=black] (p) circle (1pt);
    foreach p/g in {O/-45,B/90,A/-90}
    path (p)+(g:3mm) node{$p$};
    draw[dashed]  (A)--(B)    (-R*sinazm,-R*cosazm,0) -- (-R*sinazp,+R*cosazp,0) ;

    end{tikzpicture}
    end{document} 

enter image description here

recensioni e valutazioni

Ci piacerebbe se potessi condividere questa divisione se ti ha aiutato.



Utilizzate il nostro motore di ricerca

Ricerca
Generic filters

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.