2

I am trying to draw a cone in a cube like this enter image description here

I tried

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

And get

enter image description here

How to draw the cone?

1

2 Answers 2

3

You can use 3dtools

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

enter image description here

3

I suggest an Asymptote way, for simplicity, like as in the following a 3D figure.

To draw a 3D cone, you need to the height h and the base circle (center K, radius r, and normal n). Asymptote gives two methods.

1. use the built-in unitcone from three module (then one can take geometric transformations like shift, scale, rotate, etc)

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

2. use revolution from solids module

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

enter image description here

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));

Update:

enter image description here

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));
5
  • 1
    The second code is incomplete! Commented Oct 23, 2021 at 17:26
  • Thanks! I added revolution mycone=cone(K,r,h,n); draw(surface(mycone),yellow+opacity(.5));
    – Black Mild
    Commented Oct 23, 2021 at 17:29
  • @BlackMild I see almost your code. Can you explain for me this syntax return (a*A+b*B+c*C)/(a+b+c)? Commented Oct 24, 2021 at 2:15
  • @JohnPaulPeter That's is barycentric coordinates en.wikipedia.org/wiki/Barycentric_coordinate_system. In my code, the function barycentric has 6 arguments (3 for triples A,B,C and 3 for their weights); it returns another triple by definition of barycentric coordinates.
    – Black Mild
    Commented Oct 24, 2021 at 6:58
  • @BlackMild Thank you very much. Voted for your answer. Commented Oct 24, 2021 at 11:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .