Tikz. 创建任意线的垂直线

Tikz. 创建任意线的垂直线

有人知道如何在 Tikz 中生成任意线的垂直线吗?如下所示:

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{quotes,angles} 
\usepackage{tikz-3dplot}

\begin{tikzpicture}
\draw [black, thick,fill=white] (0.0,0.0) circle [radius=0.75];
\draw [->] (0,0) -- (cos{45}*0.75,sin{45}*0.75);
\node at (0.1,0.4) {{ ${r}$}};
\draw [->,thick] (-3,0) -- (-1.75,0);
\draw  [thick] (-1.75,0) -- (-0.5,0.0);
\draw  [thick,dashed] (-0.75,0) -- (0,0);
\draw  [thick,dashed] (0.0,0.0) -- (0.75,0.0);
\draw  [->,thick] (0.5,0.0) -- (1.75,0.0);
\draw  [thick, dashed] (0.0,0.0) -- (0.0,0.75);
\draw  [->,thick] (0.0,0.4) -- (0.0,2);
\node at (1.9,0.0) {{\large $z$}};
\node at (0.0,2.1) {{\large $y$}};
\draw  [thick] (-2.3,-0.25) -- (-2.3,0.25);
\draw  [thick] (-2.2,-0.25) -- (-2.2,0.25);
\path 
    (1,0) coordinate (a)
    -- (0,0) coordinate (O)
    -- (1,1) coordinate (b)
  pic["$\theta$",draw=red,<->,angle eccentricity=1.35,angle radius=0.4cm] {angle=a--O--b};
\end{tikzpicture} 

我很容易就画出了垂直于 x 轴的线。我现在想画出类似于下图中穿过原点的线

\begin{tikzpicture}
\draw [->,thick] (-3.5,0)--(3.5,0) node[right, at end] {\large$x$};
\draw [->,thick] (0,3.5)--(0,-3.5)node[right, at end] {\large$y$};;
\draw[thick] (-3,-2) -- (3,2);
\path 
    (0,3.5) coordinate (a)
    -- (0,0) coordinate (O)
    -- (3,2) coordinate (b)
  pic["$\theta_1$",draw=red,<->,angle eccentricity=1.2,angle radius=1cm] {angle=b--O--a};
\draw [thick] (3,-2)--(-3,2);
\path 
    (0,3.5) coordinate (e)
    -- (0,0) coordinate (O)
    -- (-3,2) coordinate (f)
  pic["$\theta_1$",draw=red,<->,angle eccentricity=1.2,angle radius=1cm] {angle=e--O--f};
\draw[->,very thick] (-3,-2)--(-1.5,-1);
\node at (-1.5,-1.3) {{$\mathbf{l}$}};

\end{tikzpicture}

有任何想法吗?!

答案1

加载calc库后,您可以绘制垂直线。为了便于您查看,我将线画成了虚线。

输出

在此处输入图片描述

代码

\documentclass[margin=10pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz}

\usetikzlibrary{calc,quotes,angles}

\begin{document}
\begin{tikzpicture}

\coordinate (O) at (0,0);

\draw [->,thick] (-3.5,0)--(3.5,0) node[right, at end] {\large$x$};
\draw [->,thick] (0,3.5) coordinate (topy) --(0,-3.5)node[right, at end] {\large$y$};;
\draw[thick] (-3,-2) -- (3,2) coordinate (line1);
\path 
    (topy)
    -- (O)
    -- (line1)
  pic["$\theta_1$",draw=red,<->,angle eccentricity=1.2,angle radius=1cm] {angle=line1--O--topy};
\draw [thick, dashed] ($(O)!3.5cm!90:(line1)$) coordinate (f) -- ($(O)!3.5cm!-90:(line1)$);
\path 
    (topy)
    -- (O)
    -- (f) 
  pic["$\theta_1$",draw=red,<->,angle eccentricity=1.2,angle radius=1cm] {angle=topy--O--f};
\draw[->,very thick] (-3,-2)--(-1.5,-1);
\node at (-1.5,-1.3) {{$\mathbf{l}$}};

\end{tikzpicture}

相关内容