我正在尝试使用plot
绘制使用复杂极坐标定义的路径。目前,我使用一个大域来绘制它,然后我定义与圆的交点。现在我想在交点处停止绘图。我该怎么做?我可以轻松计算交点的坐标?所以我尝试使用range
或xrange
选项,但它们不适用于用于绘图的非参数函数。
梅威瑟:
\documentclass[a4paper]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
%\usepackage{tikz-3dplot}
\usepackage{tikz,pgfplots,pgf}
\usepackage{xcolor}
\usetikzlibrary{backgrounds,calc,shapes.geometric,intersections}
\usepackage[active,float]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
%% Parametres
%module
\def\ENGmodule {0.4}
%nb dents
\def\ENGdents {30}
%angle de pression
\def\ENGanglepression {20}
%calculs normalisés
%rayon et diamètre primitifs
\pgfmathsetmacro{\ENGrayonprimitif}{\ENGmodule*\ENGdents/2}
%rayon et diamètre de base
\pgfmathsetmacro{\ENGrayonbase}{\ENGrayonprimitif*cos(\ENGanglepression)}
%saillie
\pgfmathsetmacro{\ENGsaillie}{1*\ENGmodule}
\pgfmathsetmacro{\ENGrayonsaillie}{\ENGrayonprimitif+\ENGsaillie}
%pas primitif
\pgfmathsetmacro{\ENGpasprimitif}{pi*\ENGmodule}
%%Utils
%fonction conversion degré en radian
\pgfmathdeclarefunction{degtorad}{1}{\pgfmathparse{#1*pi/180}}
\pgfmathdeclarefunction{radtodeg}{1}{\pgfmathparse{#1*180/pi}}
%fonction involute
\pgfmathdeclarefunction{involute}{1}{\pgfmathparse{tan(#1)-degtorad(#1)}}
\pgfmathdeclarefunction{involuted}{1}{\pgfmathparse{radtodeg(involute(#1))}}
%%Courbes
%polaire flancs dents
\pgfmathdeclarefunction{flancangle}{3}{\pgfmathparse{involuted(#1)+#3*(#2-1)*radtodeg(\ENGpasprimitif/\ENGrayonprimitif)}}
\pgfmathdeclarefunction{flancpolaire}{1}{\pgfmathparse{\ENGrayonbase/cos(#1)}}
%%% Début dessin
\begin{tikzpicture}
\draw[help lines,step=1mm,gray!50!white] (-1.5*\ENGrayonbase,-1.5*\ENGrayonbase) grid (1.5*\ENGrayonbase,1.5*\ENGrayonbase);
%
\coordinate (orig) at (0,0);
%
\begin{scope}
\draw[red!50!black,name path=cerclesaillie] (orig) circle (\ENGrayonsaillie);
\draw [domain=0:40, blue,name path=flA] plot ({flancangle(\x,1,1)} : {flancpolaire(\x)} );
\draw [domain=0:40, blue,name path=flB] plot ({-flancangle(\x,1,-1)+radtodeg(\ENGpasprimitif/\ENGrayonprimitif)/2} : {flancpolaire(\x)} );
\path[name intersections={of={flA} and cerclesaillie, by={A}}];
\path[name intersections={of={flB} and cerclesaillie, by={B}}];
\end{scope}
\end{tikzpicture}
\end{document}
当前结果(蓝色表示我想在与红线的交点处停止的线):
答案1
您可以使用\clip
而不是计算来实现这一点。见下文。
\documentclass[a4paper]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
%\usepackage{tikz-3dplot}
\usepackage{tikz,pgfplots,pgf}
\usepackage{xcolor}
\usetikzlibrary{backgrounds,calc,shapes.geometric,intersections}
\usepackage[active,float]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
%% Parametres
%module
\def\ENGmodule {0.4}
%nb dents
\def\ENGdents {30}
%angle de pression
\def\ENGanglepression {20}
%calculs normalisés
%rayon et diamètre primitifs
\pgfmathsetmacro{\ENGrayonprimitif}{\ENGmodule*\ENGdents/2}
%rayon et diamètre de base
\pgfmathsetmacro{\ENGrayonbase}{\ENGrayonprimitif*cos(\ENGanglepression)}
%saillie
\pgfmathsetmacro{\ENGsaillie}{1*\ENGmodule}
\pgfmathsetmacro{\ENGrayonsaillie}{\ENGrayonprimitif+\ENGsaillie}
%pas primitif
\pgfmathsetmacro{\ENGpasprimitif}{pi*\ENGmodule}
%%Utils
%fonction conversion degré en radian
\pgfmathdeclarefunction{degtorad}{1}{\pgfmathparse{#1*pi/180}}
\pgfmathdeclarefunction{radtodeg}{1}{\pgfmathparse{#1*180/pi}}
%fonction involute
\pgfmathdeclarefunction{involute}{1}{\pgfmathparse{tan(#1)-degtorad(#1)}}
\pgfmathdeclarefunction{involuted}{1}{\pgfmathparse{radtodeg(involute(#1))}}
%%Courbes
%polaire flancs dents
\pgfmathdeclarefunction{flancangle}{3}{\pgfmathparse{involuted(#1)+#3*(#2-1)*radtodeg(\ENGpasprimitif/\ENGrayonprimitif)}}
\pgfmathdeclarefunction{flancpolaire}{1}{\pgfmathparse{\ENGrayonbase/cos(#1)}}
%%% Début dessin
\begin{tikzpicture}
\draw[help lines,step=1mm,gray!50!white] (-1.5*\ENGrayonbase,-1.5*\ENGrayonbase) grid (1.5*\ENGrayonbase,1.5*\ENGrayonbase);
%
\coordinate (orig) at (0,0);
%
\draw [red!50!black,name path=cerclesaillie] (orig) circle (\ENGrayonsaillie);
\begin{scope}
\clip (orig) circle (\ENGrayonsaillie);
\draw [domain=0:40, blue,name path=flA] plot ({flancangle(\x,1,1)} : {flancpolaire(\x)} );
\draw [domain=0:40, blue,name path=flB] plot ({-flancangle(\x,1,-1)+radtodeg(\ENGpasprimitif/\ENGrayonprimitif)/2} : {flancpolaire(\x)} );
\path[name intersections={of={flA} and cerclesaillie, by={A}}];
(A) circle (2pt);
\path[name intersections={of={flB} and cerclesaillie, by={B}}];
\end{scope}
\end{tikzpicture}
\end{document}
我已将红色圆圈移到 之外scope
,然后在 内scope
复制圆圈(不draw
复制)并将其设置为 内其他元素的剪切路径scope
。
我得到的结果:
要填充两条蓝线之间的区域,您可以连接两条路径并使用\fill
:
\documentclass[a4paper]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
%\usepackage{tikz-3dplot}
\usepackage{tikz,pgfplots,pgf}
\usepackage{xcolor}
\usetikzlibrary{backgrounds,calc,shapes.geometric,intersections}
\usepackage[active,float]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
%% Parametres
%module
\def\ENGmodule {0.4}
%nb dents
\def\ENGdents {30}
%angle de pression
\def\ENGanglepression {20}
%calculs normalisés
%rayon et diamètre primitifs
\pgfmathsetmacro{\ENGrayonprimitif}{\ENGmodule*\ENGdents/2}
%rayon et diamètre de base
\pgfmathsetmacro{\ENGrayonbase}{\ENGrayonprimitif*cos(\ENGanglepression)}
%saillie
\pgfmathsetmacro{\ENGsaillie}{1*\ENGmodule}
\pgfmathsetmacro{\ENGrayonsaillie}{\ENGrayonprimitif+\ENGsaillie}
%pas primitif
\pgfmathsetmacro{\ENGpasprimitif}{pi*\ENGmodule}
%%Utils
%fonction conversion degré en radian
\pgfmathdeclarefunction{degtorad}{1}{\pgfmathparse{#1*pi/180}}
\pgfmathdeclarefunction{radtodeg}{1}{\pgfmathparse{#1*180/pi}}
%fonction involute
\pgfmathdeclarefunction{involute}{1}{\pgfmathparse{tan(#1)-degtorad(#1)}}
\pgfmathdeclarefunction{involuted}{1}{\pgfmathparse{radtodeg(involute(#1))}}
%%Courbes
%polaire flancs dents
\pgfmathdeclarefunction{flancangle}{3}{\pgfmathparse{involuted(#1)+#3*(#2-1)*radtodeg(\ENGpasprimitif/\ENGrayonprimitif)}}
\pgfmathdeclarefunction{flancpolaire}{1}{\pgfmathparse{\ENGrayonbase/cos(#1)}}
%%% Début dessin
\begin{tikzpicture}
\draw[help lines,step=1mm,gray!50!white] (-1.5*\ENGrayonbase,-1.5*\ENGrayonbase) grid (1.5*\ENGrayonbase,1.5*\ENGrayonbase);
%
\coordinate (orig) at (0,0);
%
\draw [red!50!black,name path=cerclesaillie] (orig) circle (\ENGrayonsaillie);
\begin{scope}
\clip (orig) circle (\ENGrayonsaillie);
\fill [domain=0:40, blue,name path=flA] plot ({flancangle(\x,1,1)} : {flancpolaire(\x)} ) -- plot [domain=40:0] ({-flancangle(\x,1,-1)+radtodeg(\ENGpasprimitif/\ENGrayonprimitif)/2} : {flancpolaire(\x)} );
\end{scope}
\end{tikzpicture}
\end{document}
看起来像这样:
注意:这种方法仍然避免计算红线和蓝线的交点。