我无法fond
在末端绘制路径,但我可以在定义路径的范围内绘制它。与路径相同,haut
但与路径表面配合良好吗?
\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}[red]
\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) ;
\path [name path=fond] (0pt,0pt) circle (1pt) ;
\NodeAngle{CB}{GA} ;
\coordinate (GaBL) at (\MyAngle:1pt) ;
\coordinate (GaBR) at (180+\MyAngle:1pt) ;
\end{scope}
%%%% ---- Plan cylindre haut ----
\begin{scope}[red]
\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) ;
\path [name path=haut] (0pt,0pt) circle (1pt) ;
% Attention dans ce plan l'axe y est vers le bas
\coordinate (GaHL) at (-\MyAngle:1pt) ;
\coordinate (GaHR) at (180-\MyAngle:1pt) ;
\end{scope}
%%%% ---- Plan de la surface ----
\begin{scope}[blue]
\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=surface] (0pt,0pt) circle (1pt) ;
\end{scope}
\draw[red] (bobL)--(bobR) ;
\draw (GaBL)--(GaHL) ;
\draw (GaBR)--(GaHR) ;
%\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] ;
% dessin du fond
% ##### don't work
\draw [use path=fond,fond] ;
%}{%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% cas ellipse tronquée %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%}
\end{tikzpicture}
\end{document}
答案1
当你将某物放入 中时scope
,范围实际上被限制在 范围内;)。使用 的主要思想scope
是将内容与世界其他地方分开。这在很多情况下都很有用,比如我们想单独剪辑某个部分(还有其他有用的情况)。当你在范围内命名路径时也会发生同样的事情。路径名称仅在特定范围内可用。要使其在外部也可用,你应该使用name path global
Torbjørn T 提到的方法。
\path [name path global=fond] (0pt,0pt) circle (1pt) ;
完整代码:
\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}[red]
\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) ;
\path [name path global=fond] (0pt,0pt) circle (1pt) ;
\NodeAngle{CB}{GA} ;
\coordinate (GaBL) at (\MyAngle:1pt) ;
\coordinate (GaBR) at (180+\MyAngle:1pt) ;
\end{scope}
%%%% ---- Plan cylindre haut ----
\begin{scope}[red]
\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) ;
\path [name path=haut] (0pt,0pt) circle (1pt) ;
% Attention dans ce plan l'axe y est vers le bas
\coordinate (GaHL) at (-\MyAngle:1pt) ;
\coordinate (GaHR) at (180-\MyAngle:1pt) ;
\end{scope}
%%%% ---- Plan de la surface ----
\begin{scope}[blue]
\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=surface] (0pt,0pt) circle (1pt) ;
\end{scope}
\draw[red] (bobL)--(bobR) ;
\draw (GaBL)--(GaHL) ;
\draw (GaBR)--(GaHR) ;
%\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] ;
% dessin du fond
% ##### don't work
\draw [use path=fond,fond] ;
%}{%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% cas ellipse tronquée %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%}
\end{tikzpicture}
\end{document}
与 path haut 相同,但与 path surface 配合良好吗?
除非你提供一些证据,否则我对这个说法持怀疑态度。除非你有一些魔杖,否则它不应该正常工作;)