# How do you label an angle with its measurement in Asymptote?

Is there a simple way to label an angle with its measurement in Asymptote? I've found that AoPS has the olympiad package, but it only provides a way to mark angles, not label them with their measure. Using the aforementioned package, I managed to create this image:

Pretty bad. How should I label that angle simply? It may also help you to know that I'm a beginner to Asymptote.

Here's the code for the image above:

import olympiad;

size(15cm);
markscalefactor = 0.5;

draw((0, 0) -- (22, 63) -- (22, 0) -- cycle);
path angle = anglemark((22, 0), (0, 0), (22, 63));
draw(angle);
draw(rightanglemark((0, 0), (22, 0), (22, 63)));
label("$70^{\circ}$", angle, E);
label("75 m", (0, 0) -- (22, 63), E);


Alternatively, you can use the markangle function from the geometry module, which is included in a set of the base Asymptote modules:

settings.tex="pdflatex";
import geometry;
import fontsize;defaultpen(fontsize(8pt));
texpreamble("\usepackage{lmodern}"+"\usepackage{amsmath}"
+"\usepackage{amsfonts}"+"\usepackage{amssymb}");

void perpMark(picture pic=currentpicture,
pair M, pair O, pair B, real size=5,
pen p=currentpen, filltype filltype = NoFill){
perpendicularmark(pic, M,unit(unit(O-M)+unit(B-M)),size,p,filltype);
}

size(6cm);
pair A=(0,0), B=(12,0), C=(7,9), D=(C.x,0);

real alpha=aTan(abs(C-D)/abs(A-D));
real beta=aTan(abs(C-D)/abs(B-D));

pen p=deepblue+0.6bp;
real w=0.6bp;
markangle(Label("$\alpha$",Relative(0.5)),n=1,radius=-10,C,A,B,red+w);
markangle(Label("$\beta$ ",Relative(0.5)),n=2,radius=-8,A,B,C,deepgreen+w);
markangle(rotate(45+alpha/2)*Label("$90^\circ-\alpha$",Relative(0.5)),n=3,radius=-8,D,C,A,blue+w);
perpMark(D,A,C,gray(0.5)+w,Fill(palegreen));

draw(A--B--C--cycle,deepblue);
draw(D--C,gray(0.5)+w);

dot(A--B--C--D,UnFill);

label("$A$",A,plain.SW);
label("$B$",B,plain.SE);
label("$C$",C,plain.NW);
label("$D$",D,plain.S);


Your data seems unclear (22,63,75,70)! You can adapt the following code for your situation. No more package is needed.

Some explanation: aTan gives value in degrees; atan gives value in radians; string(real x, int digits=realDigits) casts the real number x to a string using precision digits and the C locale. So string(angleA,digits=4) gives the value of angleA with 4 precision digits.

Asymptote allows users high customization, that is, there are several ways to draw. For example,

draw(arc(A,.9,180,180-angleA),red);


can be replaced by

draw(arc(A,A+.3*(O-A),B,CW),red);


//http://asymptote.ualberta.ca/
unitsize(1cm);
real a=3, b=4;
pair O=(0,0), A=(a,0), B=(0,b);
real angleA=aTan(b/a); // in degrees

draw(box(O,(.4,.4)),red);
draw(arc(A,.9,180,180-angleA),red);
string Atext=string(angleA,digits=4)+"$^{\circ}$";
label(scale(.5)*Atext,A+.6dir(180-angleA/2),blue);
draw(O--A--B--cycle);

label("$O$",O,SW);
label("$A$",A,SE);
label("$B$",B,NW);
shipout(bbox(5mm,invisible));


Update: This is for fun. I often create my own command for angle marks. The command rightanglemark returns a path. It can be draw, or fill, or filldraw with suitable use.

unitsize(1.2cm);

// right angle mark as a path
path rightanglemark(pair A, pair C, pair B, real size=.3){
pair Ca=C+size*unit(A-C);
pair Cb=C+size*unit(B-C);
pair Cab=Ca+Cb-C;
return Ca--Cab--Cb;
}

real a=3, b=4;
real c=sqrt(a^2+b^2);
pair O=(0,0), A=(-c/2,0), B=(c/2,0);
real angleA=aTan(b/a), angleB=90-angleA; // in degrees
pair C=c/2*dir(2*angleA);
draw(circle(O,c/2),lightmagenta);

//draw(rightanglemark(A,C,B),red);  // to draw angle
//fill(rightanglemark(A,C,B)--C--cycle,palegreen);  // >>>to fill angle
filldraw(rightanglemark(A,C,B)--C--cycle,palegreen,red); // >>>to fill and draw angle

draw(arc(A,.4,0,angleA),red);
draw(arc(B,.4,180,180-angleB),red);
draw(arc(B,.45,180,180-angleB),red);

string Atext=string(angleA,digits=4)+"$^{\circ}$";
string Btext=string(angleB,digits=4)+"$^{\circ}$";
label(scale(.6)*Atext,A+.8dir(angleA/2),blue);
label(scale(.6)*Btext,B+.8dir(180-angleB/2),blue);

draw(Label("$a=$ "+string(a),Relative(.5),Rotate(B-C)),B--C);
draw(Label("$c=$ "+string(c),Relative(.5)),A--B);
draw(Label("$b=$ "+string(b),Relative(.5),Rotate(C-A)),C--A);

label("$A$",A,W);
label("$B$",B,E);
label("$C$",C,N);
dot(O,lightmagenta);

shipout(bbox(5mm,invisible));

• Thanks a lot! Just to clarify, you're basically making the label smaller and nudging it inside the arc, right? May 21, 2021 at 2:18
• yes! is that what you want? May 21, 2021 at 2:21
• In the image, a should be 4 and b should be 3. May 25, 2021 at 0:38
• @ollydbg23 thank you! I will correct it soon. May 29, 2021 at 12:37

Using tzplot:

\documentclass[tikz]{standalone}

\usepackage{tzplot}

\begin{document}

\begin{tikzpicture}[scale=.1,font=\scriptsize]
\tzcoors(0,0)(A){A}[-135](63,0)(B){B}[0](0,22)(C){C}[135];
\tzpolygon(A)(B){75m}[a](C);
% simple angle marks with labels
\tzanglemark(A)(C)(B){70\textdegree}(5cm)
\tzrightanglemark(B)(A)(C){90\textdegree}[pos=.5,red](5cm)
\tzanglemark[double](A)(B)(C){$\theta$}(5cm)
\end{tikzpicture}

\end{document}