帮助绘制单位圆和线

帮助绘制单位圆和线

我想绘制一个单位圆,上面标有点的坐标以及与圆相交的线,如下所示:

下面粘贴的代码完成了部分工作。但我想要

  1. 坐标越大,
  2. 线条,以及
  3. 标记线的斜率,理想情况下线与标记不相交。

我将非常感谢您的帮助。


% Unit circle % Author: Supreme Aryal
% A unit circle with cosine and sine values for some
% common angles.

\documentclass[landscape]{article}
\usepackage{tikz} %%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}% %%%>

\begin{comment} :Title: Unit circle

A unit circle with cosine and sine values for some common angles.

\end{comment}

\usepackage[top=1in,bottom=1in,right=1in,left=1in]{geometry} \begin{document}
    \begin{tikzpicture}[scale=5.3,cap=round,>=latex]
        % draw the coordinates
        \draw[->] (-1.5cm,0cm) -- (1.5cm,0cm) node[right,fill=white] {$x$};
        \draw[->] (0cm,-1.5cm) -- (0cm,1.5cm) node[above,fill=white] {$y$};

        % draw the unit circle
        \draw[thick] (0cm,0cm) circle(1cm);

        \foreach \x in {0,30,...,360} {
                % lines from center to point
                % dots at each point
                \filldraw[black] (\x:1cm) circle(0.4pt);
                % draw each angle in degrees
        }


        \foreach \x/\xtext/\y in {
            % the coordinates for the first quadrant
            30/\frac{\sqrt{3}}{2}/\frac{1}{2},
            45/\frac{\sqrt{2}}{2}/\frac{\sqrt{2}}{2},
            60/\frac{1}{2}/\frac{\sqrt{3}}{2},
            % the coordinates for the second quadrant
            150/-\frac{\sqrt{3}}{2}/\frac{1}{2},
            135/-\frac{\sqrt{2}}{2}/\frac{\sqrt{2}}{2},
            120/-\frac{1}{2}/\frac{\sqrt{3}}{2},
            % the coordinates for the third quadrant
            210/-\frac{\sqrt{3}}{2}/-\frac{1}{2},
            225/-\frac{\sqrt{2}}{2}/-\frac{\sqrt{2}}{2},
            240/-\frac{1}{2}/-\frac{\sqrt{3}}{2},
            % the coordinates for the fourth quadrant
            330/\frac{\sqrt{3}}{2}/-\frac{1}{2},
            315/\frac{\sqrt{2}}{2}/-\frac{\sqrt{2}}{2},
            300/\frac{1}{2}/-\frac{\sqrt{3}}{2}}
                \draw (\x:1.45cm) node[fill=white] {$\left(\xtext,\y\right)$};

        % draw the horizontal and vertical coordinates
        % the placement is better this way
        \draw (-1.25cm,0cm) node[above=1pt] {$(-1,0)$}
              (1.25cm,0cm)  node[above=1pt] {$(1,0)$}
              (0cm,-1.25cm) node[fill=white] {$(0,-1)$}
              (0cm,1.25cm)  node[fill=white] {$(0,1)$};
    \end{tikzpicture} \end{document}

答案1

也许稍微清理一下会有好处

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fpu}
\begin{document}
\begin{tikzpicture}[cap=round,>=latex,every node/.style={scale=0.5}]
        \draw[->] (-1.5cm,0cm) -- (1.5cm,0cm) node[right,fill=white]{$x$};
        \draw[->] (0cm,-1.5cm) -- (0cm,1.5cm) node[above,fill=white]{$y$};
        \draw[thick] (0cm,0cm) circle(1cm);
% Source of rays
\coordinate (s) at (-1cm,0);
\node[above left] at (-1cm,0) {$(-1,0)$};
\foreach \x in {2,1,0.5,0.333333,-0.25,-1}{
\draw[orange] (s)--++({atan2(1,\x)}:2) node[black,right] {$m=\pgfmathprintnumber[frac]{\x}$};
}
\end{tikzpicture}

\end{document}

在此处输入图片描述

请注意,通过库放置的分数fpu确实对数字输入非常敏感。如果你从中删除几个3s,0.333333你可能会明白我在警告什么 :)

