# Asymptote: drawing broken lines

I've started using asymptote and very much like it as an alternative to TikZ. What I miss is TikZ's feature (A)!0.5!42:(B), which says "Go half-way on the segment from A to B and turn to 42 degrees counterclockwise". I can imagine there are ways to achieve this via geometric primitives, in asymptote. However, I also expect there is an idiomatic way to do it. Any ideas / references?

So far, Asymptote does not have built-in function for that partway modifier (rotate around and take partway). However, we can easily create a new Asymptote command for that task! Both TikZ and Asymptote codes are given for comparison. \documentclass[border=5mm]{standalone}
\usepackage[inline]{asymptote}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw[violet!50,thin] (0,0) grid (6,5);
\path
(1,1) coordinate (A) node[left]{$A$}
(5,3) coordinate (B) node[right]{$B$}
($(A)!.7!20:(B)$) coordinate (C) node[above left]{$C$}
% for comparison
([rotate around={20:(A)}]B) coordinate (Bt) node[right]{$B'$}
%($(A)!.7!(Bt)$) coordinate (C) node[right]{$C$}
;
\draw[dashed] (A)--(Bt);
\draw (A)--(B);
\draw[red] (A)--(C);
\fill (C) circle(1.5pt);
\end{tikzpicture}
\hspace{5mm}
\begin{asy}
unitsize(1cm);
import math; // for grid
pair RnP(pair A, pair B, real deg=0, real pos){
pair Bt=rotate(deg,A)*B;
pair C=pos*Bt+(1-pos)*A;
return C;
}

pair A=(1,1), B=(5,3);
pair Bt=rotate(20,A)*B;
pair C=RnP(A,B,20,.7);

draw(A--Bt,dashed);
draw(A--B);
draw(A--C,red);
label("$A$",A,W);
label("$B$",B,E); label("$B'$",Bt,E);
label("$C$",C,NW);
dot(C);
\end{asy}
\end{document}


PS: We can write the function with shorter code

pair RnP(pair A, pair B, real deg=0, real pos){
return (1-pos)*A+pos*(rotate(deg,A)*B);
}


or (by commutativity),

pair RnP(pair A, pair B, real deg=0, real pos){
return rotate(deg,A)*(pos*B+(1-pos)*A);
}

• I see that it works. For the sake of shedding a light on a possible derivation. One can see that the point in question is A + (1-pos)*(B-A)*rotate(deg,A). I then assume rotate(deg,A)*B == B*rotate(deg,A). But where did the -A*rotate(deg,A) disappear? Jan 17, 2022 at 17:58
• @Ilonpilaaja I guess you are confusing a bit, see my update (1-pos)*A+pos*(rotate(deg,A)*B). Note that B*rotate(deg,A) is wrong syntax, and rotate(deg,A)*B gives the point (pair) that is counter-clockwise rotated deg degrees from B around A Jan 17, 2022 at 18:22
• That makes a lot of sense now. As in the OP, I wanted to know whether a built-in function exists, and if not, what would be the most idiomatic way. Jan 17, 2022 at 19:19
• @Ilonpilaaja 1. No; 2. a function like one I created above. Jan 20, 2022 at 22:13