我是 TikZ 的新手,我想展示一个矢量是可以分解为
我怎样才能告诉 TikZ 绘制一条与是到X和一个向量ε正交于X,从原点开始?这是代码,但缺少投影。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning,arrows.meta}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm]
\draw[thick,->] (-4.5,0) -- (4.5,0);
\draw[thick,->] (0,0) -- (0,4.5);
\coordinate (A) at (0,0);
\coordinate (B) at (-4,3);
\draw [extended line=0.5cm, <->] (A) -- (B)
node[pos=0.8,left=1em, font=\small]{$X$};
\draw [ ->] (0,0) -- (-2.6, 4.3) node[anchor=north east,font=\small] {$y$};
\end{tikzpicture}
\end{document}
答案1
可以使用 来将坐标投影到和(yn)
之间的线上,如(A)
(B)
($(A)!(yn)!(B)$)
Marian G. 链接的帖子为了得到图像,你可能想要简单地(意味着没有交叉点、明确的角度等)做
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm]
\draw[thick,-stealth] (-4.5,0) -- (4.5,0);
\draw[thick,-stealth] (0,0) -- (0,4.5);
\coordinate (A) at (0,0);
\coordinate (B) at (-4,3);
\draw [extended line=0.5cm, stealth-stealth] (A) -- (B) node[pos=1.15,font=\small]{$X$};
\draw [ -stealth] (0,0) -- (-2.6, 4.3) coordinate (yn) node[right]{$y$};
\draw[dashed] (yn) -- node[midway,above left]{$\varepsilon$} ($(A)!(yn)!(B)$) node[below left]{$y_p$};
\end{tikzpicture}
\end{document}
答案2
作为起点:
\documentclass[12pt,tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
calc,
intersections,
quotes}
\begin{document}
\begin{tikzpicture}[
lbl/.style = {inner sep=2pt, font=\footnotesize, sloped},
every path/.style = {-Straight Barb},
extended line/.style = {shorten >=-#1,shorten <=-#1},
extended line/.default = 1cm
]
\draw[semithick] (-4.5,0) -- (4.5,0);
\draw[semithick] (0,-0.5) -- (0,4.5);
%
\coordinate (A) at (0,0);
\coordinate (B) at (-3.2,1.6);
\coordinate (C) at (-2.6,4.3);
%
\path[name path=X] (A) -- (C); % <---
\path[name path=P] (B) -- ($(B)!1!90:(A)$); % <---
\draw[name intersections={of=P and X, by={p}}, % <---
dashed,->] % <---
(B) -- node[lbl,above] {$y_q$} (p); % <---
\draw[thick] (A) -- node[lbl,above] {$y$}
(p) node[above] {$Y$};
\draw[dashed] (A) -- node[lbl,below] {$y_d$} (B);
\end{tikzpicture}
\end{document}