# Tikz coordinate calculation

Consider the followinting tikz picture. I need to place the segment re-D so that its measure will be 8/9ths the measure of the segment ut-C. Now I just placed it at a random distance of 8/9 between ut and ut'. What function should I use (intersect? sin, cos?) and how do I write it down for tikz?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[scale=2]

\coordinate (o) at (0,0);
\coordinate [label=below:ut] (ut) at (2,0);
\coordinate [label=below:ut'] (ut') at (4,0);

\coordinate [label=above:C] (C) at (2, 2.4);
\coordinate [label=above:c] (c) at (4, 1.2);
\coordinate (O) at ($(c)!2!(C)$);

\draw (ut) -- (ut');
\draw (ut) -- (C);
\draw (C) -- (c);
\draw (ut') -- (c);

\coordinate [label=below:re] (re) at ($(ut)!8.0/9!(ut')$);

\coordinate [label=above:D] (D) at ($(C)!8.0/9!(c)$);

\draw (re) --(D);

\node [fill=black, inner sep=1pt] (c') at ($(ut)!1.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!2.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!3.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!4.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!5.0/6!(C)$) {};

\node [fill=black, inner sep=1pt] (c') at ($(ut')!1.0/3!(c)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut')!2.0/3!(c)$) {};
\draw (ut') -- (c);

\end{tikzpicture}
\end{document}


Thank you,

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,decorations,decorations.text}

\begin{document}

\begin{tikzpicture}[scale=5]

\coordinate (o) at (0,0);
\coordinate [] (ut) at (2,0);
\node  [xshift=-0.8ex, yshift=1.5ex] at (ut) {u};
\node  [xshift=0.65ex, yshift=1.6ex] at (ut) {t};
\coordinate (fa') at (4,0);
\node  [xshift=1.2ex, yshift=1.5ex] at (fa') {fa};

\coordinate [label=above:C] (C) at (2, 2.4);
\coordinate [label=above:c] (c) at (4, 1.2);
\coordinate (O) at ($(c)!2!(C)$);

\draw (ut) -- (fa');
\draw (ut) -- (C);
\draw (C) -- (c);
\draw (fa') -- (c);

\path let \p1=($(C)-(ut)$), \p2=($(c)-(ut)$) in
(fa') ++({-(8/9*\y1 / (\y1-\y2) - 1)  * \x2},0)
coordinate  (re)
++(0, {8/9*\y1}) coordinate  (D);

\draw (re) -- (D);
\node  [xshift=-0.7ex, yshift=1.5ex] at (re) {r};
\node  [xshift=0.7ex, yshift=1.5ex] at (re) {e};

\path let \p1=($(C)-(ut)$), \p2=($(c)-(ut)$) in
(fa') ++({-(64/81*\y1 / (\y1-\y2) - 1)  * \x2},0)
coordinate  (mi)
++(0, {64/81*\y1}) coordinate  (E);
\draw (mi) --(E);
\node  [xshift=-1.2ex, yshift=1.5ex] at (mi) {m};
\node  [xshift=0.45ex, yshift=1.75ex] at (mi) {i};

\path let \p1=($(C)-(ut)$), \p2=($(c)-(ut)$) in
(fa') ++({-(3/4*\y1 / (\y1-\y2) - 1)  * \x2},0)
coordinate  (fa)
++(0, {3/4*\y1}) coordinate  (F);
\draw (fa) -- (F);
\node  [xshift=-0.7ex, yshift=1.9ex] at (fa) {f};
\node  [xshift=0.7ex, yshift=1.5ex] at (fa) {a};

\path let \p1=($(C)-(ut)$), \p2=($(c)-(ut)$) in
(fa') ++({-(2/3*\y1 / (\y1-\y2) - 1)  * \x2},0)
coordinate  (sol)
++(0, {2/3*\y1}) coordinate [label=above:G] (G);
\draw  (sol) -- (G);
\node  [xshift=-0.5ex, yshift=1.5ex] at (sol) {s};
\node  [xshift=1.2ex, yshift=1.9ex] at (sol) {ol};

\path let \p1=($(C)-(ut)$), \p2=($(c)-(ut)$) in
(fa') ++({-(16/27*\y1 / (\y1-\y2) - 1)  * \x2},0)
coordinate  (la)
++(0, {16/27*\y1}) coordinate (A);
\draw  (la) -- (A);

\path let \p1=($(C)-(ut)$), \p2=($(c)-(ut)$) in
(fa') ++({-(128/243*\y1 / (\y1-\y2) - 1)  * \x2},0)
coordinate  (si)
++(0, {128/243*\y1}) coordinate (B);
\draw  (si) -- (B);

\node [fill=black, inner sep=1pt] (c') at ($(ut)!1.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!2.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!3.0/6!(C)$) {};
\node [xshift=-0.5em, yshift=-2em] (c') at ($(ut)!3.0/6!(C)$) {6};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!4.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!5.0/6!(C)$) {};

\node [fill=black, inner sep=1pt] (c') at ($(fa')!1.0/3!(c)$) {};
\node [xshift=0.5em, yshift=-2em] (c') at ($(fa')!1!(c)$) {3};
\node [fill=black, inner sep=1pt] (c') at ($(fa')!2.0/3!(c)$) {};
\draw (fa') -- (c);

\node [fill=black, inner sep=1pt] (c') at ($(sol)!1.0/4!(G)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(sol)!2.0/4!(G)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(sol)!3.0/4!(G)$) {};
\node [xshift=-0.5em, yshift=-2em] (c') at ($(sol)!3.0/4!(G)$) {4};

\draw[postaction={decorate,decoration={text along path,text align=center,text={Diapason},raise=5pt}}](ut)to[bend right=800] (fa'){};
\draw[postaction={decorate,decoration={text along path,text align=center,text={Diapente},raise=5pt}}](ut)to[bend right=800] (sol){};
\draw[postaction={decorate,decoration={text along path,text align=center,text={Diatessaron},raise=5pt}}](sol)to[bend right=800] (fa'){};

\end{tikzpicture}
\end{document}


You can either use the intersection library to calculate the intersection of the path (C)-(c) with another path at height 8/9C (the red path in the first picture).

\path[draw,red, name path=target] ($(ut)!8.0/9!(C)$)
node [label=left:8/9] {} -- ++(1,0);
\path[name intersections={of=target and C-c}]
(intersection-1) coordinate[label=above:D](D)
(intersection-1 |- ut) coordinate[label=below:re](re);


Or you could do the calculations yourself using the let syntax and the intercept theorem, which you have probably learned in school (second picture).

\path let \p1=($(C)-(ut)$), \p2=($(c)-(ut)$) in
(ut') ++({-(8/9*\y1 / (\y1-\y2) - 1)  * \x2},0)
coordinate [label=below:re] (re)
++(0, {8/9*\y1}) coordinate [label=above:D] (D);


\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, intersections}
\begin{document}

\begin{tikzpicture}[scale=2]
\coordinate (o) at (0,0);
\coordinate [label=below:ut] (ut) at (2,0);
\coordinate [label=below:ut'] (ut') at (4,0);

\coordinate [label=above:C] (C) at (2, 2.4);
\coordinate [label=above:c] (c) at (4, 1.2);
\coordinate (O) at ($(c)!2!(C)$);

% Help path. Style draw,red is only for illustration.
\path[draw,red, name path=target] ($(ut)!8.0/9!(C)$)
node [fill=black, inner sep=1pt, label=left:8/9] {}
-- ++(1,0);

\draw (ut) -- (ut');
\draw (ut) -- (C);
\draw[name path=C-c] (C) -- (c);
\draw (ut') -- (c);

\path[name intersections={of=target and C-c}]
(intersection-1) coordinate[label=above:D](D)
(intersection-1 |- ut) coordinate[label=below:re](re);

\draw (re) --(D);
\draw (ut') -- (c);
\end{tikzpicture}

\begin{tikzpicture}[scale=2]
\coordinate (o) at (0,0);
\coordinate [label=below:ut] (ut) at (2,0);
\coordinate [label=below:ut'] (ut') at (4,0);

\coordinate [label=above:C] (C) at (2, 2.4);
\coordinate [label=above:c] (c) at (4, 1.2);
\coordinate (O) at ($(c)!2!(C)$);

\draw (ut) -- (ut');
\draw (ut) -- (C);
\draw (C) -- (c);
\draw (ut') -- (c);

% Use basic school geometry to calculate intersection.
\node [fill=black, inner sep=1pt, label=left:8/9] at ($(ut)!8.0/9!(C)$) {};

\path let \p1=($(C)-(ut)$), \p2=($(c)-(ut)$) in
(ut') ++({-(8/9*\y1 / (\y1-\y2) - 1)  * \x2},0)
coordinate [label=below:re] (re)
++(0, {8/9*\y1}) coordinate [label=above:D] (D);

\draw (re) --(D);
\draw (ut') -- (c);

\end{tikzpicture}

\end{document}

• Thank you, @Fritz. I'll follow up adding the picture complete with all the other proportions. – user56153 Sep 18 '14 at 13:41

Here is another solution using intersection of to calculate the intersection point D, rather than the intersections library.

Here's the code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[scale=2]
\coordinate (o) at (0,0);
\coordinate [label=below:ut] (ut) at (2,0);
\coordinate [label=below:ut'] (ut') at (4,0);

\coordinate [label=above:C] (C) at (2, 2.4);
\coordinate [label=above:c] (c) at (4, 1.2);
\coordinate (O) at ($(c)!2!(C)$);

\draw (ut) -- (ut');
\draw (ut) -- (C);
\draw (C) -- (c);
\draw (ut') -- (c);

\coordinate (leftD) at ($(C)!1.0/9!(ut)$);
\coordinate (rightD) at (leftD-|c);
\coordinate (D) at (intersection of leftD--rightD and C--c);
\draw[red](D)node[above]{D}--(D|-ut)node[below]{re};

\node [fill=black, inner sep=1pt] (c') at ($(ut)!1.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!2.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!3.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!4.0/6!(C)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut)!5.0/6!(C)$) {};

\node [fill=black, inner sep=1pt] (c') at ($(ut')!1.0/3!(c)$) {};
\node [fill=black, inner sep=1pt] (c') at ($(ut')!2.0/3!(c)$) {};
\draw (ut') -- (c);
\end{tikzpicture}
\end{document}