两个命令对同一条线的绘制结果不一致

两个命令对同一条线的绘制结果不一致

我有一条带有方程的线y = (3/5)x + 1,并且我使用 绘制了网格线TikZ。每个单位对应0.5cm。命令

\draw[<->] ({-7/2},{((3/5)*(-7) + 1)/2}) -- ({7/2},{((3/5)*7 + 1)/2});

\draw[<->] (-3.5, -3.2)(3.5, 5.2);

应该画出相同的线。但事实并非如此。起初,我注意到点(-5,-2)(0,1)(5,4)不属于这两条线。现在,我发现这两条线的定义域甚至不一样!

我知道这条线的第一个代码看起来有点混乱。calc不过,这个包应该能够“处理”这个问题。有时我也需要绘制一条斜率为 $1/\sqrt{2}$ 的线。

    \documentclass{amsart}
    \usepackage{amsmath}
    \usepackage{amsfonts}

    \usepackage{tikz}
    \usetikzlibrary{calc,positioning,intersections}


    \begin{document}

    \begin{tikzpicture}


    %Some distances from the origin along the axes are labeled. (The horizontal spacing occupied by
    %the minus sign indicating the additive inverse of a number is ignored so that the number is
    %centered a horizontal or vertical line.)
    \node[fill=white, anchor=north, inner sep=0.15cm, font=\tiny] at (-3,0){\makebox[0pt][r]{$-$}$6$};
    \node[fill=white, anchor=north, inner sep=0.15cm, font=\tiny] at (-2,0){\makebox[0pt][r]{$-$}$4$};
    \node[fill=white, anchor=north, inner sep=0.15cm, font=\tiny] at (-1,0){\makebox[0pt][r]{$-$}$2$};
    \node[fill=white, anchor=north, inner sep=0.15cm, font=\tiny] at (1,0){2};
    \node[fill=white, anchor=north, inner sep=0.15cm, font=\tiny] at (2,0){4};
    \node[fill=white, anchor=north, inner sep=0.15cm, font=\tiny] at (3,0){6};

    \node[fill=white, anchor=east, inner sep=0.15cm, font=\tiny] at (0,-2){\makebox[0pt][r]{$-$}$4$};
    \node[fill=white, anchor=east, inner sep=0.15cm, font=\tiny] at (0,-1){\makebox[0pt][r]{$-$}$2$};
    \node[fill=white, anchor=east, inner sep=0.15cm, font=\tiny] at (0,1){2};
    \node[fill=white, anchor=east, inner sep=0.15cm, font=\tiny] at (0,2){4};


    %The axes are drawn.
    \draw[latex-latex] (-4,0) -- (4,0);
    \draw[latex-latex] (0,-3) -- (0,3);
    \node [anchor=north west] at (4,0) {$x$};
    \node [anchor=south west] at (0,3) {$y$};


    %A grid on the Cartesian plane is drawn with dashed, gray lines.
    \foreach \x in {-2.5,-2,...,2.5} \draw[dashed,gray!50] (-3.75,\x) -- (3.75,\x);
    \foreach \x in {-3.5,-3,...,3.5} \draw[dashed,gray!50] (\x,-2.75) -- (\x,2.75);

%Line k is drawn with two commands. An equation for the line is y = (3/5)x + 1.
%This line is drawn a bit to the left of the vertical line x=-7
%and a bit  to the right of the vertical line x=7.

%
    \draw[<->] ($({-7/2},{((3/5)*(-7) + 1)/2}) +({(-1/2)/2}, {{(3/5)*((-1/2)/2)}})$)
    -- ($({7/2},{((3/5)*7 + 1)/2}) +({(1/2)/2}, {{(3/5)*((-1/2)/2)}})$);
    %
    \draw[<->] (-3.5,-1.6) -- (3.5,2.6);


    \end{tikzpicture}

    \end{document}

答案1

是你把事情复杂化了,还是我把事情简单化了?我太笨了,看不出你从哪里得到这些坐标计算,你不就是想要吗\draw[<->] (-7/2,{((3/5)*(-7) + 1)/2}) -- (7/2,{((3/5)*7 + 1)/2});

(顺便说一句,如果你使用的话pgfplots你根本不必考虑这些事情。)


但是,你的错误是在该线的最后一个 y 坐标上:

\draw[<->] ($({-7/2},{((3/5)*(-7) + 1)/2}) +({(-1/2)/2}, {{(3/5)*((-1/2)/2)}})$)
    -- ($({7/2},{((3/5)*7 + 1)/2}) +({(1/2)/2}, {{(3/5)*((-1/2)/2)}})$);

实际应该是 (1/2),而实际却是 (-1/2)。

话虽如此,你确实把事情弄得比需要的更难了。\draw上面的命令所做的是从 -7.5 到 7.5 画一条线,而不是从 -7 到 7。你可以用下面的命令得到完全相同的结果

\draw[<->] (-7.5/2,{((3/5)*(-7.5) + 1)/2}) -- (7.5/2,{((3/5)*7.5 + 1)/2});

我认为它更简短并且更容易阅读。

另外值得一提的是,如果您的目标只是稍微延长一下线路,那么您可以使用shorten,如\draw[<->,shorten >=-0.125cm,shorten <=-0.125cm] (-7/2,{((3/5)*(-7) + 1)/2}) -- (7/2,{((3/5)*7 + 1)/2});

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections}
\begin{document}
\begin{tikzpicture}
%Some distances from the origin along the axes are labeled. (The horizontal spacing occupied by
%the minus sign indicating the additive inverse of a number is ignored so that the number is
%centered a horizontal or vertical line.)
\foreach \x in {2,4,6}
  {
   \node[fill=white, anchor=north, inner sep=0.15cm, font=\tiny] at (-\x/2,0){\makebox[0pt][r]{$-$}$\x$};
   \node[fill=white, anchor=north, inner sep=0.15cm, font=\tiny] at (\x/2,0){$\x$};   
  }

\foreach \y in {2,4,6}
  {
   \node[fill=white, anchor=east, inner sep=0.15cm, font=\tiny] at (0,-\y/2,0){\makebox[0pt][r]{$-$}$\y$};
   \node[fill=white, anchor=east, inner sep=0.15cm, font=\tiny] at (0,\y/2){$\y$};   
  }


%The axes are drawn.
\draw[latex-latex] (-4,0) -- (4,0);
\draw[latex-latex] (0,-3) -- (0,3);
\node [anchor=north west] at (4,0) {$x$};
\node [anchor=south west] at (0,3) {$y$};


%A grid on the Cartesian plane is drawn with dashed, gray lines.
\foreach \x in {-2.5,-2,...,2.5} \draw[dashed,gray!50] (-3.75,\x) -- (3.75,\x);
\foreach \x in {-3.5,-3,...,3.5} \draw[dashed,gray!50] (\x,-2.75) -- (\x,2.75);



%Line k is drawn with two commands. An equation for the line is y = (3/5)x + 1.
%
\draw[<->,green,ultra thick] (-7.5/2,{((3/5)*(-7.5) + 1)/2}) -- (7.5/2,{((3/5)*7.5 + 1)/2});
%
\draw[<->,red,thick] (-3.5,-1.6) -- (3.5,2.6);

\draw[<->,blue,thin,,samples at={-3.5,3.5}] plot (\x,{\x*3/5 + 0.5});

\draw[<->] ($({-7/2},{((3/5)*(-7) + 1)/2}) +({(-1/2)/2}, {{(3/5)*((-1/2)/2)}})$)
    -- ($({7/2},{((3/5)*7 + 1)/2}) +({(1/2)/2}, {{(3/5)*((1/2)/2)}})$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容