此外,如果您想要放大,节点形状需要关键transform shape选项来遵循当前变换。因此,最好像我通过 所做的那样单独缩放节点every node/.style={...}


对于评论中 Luigi 的问题,我们可以简单地使用半角关系来找到它与圆的交点,然后从该点延伸一个固定的量,以使延伸的长度始终相同。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fpu}
\begin{document}
\begin{tikzpicture}[cap=round,>=latex,every node/.style={scale=0.5}]
        \draw[->] (-1.5cm,0cm) -- (1.5cm,0cm) node[right,fill=white]{$x$};
        \draw[->] (0cm,-1.5cm) -- (0cm,1.5cm) node[above,fill=white]{$y$};
        \draw[thick] (0cm,0cm) circle(1cm);
% Source of rays
\coordinate (s) at (-1cm,0);
\node[above left] at (-1cm,0) {$(-1,0)$};
\foreach \x in {2,1,0.5,0.333333,-0.25,-1}{
\pgfmathsetmacro\myhalfangle{2*atan2(1,\x)}
\draw[orange] (s)-- ({cos(\myhalfangle)},{sin(\myhalfangle)}) 
-- ++(0.5*\myhalfangle:1.2cm) node[black,right] {$m=\pgfmathprintnumber[frac]{\x}$};
}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

@percusse 的回答很棒(当然是+1),但是当涉及到使用轴绘制图片时,我肯定会考虑pgfplots. 输出非常相似

在此处输入图片描述

但结构略有不同

\documentclass{article}

\usepackage{pgfplots}
\usetikzlibrary{fpu}

\pgfplotsset{every axis/.append style={
                    axis x line=middle,    % put the x axis in the middle
                    axis y line=middle,    % put the y axis in the middle
                    axis line style={<->}, % arrows on the axis
                    xlabel={$x$},          % default put x on x-axis
                    ylabel={$y$},          % default put y on y-axis
                    }}


% set the arrows as stealth fighters
\tikzset{>=stealth}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[axis equal,
            xmin=-1.5,xmax=1.5,
            ymin=-1.5,ymax=1.5,
            xtick={-10},
            ytick={-10},
            ]
    \addplot [domain=0:2*pi,samples=50] ({cos(deg(x))},{sin(deg(x))});
    \node  at (axis cs:-1,0)[anchor=south east]{$(-1,0)$};
    \pgfplotsinvokeforeach{1,0.5,0.333333,-0.25,-1}{
        \pgfmathparse{2*cos(atan2(1,#1))-1}
        \addplot[red,->] expression[domain=-1:{\pgfmathresult}]{#1*x+#1}node[black,right] {$m=\pgfmathprintnumber[frac]{#1}$};
    }
  \end{axis}
\end{tikzpicture}

\end{document}

我喜欢这种方法,因为它有轴的全局设置。只需在序言中稍加修改,您就可以为图片增添趣味(使用全局定义的设置),例如

% framing
\pgfplotsset{framed/.style={axis background/.style ={draw=blue,fill=yellow!20,rounded corners=3ex}}}

在此处输入图片描述

\begin{tikzpicture}
  \begin{axis}[axis equal,
            xmin=-1.5,xmax=1.5,
            ymin=-1.5,ymax=1.5,
            xtick={-10},
            ytick={-10},
            minor xtick={-1.5,-1,...,1.5},
            minor ytick={-1.5,-1,...,1.5},
            framed,
            grid=both,
            ]
    \addplot [domain=0:2*pi,samples=50] ({cos(deg(x))},{sin(deg(x))});
    \node  at (axis cs:-1,0)[anchor=south east]{$(-1,0)$};
    \pgfplotsinvokeforeach{1,0.5,0.333333,-0.25,-1}{
        \pgfmathparse{2*cos(atan2(1,#1))-1}
        \addplot[red,->] expression[domain=-1:{\pgfmathresult}]{#1*x+#1}node[black,right] {$m=\pgfmathprintnumber[frac]{#1}$};
    }
  \end{axis}
\end{tikzpicture}

相关内容