3

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:

Diagram

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);

3 Answers3

6

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);

enter image description here

g.kov
  • 21,864
  • 1
  • 58
  • 95
5

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);

enter image description here

//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.

enter image description here

unitsize(1.2cm);

// right angle mark as a path path rightanglemark(pair A, pair C, pair B, real size=.3){ pair Ca=C+sizeunit(A-C); pair Cb=C+sizeunit(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/2dir(2angleA); 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));

Black Mild
  • 17,569
1

Using tzplot:

enter image description here

\documentclass[tikz]{standalone}

\usepackage{tzplot}

\begin{document}

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

\end{document}

I. Cho
  • 2,985