我有一些无理坐标的点,因为我混合使用了极坐标和笛卡尔坐标。我想将一个坐标指定为一个事物的 x 值和另一个事物的 y 值。
在这个特定的例子中,我希望左边的两条线具有相同的左端点。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (left) at (155:2);
\coordinate (top) at (65:2);
\coordinate (bottom) at (245:2);
\coordinate (right) at (335:2);
\coordinate (leftEdge) at ($ (left) + (-2,0) $);
\coordinate (bottomEdge) at ($ (bottom) + (0,-2) $);
\path[draw=black] (left) -- (top) -- (right) -- (bottom) -- cycle;
\path[draw=blue] (left) -- (leftEdge);
\path[draw=black] (bottom) -- (bottomEdge);
\path[draw=red] (bottom) -- ++(-2,0);
\end{tikzpicture}
\end{document}
我认为有一种方法可以做到这一点(leftEdge.x,bottom.y)
,但我一直无法让它发挥作用。
我怎样才能使红色边缘到达蓝色边缘的左边?
答案1
在您的示例中,您需要做的就是说\path[draw=red] (bottom) -- (bottom-|leftEdge);
。这个很好的答案为您提供了有关此语法的非常好的讨论。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (left) at (155:2);
\coordinate (top) at (65:2);
\coordinate (bottom) at (245:2);
\coordinate (right) at (335:2);
\coordinate (leftEdge) at ($ (left) + (-2,0) $);
\coordinate (bottomEdge) at ($ (bottom) + (0,-2) $);
\path[draw=black] (left) -- (top) -- (right) -- (bottom) -- cycle;
\path[draw=blue] (left) -- (leftEdge);
\path[draw=black] (bottom) -- (bottomEdge);
\path[draw=red] (bottom) -- (bottom-|leftEdge);
\end{tikzpicture}
\end{document}