I'm having some difficulty drawing an arc as part of a path. What I'd like to do is draw a whole ellipse then shade only part of it. The shaded part is defined by four points on the ellipse. I can do this by clipping, but I'd like to understand from where the arc
path is subtended. Additionally, it seems like drawing the path with arcs would be a better option since I can use the cycle
path operation at the end and, ideally, it would cover up the dashed ellipse.
Example code as a starting point:
\documentclass[border=5pt]{standalone}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[every text node part/.style={font=\footnotesize},
>=latex]
\draw (0, 0) [dashed, name path=footprint] circle [x radius=2, y radius=4];
\path [name path=top slice] (-2, 1) -- (2, 1);
\path [name path=bottom slice] (-2, -1) -- (2, -1);
\path [name intersections={of=footprint and {top slice}, name=top}];
\path [name intersections={of=footprint and {bottom slice},
name=bottom}];
\pgfmathanglebetweenpoints{%
\pgfpointorigin}{%
\pgfpointanchor{top-1}{center}}
\let\angleorigr\pgfmathresult
\pgfmathanglebetweenpoints{%
\pgfpointorigin}{%
\pgfpointanchor{bottom-2}{center}}
\pgfmathsetmacro{\angleendr}{\pgfmathresult - 360}
\pgfmathanglebetweenpoints{%
\pgfpointorigin}{%
\pgfpointanchor{top-2}{center}}
\let\angleendl\pgfmathresult
\pgfmathanglebetweenpoints{%
\pgfpointorigin}{%
\pgfpointanchor{bottom-1}{center}}
\pgfmathsetmacro{\angleorigl}{\pgfmathresult}
% It should look something like:
%\begin{scope}
% \path [clip] (-2, 1) -- (2, 1) -- (2, -1) -- (-2, -1) --
% cycle;
% \path [clip] (0, 0) circle [x radius=2, y radius=4];
% \filldraw [fill=lightgray, fill opacity=0.5]
% (-2, 1) -- (2, 1) (2, -1) -- (-2, -1)
% (0, 0) circle [x radius=2, y radius=4];
%\end{scope}
% Using arcs it looks crazy:
\draw [fill=lightgray, opacity=0.5]
(top-2) -- (top-1)
arc [x radius=2, y radius=4, start angle=\angleorigr,
end angle=\angleendr]
(bottom-2) -- (bottom-1)
arc [x radius=2, y radius=4, start angle=\angleorigl,
end angle=\angleendl];
\end{tikzpicture}
\end{document}
So how is the "center point" of the arc component determined (please modify this example to show the path can be generated using arcs)?
($(<current point of the path>)+({-<x radius>*cos(<start angle>)},{-<y radius>*sin(<start angle>)})$)
. One way would be tomoveto
that point before drawing the arc, but that would break filling, I think.