直角標記未正確顯示

直角標記未正確顯示

TikZ編譯以下程式碼以顯示兩條直角相交的線。一個小正方形,以黑色繪製,邊長為 3 毫米,頂點位於交點,表示直線相交為直角。直角標記彎曲不過,圍繞原點的點。我怎樣才能避免這種扭曲呢? (我希望直角標記遮蓋 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}

相關內容