13

I needed the PI constant in C++, and I was lead to the answer that:

const PI = atan(1) * 4

Note that despite involving code, I'm asking this from a mathematics perspective.

I have 2 questions about this:

  • Is this an estimation of PI, or should it give me a large degree of accuracy?
  • How does this give PI?

On the second point, if I understand atan correctly, it takes a ratio of two sides, and returns the corresponding angle.

That means that atan(1) is referring a situation with 2 equal length sides.

I think I'm misunderstanding something though, as atan(1) gives me 0.7853981633974483, which seems like a very tiny angle.

If anyone can fill in the holes, it would be greatly appreciated.

  • 4
    I use pi = acos(-1) in C++, as I consider it neater. – GFauxPas Mar 29 '15 at 17:31
  • 3
    ... and I use const pi=3.1415926535897932384626433, but that's mostly because I cannot remember to simply use the predefine M_PI (cf. this) – Hagen von Eitzen Mar 29 '15 at 17:32
  • 2
    But in both these cases you must make sure you are in radian mode, not degree. The arctan of 1 is 45 degrees. – GEdgar Mar 29 '15 at 17:33
  • 1
    As @GEdgar hints, the value of atan(1) you're looking at there is in radians. This is the standard measure of angle in mathematics. You can think of this as measuring angle by measuring the length of circumference of a unit circle included by that angle. $2\pi$ radians is the whole circle, ie. 360 degrees. – Joffan Mar 29 '15 at 17:40
  • 1
    @HagenvonEitzen How can you live with truncating before an $8$ rather than a smaller digit? :) – Erick Wong Jul 09 '15 at 14:59
  • Is there any advantage of atan(1) * 4 over acos(-1)? – Leonardo Castro Sep 06 '16 at 14:17

6 Answers6

16

I'm including this little gif from Wikipedia as a great way to understand radians.

enter image description here

Joffan
  • 39,627
12

The function $\arctan\colon \mathbb{R}\to (-\frac{\pi}{2},\frac{\pi}{2})$ is the inverse of $\tan$. (for the right domain of definition). As $\tan \frac{\pi}{4} = 1$, this means that $\arctan 1=\frac{\pi}{4}$.

Regarding your question about angles: angles are (in mathematics) measured in radians (in $[0,2\pi)$ or $[-\pi,\pi)$), not in degrees: you should expect a value or order $\pi$ or so, not ranging between $0$ and $360$.

Clement C.
  • 67,323
  • You can see this readily if you consider that $\theta = \dfrac \pi 4$ satisfies $\sin \theta = \cos \theta$ – GFauxPas Mar 29 '15 at 17:30
  • 1
    the terms used for the inverse function of $tan,$ i know of, are either $\tan^{-1}$ or $arctan.$ the reciprocal is reserved for $\frac{1}{\tan}$ – abel Mar 29 '15 at 17:51
  • @abel : my bad, translation issues. Will edit my post. – Clement C. Mar 29 '15 at 18:01
  • clement, no problem. native english speaking students stumble over this all the time. – abel Mar 29 '15 at 18:39
2

You certainly know that $\sin{\frac{\pi}{4}}=\cos{\frac{\pi}{4}}=\frac{\sqrt{2}}{2}$ so one has $\tan{\frac{\pi}{4}}=1$ and therefore $\pi=4\tan^{-1}{1}$

marwalix
  • 16,773
1

Math explanation from a non-math person:

In a right angled triangle if the two short sides are equal, the angle is 45 degrees.

45 degrees in radians is π/4. (The full circumference is 2πr, 180 degrees is π and 45 degrees is π/4)

sin π/4 = cos π/4 because the two sides are equal.

tan π/4 = tan 45 = 1.

Arctan(1) is the degree (or radian) which returns a value of 1. So arctan of 1 is either 45 degrees or π/4.

π = 4*arctan(1)

gizmo
  • 11
1

This shows geometric explanation for relationship between tan, atan and Pi.

Because horizontal segment AB = 1 and vertical segment BD = 1, angle alpha = 45°. From there you can use atan( BD ) to determine 45° in radiant and take that times 4 to get Pi.

enter image description here

VisorZ
  • 150
0

You are correct, in all numeric programing languages like fortran, c, c++, and many others, for a program generalized input line that looks something like:

    print, numeric,  %pi , acos(-1), 4*atan(1)

all return the same numeric value. Here the system stored value %pi may be faster than trig evaluation.

    3.141592653589793, 3.141592653589793, 3.141592653589793
eromana
  • 11