1

Let's say I draw a line from point A to point B. I was wondering if there is a way in tkz-euclide, or tikz if necessary, to extend the line beyond B by a set distance without having to set a specific coordinate for an endpoint C? At the moment I'm guessing the endpoint and using \tkzDrawSegment(B,C). I realize I could also do it using some arithmetic based on the slope of AB but wondered if there is something built in that is more automatic.

\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}

O'Neil
  • 205
rhody
  • 1,020
  • Use TikZ, \draw (A)--(B)--([turn]0:1) means drawing a segment from A' toB, and drawing1`cm more in the direction of A--B – Black Mild Nov 27 '22 at 17:00
  • @rhody answer has been edited to elaborate extension of coordinate B at other angles and distances – js bibra Nov 28 '22 at 03:08

3 Answers3

2

Does this satisfy-- you could define a third coordinate C with the help of

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

the coordinate can be labelled C with the help of [label=0:C] where 0 is the angle of the label and C is the text of the label

MWE

\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}

enter image description here

Alternatively if you do not want the line B--C to be seen replace draw with path as below

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

In case you do not want any label on the coordinate C simply remove the [label=0:C] option

MWE

\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}

enter image description here

Simply rinse and repeat for any number of extended coordinates

The lines have been numbered here for help in defining intersections(which have not been used here) -- please see https://tex.stackexchange.com/a/476785/197451

EDIT

Further elaboration of extending coordinate B at other angles and different 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}

enter image description here

js bibra
  • 21,280
1

I found a way that is briefly described in the manual. One uses the add option when you draw the line.

For example this will extend the line AB to the right by 10%

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

This will extend the line to the right by 20% and to the left by 50%

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

I don't know if there is a way to get the coordinates of the new endpoints from which one could do further line extensions.

rhody
  • 1,020
  • 2
    With the calc library of TikZ you can do \draw ($(A)!-.5!(B)$) coordinate (A') -- ($(B)!-.2!(A)$) coordinate (B'); which also gives you these new endpoints. (Or ($(B)!1.5!(A)$) and ($(A)!1.2!(B)$).) – Qrrbrbirlbel Nov 27 '22 at 02:27
  • https://tex.stackexchange.com/questions/476778/tkz-euclide-get-altitude-point-without-drawing?rq=1 – js bibra Nov 27 '22 at 02:45
1

If you want to extend a line then as you found the command is \tkzDrawSegment[add = 0 and .1](A,B) but if you want to know the point obtained you can do

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

Edit: Example of use to draw the intercept theorem:

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

\begin{document}

\begin{tikzpicture} \tkzDefPoint(-1,-1){A} \tkzLabelPointbelow left{A} \tkzDefPoint(1.5,-0.5){B} \tkzLabelPointbelow right{B} \tkzDefPoint(0,2){C} \tkzLabelPointabove{C}

\tkzDefPointWithcolinear=at B, K=0.5\tkzGetPoint{M} \tkzLabelPointbelow right{M} \tkzDefPointWithcolinear=at C, K=0.5\tkzGetPoint{N} \tkzLabelPointabove left{N} \tkzDrawPolygonred %\tkzDrawPolygonblue \tkzDrawSegmentsblue \tkzDrawSegmentsblue \tkzDrawSegmentsblue \end{tikzpicture}

\begin{tikzpicture} \tkzDefPoint(-1,-1){A} \tkzLabelPointbelow right{A} \tkzDefPoint(1.5,-0.5){B} \tkzLabelPointbelow right{B} \tkzDefPoint(0,2){C} \tkzLabelPointabove{C}

\tkzDefPointWithcolinear=at B, K=2\tkzGetPoint{M} \tkzLabelPointbelow left{M} \tkzDefPointWithcolinear=at C, K=2\tkzGetPoint{N} \tkzLabelPointbelow right{N} \tkzDrawPolygonred %\tkzDrawPolygonblue \tkzDrawSegmentsblue \tkzDrawSegmentsblue \tkzDrawSegmentsblue \end{tikzpicture}

\end{document}

enter image description here

enter image description here

PatrickT
  • 2,923
Alain Matthes
  • 95,075