# Using Asymptote, how do I rotate the label indicating the length of the side of a triangle?

I have a diagram of a right triangle. I would like the label for the length of the hypotenuse to be typeset in the direction of the hypotenuse.

Also, I would appreciate the code for drawing the right-angle mark in blue and coloring the region enclosed by it yellow.

I wanted to add an arc of a circle indicating the measure of $\angle{QPR}$ is $\theta$. Why doesn't the following code draw the arc?

import geometry;
pen BluePen=blue+1bp;

I didn't include that in the following code to avoid errors in compiling.

[asy]
size(150);
pair P, Q, R;
P = (sqrt(7),1);
Q = (0,0);
R = (sqrt(7),0);
//
draw(P--Q--R--cycle);
//
//
label(scale(0.75)* "$\sqrt{x}$", Q--R, S);
label(scale(0.75)* "$\sqrt{x+1}$", P--Q, NNW);
label(scale(0.75)* "$1$", P--R, E);
label(scale(0.85)* "$P$", P, N);
label(scale(0.85)* "$Q$", Q, S);
label(scale(0.85)* "$R$", R, S);
//
//
//
draw(rightanglemark(P, R, Q, 4));
[/asy]

Here is a quick way.

// http://asymptote.ualberta.ca/
size(150);
pair P, Q, R;
P = (sqrt(7),1);
Q = (0,0);
R = (sqrt(7),0);
filldraw(box(R,R+.2dir(135)),yellow,black);
draw(arc(P,.2,degrees(R-P),degrees(Q-P)));
path pmark=arc(P,.3,degrees(R-P),degrees(Q-P));
label(scale(0.75)*"$\theta$",relpoint(pmark,.5));
draw(P--Q--R--cycle);
label(scale(0.75)* "$\sqrt{x}$", Q--R, S);
label(Label(scale(0.75)* "$\sqrt{x+1}$",Rotate(P-Q)), P--Q);
label(scale(0.75)* "$1$", P--R, E);
label(scale(0.85)* "$P$", P, NE);
label(scale(0.85)* "$Q$", Q, SW);
label(scale(0.85)* "$R$", R, SE);
• What is the "R+.2dir(135)" in the command box(R,R+.2dir(135))? Commented Feb 15, 2021 at 18:18
• @user74973 it is a box - a rectangle (in this case, a square) with 2 opposite vertexes are R and R+.2dir(135) (from R, go .2=2mm in the direction of 135) Commented Feb 15, 2021 at 23:37

Alternatively, using perpendicularmark() from geometry module,

settings.tex="pdflatex";
import geometry;
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(150);
pair P, Q, R;
P = (sqrt(7),1);
Q = (0,0);
R = (sqrt(7),0);
perpMark(R, P, Q, Fill(paleyellow));
draw(P--Q--R--cycle);
dot(P--Q--R,UnFill);
label(scale(0.75)* "$\sqrt{x}$", (Q+R)/2, UnFill);
label(rotate(degrees(P-Q))*scale(0.75)* "$\sqrt{x+1}$", (P+Q)/2,UnFill);
label(scale(0.75)* "$1$", (P+R)/2,UnFill);
label(scale(0.85)* "$P$", P, N);
label(scale(0.85)* "$Q$", Q, S);
label(scale(0.85)* "$R$", R, S);

• P.S. It's preferable to use the proper font settings instead of just scaling the LaTeX labels. Commented Feb 7, 2021 at 19:08

Using tzplot:

\documentclass[tikz]{standalone}

\usepackage{tzplot}

\begin{document}

\begin{tikzpicture}[scale=1.5,font=\scriptsize]
\tzcoors(0,0)(Q){$Q$}[-135]({sqrt(7)},1)(P){$P$}[45]({sqrt(7)},0)(R){$R$}[-45];
\tzpolygon(P){$\sqrt{x+1}$}[sloped,a](Q){$\sqrt x$}[b](R){1}[r](P);
\tzanglemark(Q)(P)(R){$\theta$}(5pt)
\tzrightanglemark*[draw,fill=yellow,opacity=1](Q)(R)(P)(3pt)
\end{tikzpicture}

\end{document}