直角标记未正确显示

直角标记未正确显示

TikZ编译以下代码以显示两条相交成直角的线。用黑色绘制的小正方形,边长为 3mm,顶点位于交点处,表示两条线相交成直角。直角标记弯道但是,在原点的点周围。我怎样才能避免这种扭曲?(我希望直角标记遮住 y 轴,但不遮住原点的点。)

这是我在询问箭头剪辑时发布的类似代码。我认为继续执行此操作的一种方法是发出命令\path[name path=up] (-3.75,3.75) -- (3.75,3.75);,... \path[name path=left] (-3.75,-3.75) -- (-3.75,3.75);,并使用该intersections包标记给定线与这四条路径之间的四个交点的坐标。但我不熟悉如何使用该intersections包。

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,quotes}


\begin{document}


\begin{tikzpicture}[outer sep=0pt,p/.style={circle, fill,inner sep=1.5pt}]

\draw[draw=gray!30,latex-latex] (-3.75,0) +(-0.25cm,0) -- (3.75,0) -- +(0.25cm,0) node[below right] {$x$};
\draw[draw=gray!30,latex-latex] (0,3.75) +(0,0.25cm) node[above right] {$y$} -- (0,-3.75) -- +(0,-0.25cm);

\clip (-3.75,-3.75) rectangle (3.75,3.75);

\draw[gray,dashed,line width=0.1pt] (-3.75,3.75) -- (3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (3.75,-3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (-3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (3.75,-3.75) -- (3.75,3.75);

\draw[draw=blue!30,-latex] (0,0) -- (142:5);
\draw[draw=blue!30,-latex] (0,0) -- (-38:5);
\draw[draw=green!50,-latex] (0,0) -- (52:5);
\draw[draw=green!50,-latex] (0,0) -- (-128:5);

\coordinate[p,label={[fill=white]below right:$O$}] (O) at (0,0);

\coordinate (A) at (0:1);
\coordinate (B) at (52:1);
\path pic[draw, angle radius=5mm,"$\phi$",angle eccentricity=1.25] {angle = A--O--B};

\coordinate (a) at (180:1);
\coordinate (b) at (142:1);
\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = b--O--a};

\coordinate (P) at (142:1);
\coordinate (Q) at (52:1);

\coordinate (R) at ($(O)!4mm! -45:(P)$);
\draw (R) -- ($(O)!(R)!(P)$);
\draw (R) -- ($(O)!(R)!(Q)$);


\filldraw[fill=white] (O) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;


\end{tikzpicture}

\end{document}

答案1

您正在使用样式来p协调Op

p/.style={circle, fill,inner sep=1.5pt}

即,该坐标具有inner sep。因此,当您从 开始绘制直角标记时O,它会从 的边界开始O,并cycle返回到相同的边界点。因此,您会得到失真。要避免这种情况,请使用O.center

哦不!它出现在那个黑色圆圈上O。为了避免这种情况,使用 tikz 库backgrounds并将整个直角标记推到背景层上,如

\begin{scope}[on background layer]
\filldraw[fill=white] (O.center) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{scope}

但您希望直角标记遮住y轴,但这并没有发生。因此,将绘制轴的线y移到上一个范围内代码right angle行如下

\begin{scope}[on background layer]
\draw[draw=gray!30,latex-latex] (0,3.75) +(0,0.25cm) node[above right] {$y$} -- (0,-3.75) -- +(0,-0.25cm);
\filldraw[fill=white] (O.center) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{scope}

完整代码:

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,quotes,backgrounds}


\begin{document}


\begin{tikzpicture}[outer sep=0pt,p/.style={circle, fill,inner sep=1.5pt}]

\draw[draw=gray!30,latex-latex] (-3.75,0) +(-0.25cm,0) -- (3.75,0) -- +(0.25cm,0) node[below right] {$x$};

\clip (-3.75,-3.75) rectangle (3.75,3.75);

\draw[gray,dashed,line width=0.1pt] (-3.75,3.75) -- (3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (3.75,-3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (-3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (3.75,-3.75) -- (3.75,3.75);

\draw[draw=blue!30,-latex] (0,0) -- (142:5);
\draw[draw=blue!30,-latex] (0,0) -- (-38:5);
\draw[draw=green!50,-latex] (0,0) -- (52:5);
\draw[draw=green!50,-latex] (0,0) -- (-128:5);

\coordinate[p,label={[fill=white]below right:$O$}] (O) at (0,0);

\coordinate (A) at (0:1);
\coordinate (B) at (52:1);
\path pic[draw, angle radius=5mm,"$\phi$",angle eccentricity=1.25] {angle = A--O--B};

\coordinate (a) at (180:1);
\coordinate (b) at (142:1);
\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = b--O--a};

\coordinate (P) at (142:1);
\coordinate (Q) at (52:1);

\coordinate (R) at ($(O)!4mm! -45:(P)$);
\draw (R) -- ($(O)!(R)!(P)$);
\draw (R) -- ($(O)!(R)!(Q)$);

\begin{scope}[on background layer]
\draw[draw=gray!30,latex-latex] (0,3.75) +(0,0.25cm) node[above right] {$y$} -- (0,-3.75) -- +(0,-0.25cm);
\filldraw[fill=white] (O.center) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{scope}

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

为什么用正方形来表示直角?你可以用两条线来表示。只需替换

\filldraw[fill=white] (O) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;

\filldraw[fill=white] ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$);

角度图

但是,如果您确实想要正方形,问题在于您没有定义坐标O,因此在其他坐标下方添加\coordinate (O) at (0,0);。我将其涂成红色以显示它。

图形角度

为了不覆盖原点,在序言中添加此内容

\pgfdeclarelayer{bg}   
\pgfsetlayers{bg,main}

然后这样做:

\begin{pgfonlayer}{bg}
\filldraw[red,fill=white] (O) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{pgfonlayer}

相关内容