如何在立方体线中绘制圆锥体?

如何在立方体线中绘制圆锥体?

我正在尝试在立方体中画一个圆锥体,像这样 在此处输入图片描述

我试过

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
    \tdplotsetmaincoords{70}{100}
\begin{tikzpicture} [tdplot_main_coords,c/.style={circle,fill,inner sep=1pt},line cap=butt,line join=round,c/.style={circle,fill,inner sep=1pt},
        declare function={a=3;}]
        \path
        (a,-a,-a) coordinate (A)
        (a,a,-a) coordinate (B)
        (-a,a,-a) coordinate (C)
        (-a,-a,-a) coordinate (D)
        (a,-a,a) coordinate (E)
        (a,a,a) coordinate (F)
        (-a,a,a) coordinate (G)
        (-a,-a,a) coordinate (H)
        (0,0,0)  coordinate (O) ;
    \draw[] (C) -- (F) -- (H) (A) -- (F) (A) -- (B) -- (C) (E) -- (F) -- (G)-- (H)--cycle (A) -- (E) (B) --  (F) (C) -- (G);
        \draw[dashed] (A) -- (D) -- (C) (C) -- (A) -- (H)--cycle (D) -- (H);
        \path foreach \p/\g in {A/-90,B/-90,C/0,D/0,E/90,F/90,G/90,H/90}{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};  
    \end{tikzpicture}
    \end{document}

并得到

在此处输入图片描述

如何绘制圆锥体?

答案1

您可以使用3d工具

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=100,theta=70},line cap=butt,line join=round,c/.style={circle,fill,inner sep=1pt},
        declare function={a=3;}]
        \path
        (a,-a,-a) coordinate (A)
        (a,a,-a) coordinate (B)
        (-a,a,-a) coordinate (C)
        (-a,-a,-a) coordinate (D)
        (a,-a,a) coordinate (E)
        (a,a,a) coordinate (F)
        (-a,a,a) coordinate (G)
        (-a,-a,a) coordinate (H)
        (0,0,0)  coordinate (O);
\pgfmathsetmacro{\mybarycenter}{barycenter("(C),(H),(F)")}
\path (\mybarycenter) coordinate (I);
\path[
3d/line through={(C) and (F) named lCF}];
\path[3d/project={(I) on lCF}] coordinate (T);
\pgfmathsetmacro{\R}{tddistance("(I)","(T)")}
\pgfmathsetmacro{\h}{tddistance("(I)","(A)")}
\tikzset{3d/define orthonormal dreibein={A={(F)},B={(H)},C={(C)}}}
\path[x={(ex)},y={(ey)},z={(ez)}] (I)   [3d/visible/.style={draw,very thin,cheating dash}]
    pic{3d/cone={r=\R,h=\h}};
\draw[3d/visible] (C) -- (F) -- (H) (A) -- (F) (A) -- (B) -- (C) (E) -- (F) -- (G)-- (H)--cycle (A) -- (E) (B) --  (F) (C) -- (G);
\draw[3d/hidden] (A) -- (D) -- (C) (C) -- (A) -- (H)--cycle (A) -- (I) (D) -- (H);
\path foreach \p/\g in {A/-90,B/-90,C/0,D/0,E/90,F/90,G/90,H/90,I/0}{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};  
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

为了简单起见,我建议采用渐近线方法,就像下面的 3D 图形一样。

要绘制 3D 圆锥,您需要知道高度h和底圆(中心K、半径r和法线n)。Asymptote 提供了两种方法。

1.使用内置的unitconefromthree模块(然后可以进行几何变换,如,,shift等)scalerotate

surface mycone=shift(K)*scale(r,r,h)*unitcone;
draw(mycone,yellow+opacity(.5));

2.solids使用模块革命

revolution mycone=cone(K,r,h,n);
draw(surface(mycone),yellow+opacity(.5));

在此处输入图片描述

unitsize(1cm);
import three;
import solids;
currentprojection=orthographic(2,2,1,center=true,zoom=.9);
// B,C,D on the XY-plane
triple B=O, D=(0,7,0),C=(5,1.5,0);
triple barycentric(triple A=O, triple B, triple C, real a=1, real b, real c){
return (a*A+b*B+c*C)/(a+b+c);
}
triple incenter(triple A=O, triple B, triple C){
real a=abs(B-C), b=abs(C-A), c=abs(A-B);
return barycentric(A,B,C,a,b,c);
}
triple K=incenter(B,C,D);   
real r=.5abs(K-reflect(B,D,Z)*K); // inradius
draw(circle(K,r,Z),red); 
dot("$K$",K,red);
real h=5;
triple A=K+h*Z;
draw(A--B^^A--C^^A--D^^B--C--D--cycle,blue);
dot("$A$",A,NW,blue);
dot("$B$",B,NE,blue);
dot("$C$",C,W,blue);
dot("$D$",D,blue);

////// to draw a CONE   ///////
// 1st way: nice! (use revolution of solids)
revolution mycone=cone(K,r,h,Z);
draw(surface(mycone),yellow+opacity(.5));

// 2nd way: also nice! (use the built-in unitcone of three)
//surface mycone=shift(K)*scale(r,r,h)*unitcone;
//draw(mycone,yellow+opacity(.5));

更新:

在此处输入图片描述

unitsize(1cm);
import three;
import solids;
triple barycentric(triple A=O, triple B, triple C, real a=1, real b, real c){
return (a*A+b*B+c*C)/(a+b+c);
}
triple incenter(triple A=O, triple B, triple C){
real a=abs(B-C), b=abs(C-A), c=abs(A-B);
return barycentric(A,B,C,a,b,c);
}
currentprojection=orthographic(dir(70,25),center=true,zoom=.95);

real a=4;
triple D=O, A=(a,0,0),B=(a,a,0),C=(0,a,0);
triple E=(a,0,a), F=(a,a,a),G=(0,a,a),H=(0,0,a);
draw(box(D,F),blue);
draw(A--H--F--C--H^^A--F,blue);
triple K=incenter(H,F,C);
triple n=normal(H--C--F);
real sHFC=.5*abs(cross(F-H,F-C));
real p=.5*(abs(H-F)+abs(F-C)+abs(H-C));
real r=sHFC/p;        // inradius
draw(circle(K,r,n),red); 
dot(K,red);
real h=abs(A-K);
revolution mycone=cone(K,r,h,n);
draw(surface(mycone),yellow+opacity(.5));

相关内容