3

I was trying to draw a part of one ellipse using \pgfpatharcto. However, when I tried to compare with the original complete ellipse, there is a small difference. I attach the code as well as the result.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}

\draw (2.5cm,0) ellipse (3.5cm and 3.8436cm);

\pgfsetstrokecolor{red}
\pgfmoveto{\pgfpoint{2.841cm}{3.8284cm}}
\pgfpatharcto{3.5cm}{3.8436cm}{0}{0}{0}{\pgfpoint{2.841cm}{-3.8284cm}}\pgfusepath{stroke};

\end{tikzpicture}
\end{document}

enter image description here

4
  • I wound say this is an rounding error? – user31729 Jan 21 '17 at 13:56
  • @ChristianHupfer I am not quite understand your point. Do you have any suggestions to overcome this issue? – yangyang Jan 21 '17 at 14:13
  • (2.841cm,3.8284) is not on the original ellipse. Try (2.841cm,3.82531415cm) instead. 2.841=3.5 cos(84.4088847) 3.82531415 = 3.8436 sin(84.4088847). – John Kormylo Jan 21 '17 at 16:58
  • @JohnKormylo Yes, you are right. The point is indeed not on the original ellipse. I need to check further. Thanks. – yangyang Jan 21 '17 at 18:36
5

It's also possible to draw twice the ellipse but inside a clipping scope the second time:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}

\draw (2.5cm,0) ellipse (3.5cm and 3.8436cm);

\begin{scope}
\clip (2.5cm,0)--++(80:3.9) arc(80:-80:3.9)--cycle;
\draw[red] (2.5cm,0) ellipse (3.5cm and 3.8436cm);
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

0
3

You might like to try Metapost to do this. It has a useful subpath syntax that lets you draw segments of a saved path. Compile with lualatex.

enter image description here

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    path e;
    e = fullcircle xscaled 3.5cm yscaled 3.8436cm;
    draw e withpen pencircle scaled 2 withcolor .8 white;
    draw subpath (-2,2) of e withcolor 2/3 red;
endfig;
\end{mplibcode}
\end{document}

Metapost provides a concept of "time" along a path. On a fullcircle path, there are 8 points of time starting with point 0 at "3 o'clock" as it were.

So subpath (0,2) of c would be from 3 o'clock to midday. You can use fractional numbers too: subpath (2.718, 3.1415) of c.

And as shown in my example you can use negative numbers to refer to points "before" point 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.