畫橢圓的問題

畫橢圓的問題

我試著使用 繪製一個橢圓的一部分\pgfpatharcto。然而,當我嘗試與原來的完整橢圓進行比較時,發現存在細微差別。我附上程式碼和結果。

\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}

在此輸入影像描述

答案1

也可以繪製兩倍的橢圓,但第二次在剪切範圍內:

\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}

在此輸入影像描述

答案2

你可能想嘗試梅塔普斯特去做這個。它有一個有用的subpath語法,可以讓您繪製已儲存路徑的分段。編譯用lualatex.

在此輸入影像描述

\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 提供了沿路徑的「時間」概念。在一條fullcircle路徑上,從「3 點鐘」的 0 點開始,有 8 個時間點。

所以subpath (0,2) of c從三點到中午。您也可以使用小數:subpath (2.718, 3.1415) of c.

正如我的範例所示,您可以使用負數來引用點 0“之前”的點。

相關內容