使用 tkz-euclide (或 tikz)将线延伸到某个点以外,而不使用明确的端点坐标

使用 tkz-euclide (或 tikz)将线延伸到某个点以外,而不使用明确的端点坐标

假设我从 A 点到 B 点画一条线。我想知道有没有办法tkz-euclide, 或者蒂克兹如果有必要,可以将线延伸到 B 以外的一段距离,而无需为端点 C 设置特定坐标?目前,我正在猜测端点并使用\tkzDrawSegment(B,C)。我意识到我也可以使用基于 AB 斜率的一些算术来做到这一点,但想知道是否有内置的更自动化的东西。

\documentclass{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
\begin{tikzpicture}
  \tkzDefPoint(0,0){A}
  \tkzDefPoint(2,1.4){B}
  \tkzLabelPoints(A)
  \tkzLabelPoints(B)  

  \tkzDrawSegment(A,B)

 % Draw the line further from B by a set distance

\end{tikzpicture}
\end{document}

答案1

我找到了手册中简要描述的一种方法。绘制线条时使用添加选项。

例如,这将使线 AB 向右延伸 10%

 \tkzDrawSegment[add = 0 and .1](A,B)

这会将线向右延长 20%,向左延长 50%

 \tkzDrawSegment[add = 0.5 and .2](A,B)

我不知道是否有办法获取新端点的坐标,以便进行进一步的线路延伸。

答案2

C这是否满足——你可以借助

   \draw [red, thick, name path=line2] (B)--++(\angle+90:3)coordinate[label=0:C](C);

坐标可以C借助[label=0:C]where0 is the angle of the labelC is the text of the label

平均能量损失

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{calc,intersections}
\newcommand{\pgfextractangle}[3]{%
    \pgfmathanglebetweenpoints{\pgfpointanchor{#2}{center}}
    {\pgfpointanchor{#3}{center}}
    \global\let#1\pgfmathresult  
}
\begin{document}
    \begin{tikzpicture}
        \tkzDefPoint(0,0){A}
        \tkzDefPoint(2,1.4){B}
        \tkzLabelPoints(A)
        \tkzLabelPoints(B)  
        
        \tkzDrawSegment[name path=line1](A,B)
        \pgfextractangle{\angle}{A}{B}

        % Draw the line further from B by a set distance
        \draw [red, thick, name path=line2] (B)--++(\angle+90:3)coordinate[label=0:C](C);
        \tkzDrawSegment[blue, thick, name path=line3](A,C)
    \end{tikzpicture}
\end{document}

在此处输入图片描述

或者,如果你不想line B--C被看到,请draw with path按如下方式替换

 \path [red, thick, name path=line2] (B)--++(\angle+90:3)coordinate[label=0:C](C);

如果您不想在坐标 C 上添加任何标签,只需删除该[label=0:C]选项

平均能量损失

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{calc,intersections}
\newcommand{\pgfextractangle}[3]{%
    \pgfmathanglebetweenpoints{\pgfpointanchor{#2}{center}}
    {\pgfpointanchor{#3}{center}}
    \global\let#1\pgfmathresult  
}
\begin{document}
    \begin{tikzpicture}
        \tkzDefPoint(0,0){A}
        \tkzDefPoint(2,1.4){B}
        \tkzLabelPoints(A)
        \tkzLabelPoints(B)  
        
        \tkzDrawSegment[name path=line1](A,B)
        \pgfextractangle{\angle}{A}{B}

        % Draw the line further from B by a set distance
        \path [red, thick, name path=line2] (B)--++(\angle+90:3)coordinate[label=0:C](C);
        \tkzDrawSegment[blue, thick, name path=line3](A,C)
    \end{tikzpicture}
\end{document}

在此处输入图片描述

只需冲洗并重复任意数量的扩展坐标即可

此处已对线进行编号,以帮助定义交叉点(此处未使用)——请参阅https://tex.stackexchange.com/a/476785/197451

编辑

进一步阐述B在其他angles和不同的扩展坐标distances

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{calc,intersections}
\newcommand{\pgfextractangle}[3]{%
    \pgfmathanglebetweenpoints{\pgfpointanchor{#2}{center}}
    {\pgfpointanchor{#3}{center}}
    \global\let#1\pgfmathresult  
}
\begin{document}
    \begin{tikzpicture}
        \tkzDefPoint(0,0){A}
        \tkzDefPoint(2,1.4){B}
        \tkzLabelPoints(A)
        \tkzLabelPoints(B)  
        
        \tkzDrawSegment[name path=line1](A,B)
        \pgfextractangle{\angle}{A}{B}
        
        % Draw the line further from B by a set distance
        \path[] (B)-- ++(\angle:4cm) coordinate (b) node[pos=1.02,anchor=west]{\tiny $(\angle:4cm)$};
        \path[] (B)-- ++(20:1cm) coordinate (x) node[pos=1.02,anchor=west]{\tiny$(20:1cm)$};
        \path[] (B)-- ++(60:2cm) coordinate (y) node[pos=1.02,anchor=west]{\tiny $(60:2cm)$};
        \path[] (B)-- ++(90:3cm) coordinate (z) node[pos=1.02,anchor=west]{\tiny $(90:3cm)$};

        \tkzDrawSegment[blue, thick](A,b)       
        \tkzDrawSegment[blue, thick](A,x)       
        \tkzDrawSegment[blue, thick](A,y)
        \tkzDrawSegment[blue, thick](A,z)               

        \tkzDrawSegment[red, dashed](B,b)
        \tkzDrawSegment[red, dashed](B,x)       
        \tkzDrawSegment[red, dashed](B,y)
        \tkzDrawSegment[red, dashed](B,z)               
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

如果你想延长一条线,那么你发现命令是,\tkzDrawSegment[add = 0 and .1](A,B)但是如果你想知道获得的点,你可以做

\tkzDefPointWith[colinear=at A, K=1.1](A,B)
\tkzGetPoint{C}

编辑:使用截距定理绘制的示例:

\documentclass[tikz,margin=3mm]{standalone}
\usepackage{tkz-euclide}

\begin{document}

\begin{tikzpicture}
  \tkzDefPoint(-1,-1){A}
  \tkzLabelPoint[below left](A){A}
  \tkzDefPoint(1.5,-0.5){B}
  \tkzLabelPoint[below right](B){B}
  \tkzDefPoint(0,2){C}
  \tkzLabelPoint[above](C){C}

  \tkzDefPointWith[colinear=at B, K=0.5](B,A)\tkzGetPoint{M}
  \tkzLabelPoint[below right](M){M}
  \tkzDefPointWith[colinear=at C, K=0.5](C,A)\tkzGetPoint{N}
  \tkzLabelPoint[above left](N){N}
  \tkzDrawPolygon[red](A,M,N)
  %\tkzDrawPolygon[blue](M,B,C,N)
  \tkzDrawSegments[blue](M,B)
  \tkzDrawSegments[blue](B,C)
  \tkzDrawSegments[blue](C,N)
\end{tikzpicture}

\begin{tikzpicture}
  \tkzDefPoint(-1,-1){A}
  \tkzLabelPoint[below right](A){A}
  \tkzDefPoint(1.5,-0.5){B}
  \tkzLabelPoint[below right](B){B}
  \tkzDefPoint(0,2){C}
  \tkzLabelPoint[above](C){C}

  \tkzDefPointWith[colinear=at B, K=2](B,A)\tkzGetPoint{M}
  \tkzLabelPoint[below left](M){M}
  \tkzDefPointWith[colinear=at C, K=2](C,A)\tkzGetPoint{N}
  \tkzLabelPoint[below right](N){N}
  \tkzDrawPolygon[red](A,M,N)
  %\tkzDrawPolygon[blue](M,B,C,N)
  \tkzDrawSegments[blue](A,B)
  \tkzDrawSegments[blue](B,C)
  \tkzDrawSegments[blue](C,A)
\end{tikzpicture}

\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容