令人惊讶地走错了路径

令人惊讶地走错了路径

为什么上面的椭圆放错了位置?它的定义方式与另外两个相同。

编辑

注意:甚至底部的椭圆也没有正确放置。

计算为大轴的节点为椭圆。可能是由于 pgftransformtriangle 导致计算错误?

编辑2

我尝试使用 \pgftransformreset,但结果是一样的。

在此处输入图片描述

\documentclass[tikz]{standalone}

\usepackage{tikz,ifthen}
\usetikzlibrary{calc,intersections,fpu}

\def\Azi{30}%30
\def\Alt{20}%20

\def\Radius{1.5}
\def\Length{5}
\def\AngleMax{atan(2*\Radius/\Length)}

\newcommand{\SetRelAngle}[1]{%
    \def\RelAngle{#1}   
    % max +23 Min -30
    \def\Angle{\AngleMax+#1}

    \pgfmathsetmacro\RadCos{\Radius*cos(\Angle)}
    \pgfmathsetmacro\RadSin{\Radius*sin(\Angle)}
    \pgfmathsetmacro\LCos{\Length*cos(\Angle)}
    \pgfmathsetmacro\LSin{\Length*sin(\Angle)}

    \pgfmathsetmacro\CosAlt{cos(\Alt)}
    \pgfmathsetmacro\SinAlt{sin(\Alt)}
    \pgfmathsetmacro\CosAzi{cos(\Azi)}
    \pgfmathsetmacro\SinAzi{sin(\Azi)}

    \pgfmathsetmacro\SinAziSinAlt{\SinAzi*\SinAlt}
    \pgfmathsetmacro\CosAziSinAlt{\CosAzi*\SinAlt}

    \pgfmathsetmacro\CosAngle{cos(\Angle)}
    \pgfmathsetmacro\SinAngle{sin(\Angle)}
    \pgfmathsetmacro\TanAngle{tan(\Angle)}

    %                           ----- Centre
    %                           ----- de l'ellipse surface
    \pgfmathsetmacro\CX{\LCos-\RadCos/\TanAngle}
    \pgfmathsetmacro\CZ{\LSin-\RadCos}

    %                           ---- Contact surface bord
    %                           ---- sup cylindre 
    \pgfmathsetmacro\CXX{\LCos+\RadSin}     

    %                           ----- grand axe au fond
    \pgfmathsetmacro\GAZ{1.5}
    \pgfmathsetmacro\GAX{-\GAZ*tan(\Angle)}
    \pgfmathsetmacro\GAY{%
        \GAZ*(tan(\Angle)*tan(\Azi)+tan(\Alt)/cos(\Azi))}
    }

% #1 premier point               ---- Angle entre 2 nodes ----
% #2 second point
% On récupère le résultat dans \MyAngle
\newcommand{\NodeAngle}[2]{%
\pgfextra{
    \pgfmathanglebetweenpoints%
        {\pgfpointanchor{#1}{center}}%
        {\pgfpointanchor{#2}{center}}%
        \global\let\MyAngle\pgfmathresult
}}

%                                   ---- Calculate projection
\newcommand{\CoorXY}[4][MyNode]{%
    \pgfmathsetmacro\PjX{%
         #2*\CosAzi
        -#3*\SinAzi}
    \pgfmathsetmacro\PjY{%
         #2*\SinAziSinAlt
        +#3*\CosAziSinAlt
        +#4*\CosAlt}
    \coordinate (#1) at (\PjX,\PjY) ;
    }

%                               ---- with a dot for debugging
\newcommand{\CoorXYT}[4][MyNode]{%
    \CoorXY[#1]{#2}{#3}{#4}
    \node[small dot,label={[font=\scriptsize]#1}] at (#1) {}
    }

%%%%                        ---- Use path several times
%%%%                        ---- thanks to Andrew Stacey
\makeatletter
\tikzset{
  use path for main/.code={%
    \tikz@addmode{%
      \expandafter\pgfsyssoftpath@setcurrentpath\csname tikz@intersect@path@name@#1\endcsname
    }%
  },
  use path for actions/.code={%
    \expandafter\def\expandafter\tikz@preactions\expandafter{\tikz@preactions\expandafter\let\expandafter\tikz@actions@path\csname tikz@intersect@path@name@#1\endcsname}%
  },
  use path/.style={%
    use path for main=#1,
    use path for actions=#1,
  }
}
\makeatother

%%%%                        ---- Définition des styles ----
\tikzset{%
    small dot/.style={fill=black,circle,scale=0.3},
    surface/.style={blue!75!black!75,fill=blue!10,smooth},
    fond/.style={blue!75!black!75,fill=blue!80!black!20}
    }

% ##############
\begin{document}
% ##############
%\foreach \An in {36,15,1,0,-1,-12}{%
%\SetRelAngle{\An}

\SetRelAngle{5}
\begin{tikzpicture}[scale=2]


\clip (-\Radius-.5,-1.5*\Radius)
    rectangle (\Length+1,\Length+.5) ;

%%%% Debugging

% Repère 
\CoorXY[CB]{0}{0}{0} ; 
%\CoorXYT[X]{2}{0}{0} ; 
%\CoorXYT[Y]{0}{3}{0} ; 
%\CoorXYT[Z]{0}{0}{2} ; 
%\draw[red,<-] (X) -- ($ (X)!2!(CB) $) ;
%\draw[red,<-] (Y) -- ($ (Y)!2!(CB) $) ;
%\draw[red,<-] (Z) -- ($ (Z)!2!(CB) $) ;

% Ellipse du haut
\CoorXY[CH]{\LCos}{0}{\LSin} ;
\CoorXY[XH]{\LCos}{-\Radius}{\LSin} ;

% Ellipse surface
\CoorXY[SH]{\CX}{0}{\CZ} ;
\CoorXY[SXH]{\CX}{-\Radius}{\CZ} ;
\CoorXY[SYH]{\CXX}{0}{\CZ} ;

%\draw[thin,dashed] (SH)--(SYH) ;

% Ellipse du bas
%\CoorXYT[BD]{0}{\Radius}{0} ;
\CoorXY[BG]{0}{-\Radius}{0} ;
\CoorXY[BH]{-\RadSin}{0}{\RadCos} ;
%\CoorXYT[BB]{\RadSin}{0}{-\RadCos} ;

% Grand Axe
\CoorXY[GA]{\GAX}{\GAY}{\GAZ} ;


%%%%                        ---- Plan cylindre bas ----
\begin{scope}
\pgftransformtriangle
    {\pgfpointanchor{CB}{center}}
    {\pgfpointanchor{BG}{center}}
    {\pgfpointanchor{BH}{center}} ;
%\draw (-1pt,-1pt) rectangle (1pt,1pt) ;
%\draw (0pt,-1pt) -- (0pt,1pt) (-1pt,0pt) -- (1pt,0pt) ;
\NodeAngle{CB}{GA} ;    
\coordinate (GaBL) at (\MyAngle:1pt) ;
\coordinate (GaBR) at (180+\MyAngle:1pt) ;

\path [name path global=fondL]
    (GaBL) arc (\MyAngle:\MyAngle+180:1pt) ;
\path [name path global=fondR]
    (GaBL) arc (\MyAngle+360:\MyAngle+180:1pt) ;

\end{scope}

%%%%                        ---- Plan cylindre haut ----
\begin{scope}
\pgftransformtriangle
    {\pgfpointanchor{CH}{center}}
    {\pgfpointanchor{XH}{center}}
    {\pgfpointanchor{SYH}{center}} ;
%\draw (-1pt,-1pt) rectangle (1pt,1pt) ;
%\draw (0pt,-1pt) -- (0pt,1pt) (-1pt,0pt) -- (1pt,-0pt) ;
%\draw (0,0) circle (1pt) ;
% Attention dans ce plan l'axe y est vers le bas
\coordinate (GaHL) at (-\MyAngle:1pt) ;
\coordinate (GaHR) at (180-\MyAngle:1pt) ;  

\path [name path global=hautL]
    (GaHL) arc (-\MyAngle:180-\MyAngle:1pt) ;
\path [name path global=hautR]
    (GaHL) arc (-\MyAngle+360:-\MyAngle+180:1pt) ;

%\draw (GaHR)--(GaHL) ;
\end{scope}

%%%%                        ---- Plan de la surface ----
\begin{scope}
\pgftransformtriangle
    {\pgfpointanchor{SH}{center}}
    {\pgfpointanchor{SXH}{center}}
    {\pgfpointanchor{SYH}{center}} ;
%\draw (-1pt,-1pt) rectangle (1pt,1pt) ;
%\draw (0pt,-1pt) -- (0pt,1pt) (-1pt,0pt) -- (1pt,-0pt) ;
\coordinate (bobR) at (180-\MyAngle:1pt) ;
\coordinate (bobL) at (-\MyAngle:1pt) ;
\path [name path global=surface] (0pt,0pt) circle (1pt) ;
\end{scope}


%\pgfmathifthenelse{\AngleMax>\Angle}{0}{1} ;
%\ifthenelse{\pgfmathresult=1}{%
    %%%%%%%%%%%%%%%%%%%%%
    %%%% Cas ellipse %%%%
    %%%%%%%%%%%%%%%%%%%%%

    % remplissage
    %\fill[fond]
    %   (GaBL)--(bobL)--(bobR)--(GaBR) --cycle ;

    % dessin de la surface
    \draw [use path=surface,surface] ;
    \draw [use path=fondL] ;
    \draw [use path=fondR] ;
    \draw [use path=hautL] ;
    \draw [use path=hautR] ;

    %}{%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%% cas ellipse tronquée %%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %}      

\draw (GaBL)--(GaHL) ;
\draw (GaBR)--(GaHR) ;
\end{tikzpicture}
\end{document}

相关内容