How to draw a cube that can be inscribed within a right circular cone?checomsth.orvg2 miiliB

7

I am trying to draw a cube that can be inscribed within a right circular cone (cone of radius r and perpendicular height h). I see at here https://www.geeksforgeeks.org/largest-cube-that-can-be-inscribed-within-a-right-circular-cone/ I can find the side length of cube. But I cann't draw it. I tried

    \\documentclass[border=3.14mm,12pt,tikz]{standalone}
\\usepackage{tikz-3dplot}
\\usetikzlibrary{calc,backgrounds}
\\begin{document}
%polar coordinates of visibility
\\pgfmathsetmacro\\th{65}
\\pgfmathsetmacro\\az{110}
\\tdplotsetmaincoords{\\th}{\\az}
%parameters of the cone
\\pgfmathsetmacro\\R{4} %radius of base
\\pgfmathsetmacro\\v{5} %hight of cone
\\begin{tikzpicture} [scale=1, tdplot_main_coords, axis/.style={blue,thick}]
\\path
coordinate (O) at (0,0,0)
coordinate (A) at (\\R,0,0)
coordinate (B) at (0,\\R,0)
coordinate (C) at ($ 2*(O) - (A) $)
coordinate (D) at ($ 2*(O) - (B) $)
coordinate (S) at (0,0,\\v)
;
\\fill (S) circle[radius=1pt] node[above] {$S$};
\\fill (A) circle[radius=1pt] node[below] {$A$};
\\fill (B) circle[radius=1pt] node[below] {$B$};
\\fill (C) circle[radius=1pt] node[above] {$C$};
\\fill (D) circle[radius=1pt] node[above] {$D$};
\\fill (O) circle[radius=1pt] node[below] {$O$};

 \\draw[thick] (A) -- (S) (S) -- (B);
\\draw[dashed] (A) -- (B) -- (C) -- (D) -- cycle (S) -- (C) (A) -- (C) (B) -- (D) (S) -- (O);

\\pgfmathsetmacro\\cott{{cot(\\th)}}
\\pgfmathsetmacro\\fraction{\\R*\\cott/\\v}
\\pgfmathsetmacro\\fraction{\\fraction<1 ? \\fraction : 1}
\\pgfmathsetmacro\\angle{{acos(\\fraction)}}

% % angles for transformed lines
\\pgfmathsetmacro\\PhiOne{180+(\\az-90)+\\angle}
\\pgfmathsetmacro\\PhiTwo{180+(\\az-90)-\\angle}

% % coordinates for transformed surface lines
\\pgfmathsetmacro\\sinPhiOne{{sin(\\PhiOne)}}
\\pgfmathsetmacro\\cosPhiOne{{cos(\\PhiOne)}}
\\pgfmathsetmacro\\sinPhiTwo{{sin(\\PhiTwo)}}
\\pgfmathsetmacro\\cosPhiTwo{{cos(\\PhiTwo)}}

% % angles for original surface lines
\\pgfmathsetmacro\\sinazp{{sin(\\az-90)}}
\\pgfmathsetmacro\\cosazp{{cos(\\az-90)}}
\\pgfmathsetmacro\\sinazm{{sin(90-\\az)}}
\\pgfmathsetmacro\\cosazm{{cos(90-\\az)}}

% % draw basis circle
\\tdplotdrawarc[tdplot_main_coords,thick]{(O)}{\\R}{\\PhiOne}{360+\\PhiTwo}{anchor=north}{}
\\tdplotdrawarc[tdplot_main_coords,dashed]{(O)}{\\R}{\\PhiTwo}{\\PhiOne}{anchor=north}{}

% % displaying tranformed surface of the cone (rotated)
\\draw[thick] (0,0,\\v) -- (\\R*\\cosPhiOne,\\R*\\sinPhiOne,0);
\\draw[thick] (0,0,\\v) -- (\\R*\\cosPhiTwo,\\R*\\sinPhiTwo,0);
 \\end{tikzpicture}
  \\end{document}

enter image description here

share|improve this question
New contributor
Thuy Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

2 Answers 2

active oldest votes
7

Assuming the formula from your link is correct, this is a possible cube. The figure seems to be confirming the formula.

