1

I would like to create a cone model where the dimension (radius and height) are variable. The problem with my current model is that the dashed circle is not covered by the gray figure when the height is too small. Any idea how to solve this problem?

enter image description here

enter image description here

%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}

%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz, tkz-euclide}%  permet de dessiner des figures, des graphiques
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre
%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans 
%                       \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)
\usepackage{xcolor}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble}
%\input{parameters}
%\input{types/f3d_fig}

%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\tikzset{volum3D/.style={font={\sansmath\sffamily\large}, line width=0.4mm, line cap=round, line join=round, >=latex,}} 

%%%%%%%%%%%%%%%%%%%%%%%% SPHERE RADIUS LABEL %%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\tikzset{pics/cone radlab/.style={code={%
    \tikzset{cone radlab/.cd,#1}%
    \def\pv##1{\pgfkeysvalueof{/tikz/cone radlab/##1}}
    \pgfmathsetmacro{\myan}{atan2(\pgf@zx,\pgf@xx)}
    \begin{scope}[local bounding box=sph]
        \path[cone radlab/corps]
        %%%     Patrie supérieur
        plot[smooth,variable=\t,samples=19,domain=\myan:{-1*sign(\myan)*180+\myan}]
        (0,
        \pv{height},
        0)
        --
        %%%     Patrie Inférieur
        plot[smooth,variable=\t,samples=19,domain=\myan:{-1*sign(\myan)*180+\myan}]
        ({\pv{ray}*\pv{scale}*cos(\t)},
        0,
        {\pv{ray}*\pv{scale}*sin(\t)})
        -- cycle
        ;
        \draw[thick, densely dashed]
        %%%       Arc Avant
        plot[smooth,variable=\t,samples=19,domain={-1*sign(\myan)*180+\myan}:\myan]
        ({\pv{ray}*\pv{scale}*cos(\t)},
        0,
        {\pv{ray}*\pv{scale}*sin(\t)})
        %%%       Arc Arrière
        plot[smooth,variable=\t,samples=19,domain={sign(\myan)*180+\myan}:\myan]
        ({\pv{ray}*\pv{scale}*cos(\t)},
        0,
        {\pv{ray}*\pv{scale}*sin(\t)})
        ;
    \end{scope}
    %%  Dot (0,0)
    \draw 
    (0,0,0) node[circle, fill=black, inner sep=1pt] {} coordinate (o)
    (\pv{ray},0,0) coordinate (r)
    ;
    %%  Barre de mesure du rayon 
    \draw[densely dashed, <->] 
    (o) -- 
    (r) node[midway, below, inner sep=6pt] {\pv{lab}}
    ;
  }},
  cone radlab/.cd,
  ray/.initial=5,
  height/.initial=10,
  lab/.initial=5 cm,
  scale/.initial=1,
  corps/.style={draw,fill=black!15},
}
\makeatother
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[volum3D, x={(0:1cm)}, y={(90:1cm)}, z={(89:0.4cm)}]

% calibration cross
%\pic at (5,0,0) {calcross};

%   Figures
\pic{cone radlab};
\node[below, yshift= -36pt, text=orange] at (0,0,0) {D};

\end{tikzpicture}
\end{document}

wouldn't be possible to solve this with an equation feed by the height? So the part would be: 'green part -- left blue part -- left red part -- right red part -- right blue part -- cycle'

enter image description here

enter image description here

2
  • I don't think I quite understand what you want to do, perhaps you could make a sketch in Paint or similar? Apr 8, 2020 at 15:54
  • I would like to have a cone model where the dimension (radius, height) are variable. The problem with my current model is that the dashed circle is not covered by the gray figure when the height is too small.
    – Nilcouv
    Apr 9, 2020 at 9:10

1 Answer 1

2

I'm not sure I understand exactly what you're trying to do, so this might not be what you are looking for!

If you only want to draw a cone, you can do it by hand. In this case, you only need to find the point in the base ellipse of the cone where the tangent go through the top point (which is where the red and blue part meet in your diagram).

In the case of a circle (and not an ellipse), using trigonometry, you can easily find an expression of the "target" angle. If I am not mistaken, the corresponding point should be "invariant" under scaling, so you can plot your figure for a circle and scale it along the y axis afterward.

\documentclass[tikz,border=5mm]{standalone}

\begin{document}

\begin{tikzpicture}

  \foreach \R in {1.1,1.6,...,4}{
    \begin{scope}[shift={(5*\R,0)}]

      %% Draw circle
      \draw[dotted] (0,0) circle (1);

      %% Compute the angle (and plot the angle)
      \pgfmathsetmacro\angle{acos(1/\R)}
      \draw[opacity=.1] (90+\angle:1)--(0,0)--(90+360-\angle:1);

      %% Draw the cone
      \draw (90+\angle:1) arc (90+\angle:90+360-\angle:1) -- (0,\R) -- cycle;

    \end{scope}
  }

  \def\R{6}
  \begin{scope}[shift={(22,0)},yscale=.5]
    \draw[dotted] (0,0) circle (1);
    \pgfmathsetmacro\angle{acos(1/\R)}
    \draw (90+\angle:1) arc (90+\angle:90+360-\angle:1) -- (0,\R) -- cycle;
  \end{scope}

\end{tikzpicture}

\end{document}

which gives results Note that because we scale the whole figure, you need to multiply the variable \R by the inverse of the yscale value.

If you still want to use the 3D coordinate system, this might be more complicated... You could take a look at this texample: http://www.texample.net/tikz/examples/map-projections/. If I understand correctly your problem correspond to drawing the latitude circle.

1
  • yes this is what i'm looking for, thank you.
    – Nilcouv
    Apr 10, 2020 at 11:46

Your Answer

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 or ask your own question.