TransWikia.com

Measure/dimension line (line parallel to a line)

TeX - LaTeX Asked on July 5, 2021

I have a problem drawing a slanted "measure line" parallel to a line.

enter image description here

documentclass[border=2pt,tikz]{standalone}
usetikzlibrary{calc}
begin{document}

begin{center}
begin{tikzpicture}
coordinate (A) at (1,1);
coordinate (B) at (4,4);
fill (A) circle(.5mm);
fill (B) circle(.5mm);
draw (A)--(B);
coordinate (P1) at ($($(A)!1!(B)$)!.2cm!90:(B)$);
coordinate (P2) at ($($(A)!0!(B)$)!.2cm!90:(B)$);
draw[|<->|] (P1)--(P2);
end{tikzpicture}
end{center}

end{document}

Notice that the line ends incorrectly using "1" and changing 1 to "0.9999" in (A)!1!(B) makes it better. I guess there is a better way to do this. TIA.

4 Answers

You can just use (A) and (B). Then the segment is long enough to get a good result.

documentclass[border=2pt,tikz]{standalone}
usetikzlibrary{calc}
begin{document}

begin{tikzpicture}
coordinate (A) at (1,1);
coordinate (B) at (4,4);
fill (A) circle(.5mm);
fill (B) circle(.5mm);
draw (A)--(B);
coordinate (P1) at ($(A)!.2cm!90:(B)$);
coordinate (P2) at ($(B)!.2cm!-90:(A)$);
draw[|<->|] (P1)--(P2);
end{tikzpicture}
end{document}

enter image description here

Correct answer by user231225 on July 5, 2021

You can also use a dimline like this:

documentclass[tikz, border=2pt]{standalone}
usepackage{tikz-dimline, calc}
begin{document}
begin{tikzpicture}
coordinate (A) at (1,1);
coordinate (B) at (4,4);
fill (A) circle(.5mm);
fill (B) circle(.5mm);
draw (A)--(B);
dimline[extension start length=0.4 cm, extension end length=0.4 cm] {($(A)!.4cm!90:(B)$)} {($(B)!.4cm!-90:(A)$)}{10};
end{tikzpicture}
end{document}

line with dimline

Or without a label:

dimline[extension start length=0.4 cm, extension end length=0.4 cm, label style=transparent] {($(A)!.4cm!90:(B)$)} {($(B)!.4cm!-90:(A)$)}{};

Answered by hpekristiansen on July 5, 2021

You can also use the - in my opinion - amazing package tkz-euclide and do something like:

documentclass[border=2mm, tikz]{standalone}

usepackage{tkz-euclide}

begin{document}

    begin{tikzpicture}
        tkzDefPoints{
        1/1/A,
        4/4/B}
        tkzDrawSegment[dim={,4mm,transparent}](A,B)
        tkzDrawPoints(A,B)
    end{tikzpicture}

end{document}

enter image description here

Answered by Concept7 on July 5, 2021

Also you can use the [turn] option.

enter image description here

documentclass[border=5mm,tikz]{standalone}
begin{document}
begin{tikzpicture}
path 
(0,0) coordinate (A) node[below]{$A$} 
(4,3) coordinate (B) node[right]{$B$}
(A)--(B)--([turn]90:2mm)  coordinate (Bt)
(B)--(A)--([turn]-90:2mm) coordinate (At);
draw[red] (A)--(B);
draw[|<->|,gray,very thin] (At)--(Bt) node[midway,above,sloped,scale=.8,black]{$5$ cm};
fill (A) circle(1pt) (B) circle(1pt);
end{tikzpicture}
end{document}

Answered by Black Mild on July 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP