Given an angle $\theta$, can I find a Pythagorean triple $(A,B,C)$ such that the corresponding right triangle contains an angle that is as close to $\theta$ as I want? And if so, how? For example suppose $\theta = 56.25^\circ$. How do I find Pythagorean triples $(A,B,C)$ such that $\tan(56.25^\circ) \approx B/A$? Looking at Euclid's formula this is the same as asking for coprime not-both-odd integers $m$ and $n$ such that $$\tan(56.25^\circ) \approx \frac{2mn}{m^2-n^2}\,$$ but this only makes a brute-force search easier. Is there a procedural way to generate such arbitrarily precise triples?

  • 3
    $\begingroup$ I show, in my answer, how to find an approximate triple for $\quad0<\theta<45^\circ$ $$f(43,23)=(1320,1978,2378)$$ $$\tan^{-1}\dfrac{1320}{1978}\approx 33.716^\circ$$ $$90-33.716\approx 56.284^\circ$$ $\endgroup$
    – poetasis
    Commented Oct 2, 2021 at 0:19
  • 1
    $\begingroup$ Using Euclid's formula $$A=m^2-k^2\quad B=2mk\quad C=m^2+k^2$$ $$f(m,k)=f(2434,1301)\\=(4231755,6333268,7616957)\space \approx 56.2499961586429^\circ$$ This triangle is within $1\%$ of $1$ second of arc from $56.25^\circ$ $\endgroup$
    – poetasis
    Commented Nov 6, 2021 at 1:00

6 Answers 6


Let $r\in[0,\infty)$. The problem posed is equivalent to finding $m\geq n\in\mathbb N$ such that $r\sim\frac{2mn}{m^2-n^2}$.

Thus, we want $$rm^2-2mn-rn^2\sim0$$Now suppose $r,n$ is given and we want to find $m$ that satisfies the equation above (not necessarily natural).

Thus, $$m=\frac{n\left(1+\sqrt{1+r^2}\right)}r$$So, we want to find a choice of $n$ that makes the expression above arbitrarily close to an integer.

But that's relatively easy. Let $c=\frac r{1+\sqrt{1+r^2}}$. Thus, $n=mc$. So, we just want to find a fraction $\frac nm$ close to $c$. Easy!


Given $\theta$, compute $$c=\frac{\sin\theta}{1+\cos\theta} = \tan\frac\theta2$$Then, find a fraction $\frac nm$ arbitrarily close to $c$. Substitute $m,n$ into your formula and voila!

  • 18
    $\begingroup$ This looks very closely related to the standard way of finding Pythagorean triples by reducing to finding rational points on the unit circle, and then classifying those according to the slope of the line joining a point to $(-1, 0)$. So, you're just saying find the slope of the line joining $(-1, 0)$ to $(\cos\theta, \sin\theta)$, take a rational slope arbitrarily close to that, and then find the other intersection of the line through $(-1, 0)$ with that rational slope with the unit circle. $\endgroup$ Commented Oct 1, 2021 at 17:22
  • 2
    $\begingroup$ @DanielSchepler Actually, it's precisely that. Great insight! $\endgroup$ Commented Oct 1, 2021 at 18:52
  • 2
    $\begingroup$ 3b1b also describes this in terms of squaring Gaussian integers. $\endgroup$
    – Kevin
    Commented Oct 2, 2021 at 3:57

This works for $\quad 0.01 \lt \tan\theta\lt 1\quad$ being limited to decimals expressible as $3$-digit fractions. For $\tan\theta>1,\space \tan\space (90-\theta)\space$ should be used. For $\tan\theta=1,\space$ the best triples are where $A^2+(A\pm1)^2=C^2.\quad$

We begin with Euclid's formula $$ A=m^2-k^2\qquad B=2mk \qquad C=m^2+k^2$$