\\documentclass[border=3.14mm,12pt,tikz]{standalone}
\\usepackage{tikz-3dplot}
\\begin{document}
%polar coordinates of visibility
\\pgfmathsetmacro\\th{65}
\\pgfmathsetmacro\\az{110}
\\tdplotsetmaincoords{\\th}{\\az}
%parameters of the cone
\\begin{tikzpicture}[scale=1, tdplot_main_coords, axis/.style={blue,thick}]
  \\pgfmathsetmacro\\R{4} %radius of base
  \\pgfmathsetmacro\\v{5} %hight of cone
  \\path (0,0,0) coordinate (O)  
      (\\R,0,0) coordinate (A)  
      (0,\\R,0) coordinate (B)  
      (-\\R,0,0) coordinate (C)  
      (0,-\\R,0) coordinate (D)  
      (0,0,\\v) coordinate (S);
  \\foreach \\point/\\pos in {S/above,A/below,B/below,C/above,D/above,O/below} 
  {\\fill (\\point) circle[radius=1pt] node[\\pos] {$\\point$};}
  \\draw[thick] (A) -- (S) (S) -- (B);
  \\draw[dashed] (A) -- (B) -- (C) -- (D) -- cycle (S) -- (C) (A) -- (C) (B) -- (D) (S) -- (O);

  \\pgfmathsetmacro\\cott{{cot(\\th)}}
  \\pgfmathsetmacro\\fraction{\\R*\\cott/\\v}
  \\pgfmathsetmacro\\fraction{\\fraction<1 ? \\fraction : 1}
  \\pgfmathsetmacro\\angle{{acos(\\fraction)}}

  % % angles for transformed lines
  \\pgfmathsetmacro\\PhiOne{180+(\\az-90)+\\angle}
  \\pgfmathsetmacro\\PhiTwo{180+(\\az-90)-\\angle}

  % % coordinates for transformed surface lines
  \\pgfmathsetmacro\\sinPhiOne{{sin(\\PhiOne)}}
  \\pgfmathsetmacro\\cosPhiOne{{cos(\\PhiOne)}}
  \\pgfmathsetmacro\\sinPhiTwo{{sin(\\PhiTwo)}}
  \\pgfmathsetmacro\\cosPhiTwo{{cos(\\PhiTwo)}}

  \\tdplotdrawarc[tdplot_main_coords,dashed]{(O)}{\\R}{\\PhiTwo}{\\PhiOne}{anchor=north}{}

  \\pgfmathsetmacro{\\a}{\\v*\\R*sqrt(2)/(\\v+sqrt(2)*\\R)} % edge
  \\pgfmathsetmacro{\\mya}{sqrt(1/2)*\\a} % half diagonal

  \\pgfmathsetmacro{\\myalpha}{90}
  \\begin{scope}[canvas is xy plane at z=0] 
   \\path foreach \\X in {1,...,4}{ (\\myalpha+90*\\X:\\mya) coordinate (P\\X)};
  \\end{scope}
  \\begin{scope}[canvas is xy plane at z=\\a] 
   \\path foreach \\X in {1,...,4}{ (\\myalpha+90*\\X:\\mya) coordinate (Q\\X)};
  \\end{scope}
  \\draw[dashed] (P4) -- (P1) -- (P2)  (P1) -- (Q1);
  \\draw (P4) -- (P3) -- (P2) -- (Q2) -- (Q3) -- (Q4) -- (Q1) -- (Q2) 
  (Q4) -- (P4) (P4) (P3) -- (Q3);

  % % draw basis circle
  \\tdplotdrawarc[tdplot_main_coords,thick]{(O)}{\\R}{\\PhiOne}{360+\\PhiTwo}{anchor=north}{}

  % % displaying transformed surface of the cone (rotated)
  \\draw[thick] (0,0,\\v) -- (\\R*\\cosPhiOne,\\R*\\sinPhiOne,0);
  \\draw[thick] (0,0,\\v) -- (\\R*\\cosPhiTwo,\\R*\\sinPhiTwo,0);


\\end{tikzpicture}
\\end{document}

enter image description here

If you rotate the cube, it still fits.

