在Latex中为两个曲线的交集区域添加阴影。

huangapple go评论87阅读模式
英文:

Shade the intersection area between 2 curves in Latex

问题

我需要绘制一个极坐标图,并填充蓝线(θ = π/8)和红色曲线(r = 4 * sqrt(2) * cos(2*θ))之间的区域。
[图例](https://i.stack.imgur.com/TxjJz.png)

我的当前Latex代码如下(尚未填充区域):

```latex
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{patterns}

\begin{document}
    \begin{tikzpicture}[scale=10]
        
        \begin{scriptsize}
            \draw[->](0,0)--(0.5,0) node[right] {初始线};
            \draw (0.03,0.2) node[right] {$r=4\sqrt{2}\cos{2\theta}$};
            \draw (0,0.01) node[above] {$O$};
            \draw[blue] (0,0)--(0.35,0.15) node[right] {$\theta=\frac{\pi}{8}$};
            \draw[color=red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius=  {4*sqrt(2)*cos(2*\x r)});
            
        \end{scriptsize}
    \end{tikzpicture}
\end{document}

我想问如何填充区域,我搜索过但找不到解决方法(我是初学者)。谢谢您提前帮助!

我尝试通过添加以下行来绘制一个与所需位置不完全匹配的区域:

\draw[fill=gray](0.01,0)to[out=215](0.13,0.053)--(0.06,0.028)--cycle;

<details>
<summary>英文:</summary>

I&#39;m having to draw a polar graph and shade the area between the line (theta = pi/8) (blue line) and the curve (r = 4 * sqrt(2) * cos(2*theta) (red curve).
[Figure](https://i.stack.imgur.com/TxjJz.png)

My current Latex (the area hasn&#39;t been shaded)

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}[scale=10]

    \begin{scriptsize}
        \draw[-&gt;](0,0)--(0.5,0) node[right] {initial line};
        \draw (0.03,0.2) node[right] {$r=4\sqrt{2}\cos{2\theta}$};
        \draw (0,0.01) node[above] {$O$};
        \draw[blue] (0,0)--(0.35,0.15) node[right] {$\theta=\frac{\pi}{8}$};
        \draw[color=red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius=  {4*sqrt(2)*cos(2*\x r)});
        
    \end{scriptsize}
\end{tikzpicture}

\end{document}


I want to ask how to shade the area, I searched it but could not find the solution. (I&#39;m the beginner).
Thank you in advance!


I tried to draw an area that not totally fit in the needed position by adding this line:
`\draw[fill=gray](0.01,0)to[out=215](0.13,0.053)--(0.06,0.028)--cycle;`

</details>


# 答案1
**得分**: 2

以下是已翻译的内容:

在使用 `\clip` 时非常容易。要求提供封闭的图形,例如圆形、矩形或您通过代码绘制的图形。如果在定义的末尾添加 `cycle`,则简单的 `\draw` 也可以创建多边形。顺便说一下,`[plot]` 也可以创建封闭图形。

以下是基于 `\clip` 的解决方案。有些点必须在“剪切范围”下使用两次,首先在“剪切范围”下,然后在常规层中,因此我定义并命名了一些坐标。出于同样的原因,我创建了一个宏,它被使用两次。

```latex
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{patterns.meta}
\newcommand\eq{80*sqrt(2)*cos(2*\x r)}

\begin{document}
\begin{tikzpicture}
  \path
  coordinate (E) at (0.6,4)
  coordinate (F) at (7,3)
  coordinate (P) at (3,3)
  coordinate (I) at (10,0)
  coordinate (O) at (0,0);
  \begin{scope}
    \clip[domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
    \draw[pattern={Lines[angle=135,distance={0.5mm}]}, pattern color=gray!50] (O)--(F)--(P)--cycle;   % &lt;--- need cycle here
  \end{scope}
  \node at (O) [above=1mm] {$O$};   % nodes also accept distance for labels
  \node at (E) [right] {$r=4\sqrt{2}\cos{2\theta}$};
  \draw[blue] (O)--(F) node[right] {$\theta=\frac{\pi}{8}$};
  \draw[-&gt;,&gt;={latex}] (O)--(I) node[right] {initial line};
  \draw[red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
\end{tikzpicture}
\end{document}

仅供演示,以下是如何通过您的图形剪切一个圆的示例:

\documentclass[tikz,border=2mm]{standalone}
\newcommand\eq{80*sqrt(2)*cos(2*\x r)}
\begin{document}
\begin{tikzpicture}
    \begin{scope}
      \clip[domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
      \draw[fill=green] (0,0) circle (3);
    \end{scope}
    \draw[color=red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
\end{tikzpicture}
\end{document}

在Latex中为两个曲线的交集区域添加阴影。

英文:

It's very easy with \clip. The requirement is to provide closed figures, such as circle, rectangle, or the one you draw by the code. A simple \draw can also create polygons if you append cycle at the end of the definition. Incidentally, [plot] creates close figures, as well.

Below is a solution based on \clip. Some points have to be used twice, first under the "clip scope" and then in regular layer, hence I have defined and named a few coordinates. For the same reason, I created a macro that is used twiced.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{patterns.meta}
\newcommand\eq{80*sqrt(2)*cos(2*\x r)}

\begin{document}
\begin{tikzpicture}
  \path
  coordinate (E) at (0.6,4)
  coordinate (F) at (7,3)
  coordinate (P) at (3,3)
  coordinate (I) at (10,0)
  coordinate (O) at (0,0);
  \begin{scope}
    \clip[domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
    \draw[pattern={Lines[angle=135,distance={0.5mm}]}, pattern color=gray!50] (O)--(F)--(P)--cycle;   % &lt;--- need cycle here
  \end{scope}
  \node at (O) [above=1mm] {$O$};   % nodes also accept distance for labels
  \node at (E) [right] {$r=4\sqrt{2}\cos{2\theta}$};
  \draw[blue] (O)--(F) node[right] {$\theta=\frac{\pi}{8}$};
  \draw[-&gt;,&gt;={latex}] (O)--(I) node[right] {initial line};
  \draw[red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
\end{tikzpicture}
\end{document}

在Latex中为两个曲线的交集区域添加阴影。


Just for demonstration, here's how to clip a circle by your figure:

\documentclass[tikz,border=2mm]{standalone}
\newcommand\eq{80*sqrt(2)*cos(2*\x r)}
\begin{document}
\begin{tikzpicture}
    \begin{scope}
      \clip[domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
      \draw[fill=green] (0,0) circle (3);
    \end{scope}
    \draw[color=red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
\end{tikzpicture}
\end{document}

在Latex中为两个曲线的交集区域添加阴影。

huangapple
  • 本文由 发表于 2023年7月18日 15:07:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710261.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定