我在使用交点功能时遇到了问题。它能用,但似乎有点“错过”真正的交点。下面的代码给我带来了错误。看这张图片(因为 <10 个代表点,所以不能直接发布):
请注意,点 E2 位于真实交点的右下方。这只是计算错误吗?还是我做错了什么?
干杯,
特雷弗
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,trees,calc}
\usetikzlibrary{intersections}
\usepackage{relsize}
\begin{tikzpicture}[
scale=2.2,
dot/.style={circle, fill=black, minimum size=4pt, inner sep=0pt},]
\newcommand\Sshift{0.8cm}
\coordinate (D_1L) at (0.2,1.8); % DL begin
\coordinate (D_2L) at (2.3,0.2); % DL end
\coordinate (S_1L) at (0.2,0.2); % SL begin
\coordinate (S_2L) at (1.8,1.8); % SL end
\coordinate (S_21L) at ([xshift=\Sshift] S_1L);
\coordinate (S_22L) at ([xshift=\Sshift] S_2L);
\draw[axis,<->] (2.8,0) node(Sxaxis)[right] {$Q_{sec}$}
-| (0,2) node(Syaxis)[above] {$P_{sec}$};
\draw[line, thick] (S_1L) -- (S_2L) node[right] {$S_1$};
\draw[line] (D_1L) -- (D_2L) node[right] {$D$};
\draw[line, thick] (S_21L) -- (S_22L) node[right] (S_22L) {$S_2$};
% intersections
\coordinate (E1L) at (intersection of S_1L--S_2L and D_1L--D_2L);
\draw[dashed] (Syaxis |- E1L) node[left]{$P_1$}
-| (Sxaxis -|E1L) node[below]{$Q_1$};
\node[dot, label=above:{$E_1$}] (E1) at (E1L) {};
\coordinate (E2L) at (intersection of S_21L--S_22L and D_1L--D_2L);
\draw[dashed] (Syaxis |- E2L) node[left]{$P_2$}
-| (Sxaxis -|E2L) node[below]{$Q_2$};
\node[dot, label=right:{$E_2$}] (E2) at (E2L) {};
\end{tikzpicture}
答案1
你在这里犯了一个错误(我删除了未知的样式)
\draw[,thick] (S_21L) -- (S_22L) node[right] (S_22L) {$S_2$};
您需要删除最后一个 (S_22L)
\draw[, thick] (S_21L) -- (S_22L) node[right] {$S_2$};
(S_22L)
您用移动坐标node[right]
, S_22L)
现在不在线上。
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,trees,calc}
\usetikzlibrary{intersections}
\usepackage{relsize}
\begin{document}
\begin{tikzpicture}[
scale=2.2,
dot/.style={circle, fill=black, minimum size=4pt, inner sep=0pt},]
\newcommand\Sshift{0.8cm}
\coordinate (D_1L) at (0.2,1.8); % DL begin
\coordinate (D_2L) at (2.3,0.2); % DL end
\coordinate (S_1L) at (0.2,0.2); % SL begin
\coordinate (S_2L) at (1.8,1.8); % SL end
\coordinate (S_21L) at ([xshift=\Sshift] S_1L);
\coordinate (S_22L) at ([xshift=\Sshift] S_2L);
\draw[<->] (2.8,0) node (Sxaxis)[right] {$Q_{sec}$}
-| (0,2) node (Syaxis)[above] {$P_{sec}$};
\draw[, thick] (S_1L) -- (S_2L) node[right] {$S_1$};
\draw[] (D_1L) -- (D_2L) node[right] {$D$};
\draw[, thick] (S_21L) -- (S_22L) node[right] {$S_2$};
% intersections
\coordinate (E1L) at (intersection of S_1L--S_2L and D_1L--D_2L);
\draw[dashed] (Syaxis |- E1L) node[left]{$P_1$}
-| (Sxaxis -|E1L) node[below]{$Q_1$};
\node[dot, label=above:{$E_1$}] (E1) at (E1L) {};
\coordinate (E2L) at (intersection of S_21L--S_22L and D_1L--D_2L);
\draw[dashed] (Syaxis |- E2L) node[left]{$P_2$}
-| (Sxaxis -|E2L) node[below]{$Q_2$};
\node[dot, label=right:{$E_2$}] (E2) at (E2L) {};
\end{tikzpicture}
\end{document}
答案2
使用tzplot
包裹:
\documentclass[tikz]{standalone}
\usepackage{tzplot}
\begin{document}
\begin{tikzpicture}[scale=2.2]
\tzaxes(3,2){$Q_{sec}$}{$P_{sec}$}
\tzline"DL"(0.2,1.8)(2.3,0.2){$D$}[r]
\tzline[thick]"SL1"(0.2,0.2)(1.8,1.8){$S_1$}[r]
\tzline[thick]<.8,0>"SL2"(0.2,0.2)(1.8,1.8){$S_2$}[r] % shifted
\tzXpoint*{DL}{SL1}(E1){$E_1$}
\tzXpoint*{DL}{SL2}(E2){$E_2$}[0]
\tzproj(E1){$Q_1$}{$P_1$}
\tzproj(E2){$Q_2$}{$P_2$}
\end{tikzpicture}
\end{document}