\\documentclass[border=3.14mm,12pt,tikz]{standalone}
\\usepackage{tikz-3dplot}
\\begin{document}
%polar coordinates of visibility
\\pgfmathsetmacro\\th{65}
\\pgfmathsetmacro\\az{110}
\\tdplotsetmaincoords{\\th}{\\az}
\\foreach \\Angle in {0,2,...,88}
{\\begin{tikzpicture}[scale=1, tdplot_main_coords, axis/.style={blue,thick}]
  \\pgfmathsetmacro\\R{4} %radius of base
  \\pgfmathsetmacro\\v{5} %hight of cone
  \\path (0,0,0) coordinate (O)  
      (\\R,0,0) coordinate (A)  
      (0,\\R,0) coordinate (B)  
      (-\\R,0,0) coordinate (C)  
      (0,-\\R,0) coordinate (D)  
      (0,0,\\v) coordinate (S);
  \\foreach \\point/\\pos in {S/above,A/below,B/below,C/above,D/above,O/below} 
  {\\fill (\\point) circle[radius=1pt] node[\\pos] {$\\point$};}
  \\draw[thick] (A) -- (S) (S) -- (B);
  \\draw[dashed] (A) -- (B) -- (C) -- (D) -- cycle (S) -- (C) (A) -- (C) (B) -- (D) (S) -- (O);

  \\pgfmathsetmacro\\cott{{cot(\\th)}}
  \\pgfmathsetmacro\\fraction{\\R*\\cott/\\v}
  \\pgfmathsetmacro\\fraction{\\fraction<1 ? \\fraction : 1}
  \\pgfmathsetmacro\\angle{{acos(\\fraction)}}

  % % angles for transformed lines
  \\pgfmathsetmacro\\PhiOne{180+(\\az-90)+\\angle}
  \\pgfmathsetmacro\\PhiTwo{180+(\\az-90)-\\angle}

  % % coordinates for transformed surface lines
  \\pgfmathsetmacro\\sinPhiOne{{sin(\\PhiOne)}}
  \\pgfmathsetmacro\\cosPhiOne{{cos(\\PhiOne)}}
  \\pgfmathsetmacro\\sinPhiTwo{{sin(\\PhiTwo)}}
  \\pgfmathsetmacro\\cosPhiTwo{{cos(\\PhiTwo)}}

  \\tdplotdrawarc[tdplot_main_coords,dashed]{(O)}{\\R}{\\PhiTwo}{\\PhiOne}{anchor=north}{}

  \\pgfmathsetmacro{\\a}{\\v*\\R*sqrt(2)/(\\v+sqrt(2)*\\R)} % edge
  \\pgfmathsetmacro{\\mya}{sqrt(1/2)*\\a} % half diagonal

  \\pgfmathsetmacro{\\myalpha}{\\Angle}
  \\begin{scope}[canvas is xy plane at z=0] 
   \\path foreach \\X in {1,...,4}{ (\\myalpha+90*\\X:\\mya) coordinate (P\\X)};
  \\end{scope}
  \\begin{scope}[canvas is xy plane at z=\\a] 
   \\path foreach \\X in {1,...,4}{ (\\myalpha+90*\\X:\\mya) coordinate (Q\\X)};
  \\end{scope}
  \\draw (P4) -- (P3) -- (P2) -- (Q2) -- (Q3) -- (Q4) -- (Q1) -- (Q2) 
  (Q4) -- (P4) (P4) (P3) -- (Q3) (P4) -- (P1) -- (P2)  (P1) -- (Q1);

  % % draw basis circle
  \\tdplotdrawarc[tdplot_main_coords,thick]{(O)}{\\R}{\\PhiOne}{360+\\PhiTwo}{anchor=north}{}

  % % displaying transformed surface of the cone (rotated)
  \\draw[thick] (0,0,\\v) -- (\\R*\\cosPhiOne,\\R*\\sinPhiOne,0);
  \\draw[thick] (0,0,\\v) -- (\\R*\\cosPhiTwo,\\R*\\sinPhiTwo,0);
\\end{tikzpicture}}
\\end{document}

enter image description here

share|improve this answer
New contributor
Schrödinger's cat is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Are style of all sides of cube dashed? – minhthien_2016 11 hours ago
  • @minhthien_2016 One could of course dash them. It depends on your conventions. – Schrödinger's cat 10 hours ago
5

I also use the formula from your link.

\\documentclass[border=2mm,12pt,tikz]{standalone}
\\usepackage{fouriernc}
\\usepackage{tikz-3dplot}
\\usetikzlibrary{calc,backgrounds}
\\begin{document}
%polar coordinates of visibility
\\pgfmathsetmacro\\th{65}
\\pgfmathsetmacro\\az{110}
\\tdplotsetmaincoords{\\th}{\\az}
%parameters of the cone
\\pgfmathsetmacro\\R{4} %radius of base
\\pgfmathsetmacro\\v{5} %hight of cone
\\pgfmathsetmacro\\a{{(\\v * \\R * sqrt(2)) / (\\v + sqrt(2) * \\R)}}
\\pgfmathsetmacro\\b{{1/2*\\a*sqrt(2)}}
\\begin{tikzpicture} [scale=1, tdplot_main_coords, axis/.style={blue,thick}]
\\begin{scope}[canvas is xy plane at z=0]
\\path
coordinate (O) at (0,0)
coordinate (A) at (\\R,0)
coordinate (B) at (0,\\R)
coordinate (C) at (-\\R,0)
coordinate (D) at (0,-\\R,0)
coordinate (M) at (\\b,0)
coordinate (N) at (0,\\b)
coordinate (P) at (-\\b,0)
coordinate (Q) at (0,-\\b);
\\end{scope}
\\begin{scope}[canvas is xy plane at z=\\a] 
\\path coordinate (M') at (\\b,0)
coordinate (N') at (0,\\b)
coordinate (P') at (-\\b,0)
coordinate (Q') at (0,-\\b)
;
\\end{scope}
\\coordinate (S) at (0,0,\\v);

\\foreach \\v/\\position in {O/below,A/below, B/right,  C/right, D/left, S/above} {\\draw[draw =black, fill=black] (\\v) circle (1.5pt) node [\\position=0.2mm] {$\\v$};
}
\\foreach \\X in {A,B} \\draw[thick] (\\X) -- (S);
\\foreach \\X in {M,N,P,Q} \\draw[dashed] (\\X) -- (\\X');
\\draw[dashed] (A) -- (B) -- (C) -- (D) -- cycle 
(M) -- (N) -- (P) -- (Q) -- cycle
(M') -- (N') -- (P') -- (Q') -- cycle
(A) -- (C) (B) -- (D)
(S)--(O)  (S)-- (C);

\\foreach \\Y in {M, N, P, Q, M', N', P', Q'} 
\\fill (\\Y) circle[radius=1.2pt];

\\begin{scope}[canvas is xy plane at z=0]
\\draw[dashed, blue]  (O) circle[radius=\\b];
\\end{scope}


\\pgfmathsetmacro\\cott{{cot(\\th)}}
\\pgfmathsetmacro\\fraction{\\R*\\cott/\\v}
\\pgfmathsetmacro\\fraction{\\fraction<1 ? \\fraction : 1}
\\pgfmathsetmacro\\angle{{acos(\\fraction)}}

% % angles for transformed lines
\\pgfmathsetmacro\\PhiOne{180+(\\az-90)+\\angle}
\\pgfmathsetmacro\\PhiTwo{180+(\\az-90)-\\angle}

% % coordinates for transformed surface lines
\\pgfmathsetmacro\\sinPhiOne{{sin(\\PhiOne)}}
\\pgfmathsetmacro\\cosPhiOne{{cos(\\PhiOne)}}
\\pgfmathsetmacro\\sinPhiTwo{{sin(\\PhiTwo)}}
\\pgfmathsetmacro\\cosPhiTwo{{cos(\\PhiTwo)}}

% % angles for original surface lines
\\pgfmathsetmacro\\sinazp{{sin(\\az-90)}}
\\pgfmathsetmacro\\cosazp{{cos(\\az-90)}}
\\pgfmathsetmacro\\sinazm{{sin(90-\\az)}}
\\pgfmathsetmacro\\cosazm{{cos(90-\\az)}}

% % draw basis circle
\\tdplotdrawarc[tdplot_main_coords,thick]{(O)}{\\R}{\\PhiOne}{360+\\PhiTwo}{anchor=north}{}
\\tdplotdrawarc[tdplot_main_coords,dashed]{(O)}{\\R}{\\PhiTwo}{\\PhiOne}{anchor=north}{}

% % displaying tranformed surface of the cone (rotated)
\\draw[thick] (0,0,\\v) -- (\\R*\\cosPhiOne,\\R*\\sinPhiOne,0);
\\draw[thick] (0,0,\\v) -- (\\R*\\cosPhiTwo,\\R*\\sinPhiTwo,0);
 \\end{tikzpicture}
  \\end{document}

enter image description here

share|improve this answer

Your Answer

Thuy Nguyen is a new contributor. Be nice, and check out our Code of Conduct.

Thanks for contributing an answer to TeX - LaTeX Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged tikz-3dplot or ask your own question.

Popular posts from this blog

Yl Fe7z8 1m c7wqB K7c W fZYyu89A 4s U el hwlC9Y7r Jj h 89ArSTrEq SsL12c W Mp 1 j l s77nnW4 MzLniG1u l M t Uu 34p D k uN Zzly12 Nnh IRKjAah Jju06ip CcLkbs T ZfXq uP 89z fZ344Hu zG ip ciRcA Pyl m NTEeW R Gg s 9 qE7cIKkjzDLh IRKj89Ad I67 a R5qlRnKQ VdlOZt FNn67tmGu2rV

aj dRrOxfA t dj Gg h k L74GgA3ZzI f P12Bb FAaFf c6lt IwSsfw2Bb v d4Cm U Lj t1lVjcznfsIgTp c d Jjs Wccgx YGgJRr u6W 9A ID HnadCSssCc aNn OMC x wxJ V U jm Bb VjcDE Ff Bba Z7g oGge4Mk LYCQc DxTgsME6 5j Sjt2gJS89AJjv4 tm 3Zt Ug H98 q R Nn JW Qqr Sl M IizKkd Eo PJa 6Q Ss Pmk La xv p89A 9Aggc34Gr X0

็ฯ ย๊น๞๩,็ื,ฟ๶๊ ฟ ญ้๲ฒ๭๫ไ,๻๐๮ ๛๴ ๎ใ๡๞ฆ