我有两条非线性线。我想在它们之间创建一条(水平)线。我尝试按照手册中的一节操作...但效果并不理想。
手册中的示例:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path (30:1cm) node(p1) {$p_1$} (75:1cm) node(p2) {$p_2$};
\draw (-0.2,0) -- (1.2,0) node(xline)[right] {$q_1$};
\draw (2,-0.2) -- (2,1.2) node(yline)[above] {$q_2$};
\draw[->] (p1) -- (p1 |- xline);
\draw[->] (p2) -- (p2 |- xline);
\draw[->] (p1) -- (p1 -| yline);
\draw[->] (p2) -- (p2 -| yline);
\end{tikzpicture}
\end{document}
我的一段代码。以及目前结果的图片。现在,该线应该从左到右,在两条红线之间(...,1.5)左右,就在蓝线下方。我该怎么做?这可能吗?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\draw[help lines] (-4,0) grid (4,4);
\draw[thick] (-4,0) rectangle (4,4);
\draw[blue, name path=line 1](-4,1.75) -- (4,1.75);
\draw[red, thick, name path=line 2] plot [smooth, tension=0.707] coordinates{(-4,0) (-1.5,3) (4,4)};
\fill[red,name intersections={of=line 1 and line 2,total=\t}]
\foreach \s in {1,...,\t}{(intersection-\s) circle (2pt) node {\footnotesize\s}};
\draw[red, thick, name path=line 3] plot [smooth, tension=0.707] coordinates{(-4,0) (1.5,1) (4,4)};
\fill[red,name intersections={of=line 1 and line 3,total=\t}]
\foreach \s in {1,...,\t}{(intersection-\s) circle (2pt) node {\footnotesize\s}};
\draw[<->, green] (0,1.5) -- (0,1.5 -| line 3); % this line failes
\end{tikzpicture}
\end{document}
答案1
像这样?
我不确定哪些点之间应该画“绿”线。我假设它显示点s1
和之间的距离s2
。如果您希望将其放在其他地方,请告诉我。
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,intersections}
\begin{document}
\begin{tikzpicture}
% grid
\draw[help lines] (-4,0) grid (4,4);
\draw[thick] (-4,0) rectangle (4,4);
% curve 1
\draw[red, thick, name path=line 1]
plot [smooth, tension=0.707] coordinates {(-4,0) (-1.5,3) (4,4)};
% curve 2
\draw[red, thick, name path=line 2]
plot [smooth, tension=0.707] coordinates {(-4,0) ( 1.5,1) (4,4)};
% path for determining of intersections
\draw[blue!50,name path=line 3] (-4,1.75) -- (4,1.75);
\fill[red,name intersections={of=line 1 and line 3, by={s1},}] (s1) circle (1pt);
\fill[red,name intersections={of=line 2 and line 3, by={s2},}] (s2) circle (1pt);
% distancew between s1 and s2
\draw[Straight Barb-Straight Barb, teal] (s1) -- (s2);
\end{tikzpicture}
\end{document}