For $\tan\theta = 1,\space$ the values for $A^2 +(A\pm1)^2=C^2\space$ triples (to feed $(m,k)$-values to Euclid's formula) may be generated sequentially with $k_{n+1}=k_n+\sqrt{2k_n^2+(-1)^{k_n}}.$ These are pell numbers $\{1,2,5,12,\cdots\}$ to be used in pairs like $\space(2,1),\space (5,2),\space (12,5)\cdots.\space$ For $\tan\theta<1,\space$ we use these steps

  1. Convert tangent to a $1$-to-$3$ digit fraction to identify the A:B ratio.

  2. Solve the tangent function for $k$

  3. Test a range of $m$-values to see which yields a $k$-value closest to an integer,

  4. Use $m$ and the rounded value of $k$ to generate the triple with Euclid's formula.

\begin{equation} \tan\theta=\dfrac{A}{B} = \dfrac{m^2-k^2}{2mk}\\ \\ 2mkA=(m^2-k^2)B\\ \\ B k^2+2 A k m - B m^2 = 0 \\ \implies k = \dfrac{\sqrt{A^2 m^2 + B^2 m^2} - A m}{B}\\ \quad \text{ for }\quad 2 \le m \le 50 \end{equation}

This range is chosen to accommodate fractions up to $3$ digits.

Example $$\tan39^\circ\approx 0.80978\approx \dfrac{149}{184} \implies A=149\quad B=184$$

$$k = \dfrac{\sqrt{149^2 m^2 + 184^2 m^2} - 149 m}{184} \quad \text{ for } 2\le m \le 30 \\\text{and we find the best fit is } \quad m=21\quad k\approx 10.016\approx 10 \\ f(21,10)=(341,420,541)\\ \tan\theta\approx\dfrac{341}{420}\approx 0.81190476 \\ \tan^{-1} 0.81190476\approx 39.07^\circ $$


For any positive integer $m>n$, \begin{gather} z=m+ni= r\angle \phi\\ z^2=(m+ni)^2=(m^2-n^2)+2mni=r^2\angle 2\phi \end{gather} where $r=\sqrt{m^2+n^2}$ and $\tan \phi=\frac{n}{m}$.

Thus $\{m^2+n^2,m^2-n^2,2mn\}$ is a Pythagorean triplet.

In your case $2\phi=56.25^\circ$ or $\phi=28.125^\circ$.

Find the simplest $m>n$ such that $\tan 28.125^\circ=\frac{n}{m}$.

\begin{align} \tan 28.125^\circ&=\frac{n}{m}\\ 0.5&\approx\frac{n}{m}\\ \end{align}

$m=2$ and $n=1$.


My "other" answer used Euclid's formula, found triples for Cotangent instead of Tangent, and required using $(90-\theta)$ for angles above $45^\circ.\quad$ This answer uses a formula I developed in $2009$ and finds triples for $0\lt \theta \lt 90^\circ$ with an error of (usually) $5$ arc seconds or less–– and extreme fractions of a second as angles approach zero of ninety degrees.

\begin{align*} \\ A&=\space \big(2n-1+k)^2-k^2 &=(2n-1)^2+&2(2n-1)k \\ B&=2(2n-1+k)k &=&2(2n-1)k+2k^2\\ C&=\space (2n-1+k)^2+k^2 & =(2n-1)^2+&2(2n-1)k+2k^2\\ \end{align*} We begin with $\dfrac{B}{A}$ and solve for $k$ testing a defined range of $n$-values to see which is closest to any integer greater than zero. The values of $A$ and $B$ are the fractional equivalent of tangent with a denominator $(A)$ of up to three digits. \begin{align*} \frac{B}{A} &=\frac{2(2n-1)k +2k^2}{(2n-1)^2 + 2(2n-1)k} \\ \\ B((2n-1)^2 + 2(2n-1)k) &=A(2(2n-1)k +2k^2)\\ \\k &= \frac{(2n-1)\big(B-A +\sqrt{A^2 + B^2}\big)}{2 A}\\ \quad \text{for} \quad 2+ \bigg\lfloor\frac{1}{\tan\theta}\bigg\rfloor\le &n\le 100 +\bigg\lfloor\frac{1}{\tan\theta}\bigg\rfloor \quad 0 \lt\theta\lt 90^\circ \end{align*}

Using the $39^\circ$ example, $\tan\theta\approx 0.80978403,\space A=184,\space B=149$

\begin{align*} k&=\bigg[ \frac{(2n-1)\big(149-184 +\sqrt{184^2 + 149^2}\big)}{2 (184)}\bigg] \\ \\ \quad \text{for} \quad &2+ \bigg\lfloor\frac{1}{\ 0.80978403}\bigg\rfloor\le n\le 100 +\bigg\lfloor\frac{1}{0.80978403}\bigg\rfloor\\ \\\\ \implies f(n,k)&=f(16,17)=(2015,1632,2593)\quad \approx 39.00489701^\circ \end{align*}

For other examples we have

\begin{align*} 0.01^\circ\rightarrow & f(5731,1)=(131377443,22924,131377445)\\ &\approx 0.009997519^\circ \\ 30^\circ\rightarrow & f(77,56)=(40545,23408,46817)\space \approx 29.9992934272601^\circ \\ 45^\circ\rightarrow & f(50,70)=(23661,23660,33461)\space \approx 44.9987892102977^\circ \\ 56.25^\circ\rightarrow & f(14,31)=(2403,3596,4325)\space \approx 56.2474707665776^\circ \\ 60^\circ\rightarrow & f(77,209)=(87363,151316,174725)\space \approx 59.9998106752595^\circ \\ 89.99^\circ\rightarrow & f(39,441139)=(67941335,389275170048,389275175977)\\ &\approx 89.9899999999744^\circ \end{align*}


We may consider the use of continued fractions. Without loss of generality we may take the larger of the two acute angles as the one to be approximated. Calling this angle $\theta$ we use the continued fraction approximants to approximate $\{1,\tan\theta,\sec\theta\}$.

Let us illustrate this method for approximating a $56.25°$ angle. The tangent of $56.25°$ is computed as a continued fraction by the standard algorithm of computing successive remainders and reciprocals to give $[1,2,73,6,2,...]$, giving the approximants $1,3/2,220/147,1323/884,2866/1915,...$. The secant gives $[1,1,3,1,840,...]$, from which we get the approximants $1,2,7/4,9/5,7569/4204,...$.

The table below shows what happens when we insert these approxinants as the ratios of sides of the triangle. Side $a$ is the smallest multiplier that will clear the fractions and thus give whole numbers for $b\approx a\tan 56.25°$ and $c\approx a\sec 56.25°$. We see that when we choose the approximants that occur just before the large numbers in the continued fractions ($220$ in the tangent and $840$ in the secant), the angles all hit within $0.2°$ of their target values $33.75°,56.25°,90°$ using surprisingly small sides $10,15,18$ (the reader might note that $10^2+15^2=18^2+1$). Subsequent highly accurate approximations to the triangle use equal or longer truncation of the continued fractions; this includes the $735-1100-1323$ triangle where all angles hit to within the nearest $0.01°$.

enter image description here


For an angle $\theta$ you can find a Pythagorean triple $(2mn, |m^2-n^2|, m^2+n^2)$ corresponding to a right triangle containing an angle about $\theta$ by find a rational approximation $$\frac{m}{n} \approx \tan\frac{\theta}{2}$$ You can find a "good" rational approximation to $\tan\frac{\theta}{2}$ using techniques from this Q&A post. Note that Don Thousands' answer is the inspiration for this realization; I wanted to express it compactly.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .