I have the points A(0,0) and B(3, 4), I want a point that is 4/6 of the length of AB and lies on the the same line. How to do this?
- 1,968
- 8
- 17
- 313
- 2
- 6
6 Answers
Using TikZ and its calc library you can use the ( $ (<name1>)!<value>!(<name1>) $ ) syntax to find a point along the segment passing through (<name1>) and (<name2>). In the example below, ( $ (a)!0.66666!(b) $ ) means a point that is two thirds away from (a) in the segment joining (a) and (b):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw[help lines,gray!40] (0,0) grid (3,4);
\coordinate (a) at (0,0);
\coordinate (b) at (3,4);
\node[label={left:$A$}] at (a) {};
\node[label={left:$B$}] at (b) {};
\draw (a) -- (b);
\node[label={left:$C$}] at ( $ (a)!0.66666!(b) $ ) (c) {};
\foreach \Nombre in {a,b,c}
\node[circle,inner sep=1.5pt,fill=black] at (\Nombre) {};
\end{tikzpicture}
\end{document}

As Andrew Swann mentions in his comment, one can also let PGF do the decimal calculation and use
( $ (a)!4/6!(b) $ )
instead of
( $ (a)!0.66666!(b) $ )
- 505,128
With tkz-euclide you can use a barycentric coordinate, which can be used to place points between other points. A point p lying on the line between the points A and B can be written as (a1 + a2)p = a1A + a2B, and (a1, a2) will be the barycentric coordinate of p.
A point that is 2/3 along the way between A and B can be found by the vector sum A + (2/3)(B - A) = (1/3)A + (2/3)B. From this you see that the barycentric coordinate of that point is (1,2), which is why
\tkzDefBarycentricPoint(A=1,B=2)
is used in the below code. If you wanted the point placed 7/10 of the way between the two points, you'd use \tkzDefBarycentricPoint(A=3,B=7).
This can only be used to place points between the two defined points, while with the TikZ solution in Gonzalo's answer, you can say for example \node[label={left:$C$}] at ( $ (a)!2!(b) $ ) (c) {}; to place c the distance 2ab away from a, on the line through b, or even \node[label={left:$C$}] at ( $ (a)!-1!(b) $ ) (c) {}; to place it ab away from a in the direction opposite of b.
\documentclass[border=3mm,tikz]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmax=3,ymax=4]
\tkzGrid
\tkzDefPoint(0,0){A}
\tkzDefPoint(3,4){B}
\tkzDefBarycentricPoint(A=1,B=2)
\tkzGetPoint{C}
\tkzDrawPoints(A,B,C)
\tkzLabelPoints(A,B,C)
\end{tikzpicture}
\end{document}

- 206,688
Without using calc or any extra library, you can also place a node directly on a path, using the pos=<pos> option (where <pos> is the relative position on the segment, here 2/3).
MWE (based on Gonzalo Medina's code):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[help lines,gray!40] (0,0) grid (3,4);
\coordinate (a) at (0,0);
\coordinate (b) at (3,4);
\node[label={left:$A$}] at (a) {};
\node[label={left:$B$}] at (b) {};
\draw (a) -- (b) node[label={left:$C$},pos=2/3] (c) {};
\foreach \Nombre in {a,b,c}
\node[circle,inner sep=1.5pt,fill=black] at (\Nombre) {};
\end{tikzpicture}
\end{document}
The isolated line is the one that matters. Note that this can be used even if you don't want a visible line between A and B, or if you want a line with specific parameters. Simply replace \draw with \path, with or without additional parameters.

- 13,552
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,4);
\coordinate (C) at ({atan(4/3)}:4*5/6);
\draw (A)--(B);
\filldraw (A) circle (2pt) node[right] {$A$};
\filldraw (B) circle (2pt)node[right] {$B$};
\filldraw[red] (C) circle (2pt)node[right] {$\frac{4\times5}{6}=3.3333$};
\end{tikzpicture}
\end{document}

-
Please see Why should the minimal class be avoided?.
standaloneclass is a really good alternative as seen in the other answers. – percusse Apr 20 '14 at 10:34
A clean, lucky solution.
Option - ∞ + 1
Using an exact factor 2 3 div instead of 0.6666 in Christoph's answer.
\documentclass[pstricks,border=24pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](3,4)
\pstGeonode[PosAngle={-135,45}]{A}(3,4){B}
\psLNode(A)(B){2 3 div}{t}
\pstGeonode(t){C}
\end{pspicture}
\end{document}
Option -1
\documentclass[pstricks,border=24pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](3,4)
\pstGeonode[PosAngle={-135,45,0}]{A}(3,4){B}([Xnodesep=2]{B}A){C}
\end{pspicture}
\end{document}
And dirty solutions with PSTricks.
Option 0
\documentclass[pstricks,border=24pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](3,4)
\pstGeonode[PosAngle={-135,45,0}]{A}(3,4){B}([Ynodesep=1.3333]{A}B){C}
\end{pspicture}
\end{document}
Option 1
\documentclass[pstricks,border=24pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](3,4)
\pstGeonode[PosAngle={-135,45,0}]{A}(3,4){B}([nodesep=3.3333]{B}A){C}
\end{pspicture}
\end{document}
Option 2
\documentclass[pstricks,border=24pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](3,4)
\pstGeonode[PosAngle={-135,45}]{A}(3,4){B}
\nodexn{(A)+.6666(B)-.6666(A)}{t}
\pstGeonode(t){C}
\end{pspicture}
\end{document}
Option 3
\documentclass[pstricks,border=24pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](3,4)
\pstGeonode[PosAngle={-135,45}]{A}(3,4){B}
\pnodes{t}(2,0)(2,4)
\pstInterLL{A}{B}{t0}{t1}{C}
\end{pspicture}
\end{document}

- 36,086
To expand the existing PSTricks solution: There is a macro \psLNode in the pst-node package, which does exactly this:
\documentclass[pstricks,border=24pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](3,4)
\pstGeonode[PosAngle={-135,45}]{A}(3,4){B}
\psLNode(A)(B){0.6666}{C}
\psdot(C)
\end{pspicture}
\end{document}
- 16,593
- 1
- 23
- 47
tikzdo the calcualtion of the decimal:($ (a)!4/6!(b) $)– Andrew Swann Apr 19 '14 at 14:32