如何找到线和圆角矩形之间的交点

如何找到线和圆角矩形之间的交点

我正在尝试在矩形“下方”显示一条线。为此,我尝试使用 Intersections 包,但不知何故,这条线没有停止:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
% rectangle
\fill[name path=hrectangle, fill opacity=.5, rounded corners=1ex, shift={(-4cm,0cm)}, rotate=-30] ( -1,-.5) rectangle ( 1,.5);

% line
\draw[name path=x axis, <->, dashed] (7,0) -- (-4,0);

% intersection
\path[name intersections={of= x axis and hrectangle}];
\foreach \i in {1,...,2}
    \fill [color=red] (intersection-\i) circle (2pt) ;

\end{tikzpicture}
\end{document}

当我编译时出现错误:

Package pgf Error: No shape named intersection-1 is known.
Package pgf Error: No shape named intersection-2 is known.

还有其他方法吗?

编辑:当我添加矩形的圆角时出现问题......

相关内容