[Tex/LaTex] How to divide a segment into n equal pieces in tikz

tikz-pgftkz-collectiontkz-euclide

I want to divide a vector in n pieces. But I want to do this in tikz. Years ago I made my drawing in CorelDraw and the result was this:
enter image description here

Now I want to make it in tikz with this code:

\documentclass{article}
\usepackage{amsmath} %voor wiskundige formules
\usepackage{pgf,tikz}
\usetikzlibrary{arrows, decorations.pathmorphing, calc,intersections,through,backgrounds,snakes,patterns} 
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{fit,arrows.meta}

\begin{document}

\begin{center}
\begin{tikzpicture}
\tkzInit[ymax=5,xmax=5]
\tkzDefPoints{1/1/A, 4/4/B};
\tkzClip
%\tkzGrid
\draw[Circle-stealth] (A) -- (B);
\node[right] at (A) {\tiny aangrijpingspunt};
\end{tikzpicture}
\end{center}
\end{document}

Resulting in this:

enter image description here

But I want to divide that segment [AB] in n pieces.

Thanks.

(And I've already looked at How to divide a line or a curve into n equal pieces and tick it using PSTricks and I couldn't find an answer their, because it is in pstricks and I prefer tikz.)

Best Answer

Since you're using tkz-euclide, you can use it to calculate the length of the path through the command \tkzCalcLength(A,B) and store it in a variable \tkzGetLength{ABl}.

Then we can set the number of "segments" (with \ticknum) we want the path split into and with a simple calculation, we can divide the path equally into those segments. Finally, we can use \tkzMarkSegment[pos=\myl, mark=|](A,B) to place marks | along the path at the designated points.

To change the number of segments, just change the value of \ticknum.

Output

output

Code

\documentclass[margin=10pt]{standalone}
\usepackage{amsmath} %voor wiskundige formules
\usepackage{pgf,tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}
\usetikzlibrary{arrows, decorations.pathmorphing, calc,intersections,through,backgrounds,patterns,fit,arrows.meta}

\newcommand{\ticknum}{10}
\pgfmathsetmacro\min{\ticknum-1}

\begin{document}
\begin{tikzpicture}
\tkzInit[ymax=5,xmax=5]
\tkzDefPoints{1/1/A, 4/4/B};
\tkzClip
%\tkzGrid
\draw[Circle-stealth] (A) -- (B);
\node[right] at (A) {\tiny aangrijpingspunt};

\tkzCalcLength(A,B)\tkzGetLength{ABl} % calculates and stores length

\foreach \x in {1,...,\min}{
    \pgfmathsetmacro\myl{((\ABl/\ticknum)/\ABl)*\x}
    \tkzMarkSegment[pos=\myl, mark=|](A,B)
}
\end{tikzpicture}
\end{document}