我如何在线的上方或给定图中的线上的任何位置写出直线方程,比如沿着直线 AB 或 BC 的边。
\begin{tikzpicture}
\tikzset{dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1}}
\draw (0,5)-- (0,0)node(o){O} --(5,0);
\draw [name path=P1] (2,0)node(d){D(30,0)} -- (0,4)node(a){A};
\draw [name path=P2] (4,0)node(c){C(50,0)} -- (0,2)node(e){E(0,50)};
\path [name intersections={of=P1 and P2,by=b}];
\node [dot=B{(20,30)} ] at (b) {};
\begin{pgfonlayer}{bg} % select background
\path [fill=green!50] (o.center) -- (d.center) -- (b) -- (e.center) -- cycle;
\end{pgfonlayer}
\end{tikzpicture}
答案1
答案2
您可以使用node[right=distance pt, pos=y]{caption}
每条直线或曲线的末端0<y<1
。
\begin{tikzpicture}
\tikzset{dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1}}
\draw (0,5)-- (0,0)node(o){O} --(5,0);
\draw [name path=P1] (2,0)node(d){D(30,0)} -- (0,4)node(a){A}node[right, pos=.8]{$y_1 = m_1x+b_1$};
\draw [name path=P2] (4,0)node(c){C(50,0)} -- (0,2)node(e){E(0,50)}node[right=8pt, pos=.4]{$y_2 = m_2x+b_2$};
\path [name intersections={of=P1 and P2,by=b}];
\node [dot=B{(20,30)} ] at (b) {};
% \begin{pgfonlayer}{bg} % select background
% \path [fill=green!50] (o.center) -- (d.center) -- (b) -- (e.center) -- cycle;
% \end{pgfonlayer}
\end{tikzpicture}
答案3
再次,正如我之前提到的问题,我会将形状标记为形状外部的角。根据上述答案,我建议基于以下方法的解决方案回答在以下 MWE 中呈现:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds,
intersections,
positioning}
\begin{document}
\begin{tikzpicture}[auto=right,
dot/.style = {circle, fill, inner sep=1pt},
every edge/.style = {draw, shorten >=-12mm},
every label/.style = {inner sep=1.5pt}
]
\coordinate[label=below left:O] (o);
\coordinate[label=below:D,right=2 of o] (d);
\coordinate[label=below:C,right=2 of d] (c);
\coordinate[label=left: E,above=2 of o] (e);
\coordinate[label=left: A,above=2 of e] (a);
%
\draw[name path=DA] (d) -- (a) node[pos=0.75] {$y_2=m_2+b_2$};
\draw[name path=CE] (c) -- (e) node[pos=0.45] {$y_1=m_1+b_1$};
\path [name intersections={of=DA and CE,by=b}] (b) node[dot, label=above right:B] {};
%
\draw (o) edge (c) (o) edge (a);
\scoped [on background layer] \fill[green] (o) --(d) -- (b) -- (e);
\end{tikzpicture}
\end{document}