我想从线 QV 到椭圆的边缘进行着色。我该怎么做?
\documentclass[11pt]{article}
\usepackage{amsmath, amssymb, eucal, yfonts, setspace, sectsty, enumitem, amscd, caption, tikz, tikz-qtree, mathtools, inconsolata, pgfplots, tikz-3dplot, pxfonts, xcolor}
\usepackage[margin=0.75in]{geometry}
\usetikzlibrary{arrows,decorations.markings,calc,fadings,decorations.pathreplacing, patterns, decorations.pathmorphing, positioning}
\allsectionsfont{\sffamily\raggedright\underline}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw (-3.25,0) -- (5,0) node[scale = .8, fill = white] at (-1.625,0) {$a$};
\draw (0,-3.25) -- (0,3.25) node[scale = .8, fill = white] at (0,1.25) {$b$};
\draw[red] (0,0) circle (3cm);
\draw[blue] (0,0) ellipse (3cm and 2.5cm);
\draw (0,0) -- (2.59808,1.5) node[scale = .8, fill = white] at (1.29904,0.75) {$a$};
\filldraw (-3,0) circle (.07cm) node[scale = .8] at (-3.2,-0.25) {$A$};
\filldraw (3,0) circle (.07cm) node[scale = .8] at (3.2,-0.25) {$P$};
\filldraw (0,-2.5) circle (.07cm) node[scale = .8] at (-0.25,-2.7) {$D$};
\filldraw (0,2.5) circle (.07cm) node[scale = .8] at (-0.25,2.7) {$B$};
\filldraw (1.75,0) circle (.07cm) node[scale = .8] at (1.5,-0.25) {$F$};
\filldraw (2.59808,1.5) circle (.07cm) node[scale = .8] at (2.84808,1.75) {$Q$};
\filldraw (0,0) circle (.07cm) node[scale = .8] at (-0.25,-0.25) {$O$};
\draw (2.59808,1.5) -- (2.59808,0);
\filldraw (2.59808,0) circle (.07cm) node[scale = .8] at (2.34808,-0.25) {$V$};
\filldraw[inner color = pink!70!, outer color = blue!40!black] (0,0) -- (0.875,0) arc (0:30:0.875cm);
\node[scale = .8, fill = white] at (0.875,0) {$ae$};
\node[scale = .8] at (1,0.28) {$E$};
\end{tikzpicture}
\end{center}
\end{document}
答案1
你只需要夹子椭圆。intersections library
如果需要,您可以获取一些坐标。
\documentclass[11pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[red] (0,0) circle (3cm);
\draw[blue] (0,0) ellipse (3cm and 2.5cm);
\begin{scope}
\clip (0,0) ellipse (3cm and 2.5cm);
\fill[blue!15] (2.59808,1.5) rectangle (3,0);
\end{scope}
\draw (2.59808,1.5) -- (2.59808,0);
\draw (-3.25,0) -- (5,0) node[scale = .8, fill = white] at (-1.625,0) {$a$};
\draw (0,-3.25) -- (0,3.25) node[scale = .8, fill = white] at (0,1.25) {$b$};
\filldraw (3,0) circle (.07cm) node[scale = .8] at (3.2,-0.25) {$P$};
\filldraw (2.59808,1.5) circle (.07cm) node[scale = .8] at (2.84808,1.75) {$Q$};
\filldraw (2.59808,0) circle (.07cm) node[scale = .8] at (2.34808,-0.25) {$V$};
\end{tikzpicture}
\end{document}
答案2
您可以使用intersections
库来找到椭圆和直线的坐标五到问相交。
命名您想要相交的路径:
\draw[name path=ellipse, blue] (0,0) ellipse (3cm and 2.5cm); \draw[name path=line VQ] (2.59808,1.5) -- (2.59808,0);
使用
name intersections
键找到交叉点。(它将以 的形式提供(Q'-1)
,如果有多个交叉点,TikZ 会将其附加-<number of intersection>
在名称后。)name intersections={of=line VQ and ellipse, name=Q'}
使用库计算该点的角度
calc
。(由于椭圆的中心是,因此(0,0)
我们直接从中心得到角度。)let \p{Q'} = (Q'-1), \n{Q'} = {atan2(\x{Q'}/3cm,\y{Q'}/2.5cm)} in
在下面的路径中您可以使用
\n{Q'}
交点的角度。绘制/填充/图案/…之间的路径五,磷和交叉点问'。
(2.59808,0) -- (3cm,0cm) % from V to P arc[x radius = 3cm, y radius = 2.5cm, start angle = 0, end angle=\n{Q'}] % from P to Q' -- cycle; % back to V
代码
或者在一整个路径中:
% Preamble:
\usetikzlibrary{intersections}
% TikZ picture:
\draw[name path=ellipse, blue] (0,0) ellipse (3cm and 2.5cm);
\draw[name path=line VQ] (2.59808,1.5) -- (2.59808,0);
\path[name intersections={of=line VQ and ellipse, name=Q'}]
let \p{Q'} = (Q'-1),
\n{Q'} = {atan2(\x{Q'}/3cm,\y{Q'}/2.5cm)}
in [
draw=green,
fill=green!50
] (2.59808,0) -- (3cm,0cm)
arc[x radius = 3cm, y radius = 2.5cm, start angle = 0, end angle=\n{Q'}]
-- cycle;
输出
使用命名坐标而不是硬编码数字,让 TikZ/TeX 为您进行计算。
看一下下面的代码。我使用了半自动标记的命名坐标。这些命名坐标用于整个 TikZ 图片。
希望代码中的注释足够有帮助。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings,calc,fadings,intersections}
\tikzset{
mark at/.style args={#1 with #2}{
decoration={
markings,
mark connection node=n#2,
mark=at position #1 with {\node[font=\footnotesize\strut] (n#2) {$#2$};}
},
decorate
}
}
\newcommand*{\myXradius}{3cm}
\newcommand*{\myYradius}{2.5cm}
\newcommand*{\myOverlap}{0.25cm}
\begin{document}
\begin{tikzpicture}[every node/.append style={font=\small}]
% Step 1: Place coordinates and label them.
\foreach \p/\x/\y/\pos in {%
O/ 0/ 0/below left,
A/-\myXradius/ 0/below left,
B/ 0/ \myYradius/above left,
D/ 0/-\myYradius/below left,
P/ \myXradius/ 0/below right%
} \coordinate[label={[name=n\p]\pos:$\p$}] (\p) at (\x,\y);
% Step 1': Place special coordinates and label them (same syntax as before)
\coordinate [label={[name=nQ]above right:$Q$}] (Q) at (30:\myXradius);
\path let \p{Q}=(Q) in coordinate[label={[name=nV]below :$V$}] (V) at (\x{Q},0); % V is Q projected on the x axis
% Step 2: Draw the lines
\draw[mark at=1.625cm with a] (O) -- (180:\myXradius + \myOverlap);
\draw[mark at=1.625cm with b] (O) -- ( 0:\myXradius + \myOverlap);
\draw (90:\myXradius + \myOverlap) -- (270:\myXradius + \myOverlap);
\draw[mark at=.5 with a] (O) -- (Q);
\draw[name path=line VQ] (V) -- (Q);
% Step 3: Draw the ellipses
\draw[ red] (O) circle [ radius = \myXradius ];
\draw[name path=ellipse, blue] (O) ellipse [x radius = \myXradius, y radius = \myYradius];
% Step 4: Find the intersection of the ellipse and the line between V and Q ...
\path[name intersections={of=line VQ and ellipse, name=Q'}]
let \p{Q'} = (Q'-1),
\n{Q'} = {atan2(\x{Q'}/\myXradius,\y{Q'}/\myYradius)}
in [
draw=green,
fill=green!50
]
% ... and draw/fill it ...
(V) -- (P)
arc[x radius = \myXradius, y radius = \myYradius, start angle = 0, end angle=\n{Q'}]
-- cycle
% ... and define a special name to it, as (Q'-1) will be lost after the path.
coordinate (Q') at (Q'-1);
% Step 5: Draw little circles where the coordinates are.
\foreach \p in {O,A,B,D,P,Q,V,Q'} \fill (\p) circle [radius=1.5pt];
% Step X: I have not changes this.
\filldraw[inner color = pink!70!, outer color = blue!40!black] (0,0) -- (0.875,0) arc (0:30:0.875cm);
\node[scale = .8, fill = white] at (0.875,0) {$ae$};
\node[scale = .8] at (1,0.28) {$E$};
\end{tikzpicture}
\end{document}