有没有一种方法可以在不借助复杂算法的情况下在点之间画出任意长度的线?

有没有一种方法可以在不借助复杂算法的情况下在点之间画出任意长度的线?

我正在寻找类似的东西

pointA to pointB, length

其中pointA是起点,pointB是终点,length是从起点到终点的线长。

\documentclass[border=10mm]{standalone}

\usepackage{tikz}

\usetikzlibrary
    {%
        positioning,
        shapes.geometric
    }

% FOLLOWING STYLES ARE NOT IMPORTANT AND CAN BE SKIMMED THROUGH;
\tikzset
    {%
        TRIANGLE/.style=
            {%
                isosceles triangle,
                isosceles triangle apex angle=60,
                minimum size=30mm,
                shape border rotate=270,
                inner sep=0mm,
                outer sep=0mm,
                line width=2mm,
                draw
            },
        LINE/.style=
            {%
                line width=2mm,
                draw=red
            }
    }

\begin{document}
    \begin{tikzpicture}
        \path node[TRIANGLE](T){};
        \path[LINE]
            % FOLLOWING COORDINATES SHOULD SERVE AS POINTS
            %  BETWEEN WHICH A LINE OF ANY SPECIFIED LENGTH CAN BE DRAWN,
            %  NOT OF A FIXED LENGTH SPANNING FROM ONE POINT TO ANOTHER (LIKE IN THIS EXAMPLE);
            % IT CAN BE DONE USING COMPLICATED ARITHMETIC
            %  BUT ARE THERE ANY MEANS IN PGF (OR ELSE) TO MAKE IT SIMPLER?
            (T.right corner)--(T.left side);
    \end{tikzpicture}
\end{document}

输出(绿线是红线应该停止的地方):

答案1

图书馆calc可以做到这一点。

\documentclass[border=10mm]{standalone}

\usepackage{tikz}

\usetikzlibrary
    {%
        calc,
        positioning,
        shapes.geometric
    }

% FOLLOWING STYLES ARE NOT IMPORTANT AND CAN BE SKIMMED THROUGH;
\tikzset
    {%
        TRIANGLE/.style=
            {%
                isosceles triangle,
                isosceles triangle apex angle=60,
                minimum size=30mm,
                shape border rotate=270,
                inner sep=0mm,
                outer sep=0mm,
                line width=2mm,
                draw
            },
        LINE/.style=
            {%
                line width=2mm,
                draw=red
            }
    }

\begin{document}
    \begin{tikzpicture}
        \path node[TRIANGLE](T){};
        \path[LINE]
            % FOLLOWING COORDINATES SHOULD SERVE AS POINTS
            %  BETWEEN WHICH A LINE OF ANY SPECIFIED LENGTH CAN BE DRAWN,
            %  NOT OF A FIXED LENGTH SPANNING FROM ONE POINT TO ANOTHER (LIKE IN THIS EXAMPLE);
            % IT CAN BE DONE USING COMPLICATED ARITHMETIC
            %  BUT ARE THERE ANY MEANS IN PGF (OR ELSE) TO MAKE IT SIMPLER?
            ($(T.right corner)!.3!(T.left side)$)--(T.left side);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容