![交点 -| 命名坐标和计算坐标](https://linux22.com/image/474517/%E4%BA%A4%E7%82%B9%20-%7C%20%E5%91%BD%E5%90%8D%E5%9D%90%E6%A0%87%E5%92%8C%E8%AE%A1%E7%AE%97%E5%9D%90%E6%A0%87.png)
我想使用命名坐标和计算坐标的交点,换句话说,命名坐标的 y 坐标,但计算坐标的 x 坐标,例如下面的点 Z,它具有
- X 的 y 坐标
- x 坐标
($(A)!0.5!(B)$)
但(X -| $(A)!0.5!(B)$)
没有用...还有其他选择吗?
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\begin{document}
\begin{tikzpicture}[dot/.style={circle, fill=black, inner sep=0, minimum width=1mm}]
\node [dot] (A) at (0.5,0) {} node[below=0.1mm of A]{A};
\node [dot] (B) at (2,3) {} node[below=0.1mm of B]{B};
\node [dot] (X) at (0,5) {} node[below=0.1mm of X]{X};
\draw (A) -- (B);
\draw (X) -| ($(A)!0.5!(B)$);
\node [dot] (Y) at (X -| B){} node[above=0.1mm of Y]{Y};
\coordinate(AB) at ($(A)!0.5!(B)$);
\node [dot] (Z) at (X -| AB){} node[above=0.1mm of Z]{Z};
\end{tikzpicture}
\end{document}
答案1
这可以通过用大括号括起来来实现$(A)!0.5!(B)$
。
X
在原始代码中,在、A
和处的点和线之间有一个小空格B
。使用选项 可以删除此空格outer sep=0pt
。
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\begin{document}
\begin{tikzpicture}[dot/.style={circle, fill=black, inner sep=0, minimum width=1mm, outer sep=0pt}]
\node [dot] (A) at (0.5,0) {} node[below=0.1mm of A]{A};
\node [dot] (B) at (2,3) {} node[below=0.1mm of B]{B};
\node [dot] (X) at (0,5) {} node[below=0.1mm of X]{X};
\draw (A) -- (B);
\draw (X) -| ($(A)!0.5!(B)$);
\node [dot] (Y) at (X -| B){} node[above=0.1mm of Y]{Y};
\node [dot] (Z) at (X -| {$(A)!0.5!(B)$}){} node[above=0.1mm of Z]{Z};
\end{tikzpicture}
\end{document}
答案2
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[dot/.style={circle, fill=black, inner sep=0, minimum width=1mm, outer sep=0pt}]
\coordinate[dot, label=below:{A}] (A) at (0.5,0);
\coordinate[dot, label=below:{B}] (B) at (2,3);
\coordinate[dot, label=below:{X}] (X) at (0,5);
\draw (A) -- (B);
\draw (X) -| ($(A)!0.5!(B)$);
\coordinate[dot, label=below:{Y}] (Y) at (X-|B);
\path let \p1=($(A)!0.5!(B)$), \p2=(X) in coordinate[dot, label=above:{Z}] (Z) at (\x1,\y2);
\end{tikzpicture}
\end{document}