Tikz。创建任意线的垂直线的问题

Tikz。创建任意线的垂直线的问题

我很难画出一条垂直于圆半径的线。如果我画一条垂直于同一半径但位于线的另一侧的线,就不会遇到同样的问题。我需要两条线都垂直于同一半径。

\documentclass[tikz,border=12pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{angles,calc,math}

\begin{document}

\begin{tikzpicture}[>=stealth]
\coordinate (O) at (0,0);
\coordinate (P) at ($ ({2*cos(60)},{2*sin(60)}) $);
\draw[draw=black, fill opacity=0.2, text opacity=1] (O) circle (2);
\draw [black] (O) -- (P) coordinate (line2) node [midway, left] {$r$};
\draw [->,black] (P) -- ($(P)!1.5cm!-90:(line2)$) node [midway, right] {not perpendicular};
\draw [->,black] (O) -- ($(O)!1.5cm!-90:(line2)$) node [right] {perpendicular};
\end{tikzpicture}

\end{document}

答案1

欢迎!line2P一致。您想line2以这样的方式定义,即与有距离P

\documentclass[tikz,border=12pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[>=stealth]
\coordinate (O) at (0,0);
\coordinate (P) at (60:2);
\draw[draw=black, fill opacity=0.2, text opacity=1] (O) circle[radius=2cm];
\draw [black] (O) -- (P) coordinate[pos=0.5] (line2) node [midway, left] {$r$};
\draw [->,black] (P) -- ($(P)!1.5cm!90:(line2)$) node [right] {perpendicular};
\draw [->,black] (O) -- ($(O)!1.5cm!-90:(line2)$) node [right] {perpendicular};
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者可以将坐标放在前面(P),在这种情况下,我们可以删除pos=0.5,并且正如@frougon所建议的那样,更改坐标的名称。

\documentclass[tikz,border=12pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[>=stealth]
\coordinate (O) at (0,0);
\coordinate (P) at (60:2);
\draw[draw=black, fill opacity=0.2, text opacity=1] (O) circle[radius=2cm];
\draw [black] (O) -- coordinate(OP) (P)  node [midway, left] {$r$};
\draw [->,black] (P) -- ($(P)!1.5cm!90:(OP)$) node [right] {perpendicular};
\draw [->,black] (O) -- ($(O)!1.5cm!-90:(OP)$) node [right] {perpendicular};
\end{tikzpicture}
\end{document}

答案2

[turn]是另一种方法。

PS:我喜欢写作清洁代码。这就是为什么我没有从 OP 的代码中进行更正。

在此处输入图片描述

\documentclass[tikz,border=12pt]{standalone}
\begin{document}
\begin{tikzpicture}
\path 
(0,0) coordinate (O) (60:2) coordinate (P)
(O)--(P)--([turn]-90:1.5) coordinate (M) node[right] {$M$}
(P)--(O)--([turn]90:1.5) coordinate (N) node[right] {$N$};
\draw (P)--(O) node[midway,left] {$r$} circle(2); 
\draw[->] (P)--(M); \draw[->] (O)--(N);
\end{tikzpicture}
\end{document}

答案3

\documentclass{standalone} 
\usepackage{tkz-euclide}
\begin{document} 
\begin{tikzpicture}[thick]
\tkzDefPoint(0,0){A}
\tkzDefPoint({2*cosd(60)},{2*sind(60)}){P}
\tkzDrawCircle(A,P)
\tkzDefPointWith[orthogonal](A,P) 
\tkzDrawLine(A,tkzPointResult)
\tkzDefPointWith[orthogonal](P,A) 
\tkzDrawLine[add=1 and 0](P,tkzPointResult)
\tkzDrawSegment(A,P)
\end{tikzpicture}
\end{document}

在此处输入图片描述

有随机选择点

\documentclass{standalone} 
\usepackage{tkz-euclide}
\begin{document} 
\begin{tikzpicture}
\tkzDefPoints{1/0/A}
\tkzDefRandPointOn[circle = center A radius 1 cm]
\tkzGetPoint{B}
\tkzDefPointWith[orthogonal](A,B)
\tkzDrawSegment(A,tkzPointResult)
\tkzDrawCircle(A,B)
\tkzDrawLine(A,tkzPointResult)
\tkzDefPointWith[orthogonal](B,A) \tkzGetPoint{b}
\tkzDrawLine[add=1 and 0](B,tkzPointResult)
\tkzDrawSegment(A,B)
\tkzMarkRightAngle[fill=gray!30,opacity=.6](A,B,b)
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案4

其他方式

\documentclass[tikz,border=12pt]{standalone}
\begin{document}
\begin{tikzpicture}[>=stealth,declare function={R=2;k=-2;m=5/4;myangle=60;}] 
\path 
(0,0) coordinate (O)
({R*sin(myangle)},{R*cos(myangle)}) coordinate (P)
({R*sin(myangle) + k*R*cos(myangle)},{R*cos(myangle) - k*R*sin(myangle)} ) coordinate (Q);
 \draw (O)  circle[radius=R]; 
\draw[->] (P) -- (Q);
\draw[->] (O) -- ({m*R*cos(myangle)},- {m*R*sin(myangle)} );
\draw (P) -- (O) node[midway,left] {$r$}; 
\foreach \p in {O,P}
\draw[fill=black] (\p) circle (1.5pt);
\foreach \p/\g in {O/180,P/40}
\path (\p)+(\g:3mm) node{$\p$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容