Home
IT Knowledge
Inspiration
Languages
EN

# Python - math.atan() method example

0 points
Created by:
1450

The `math.atan` function returns number in radians in the range `-math.pi/2` to `+math.pi/2`.Â The function calculates the inverted tangent function value.

``````import math

def calculateAngle(a, b):
return math.atan(a / b)

#   |\
#   | \ h - for this function this information is not necessary
# a |  \
#   |__*\ <- angle
#     b

# a, b and h build isosceles right triangle
a = 3
b = a
print(calculateAngle(a, b))  # 0.7853981633974483 <-  45 degrees

# a, b and h build half of equilateral triangle
a = 3
b = a * math.sqrt(3)
print(calculateAngle(a, b))  # 0.5235987755982987 <- ~30 degrees``````

## 1. Documentation

 Syntax ``math.atan(number)`` Parameters `number` - a number value that represents the result of the operationÂ `opposite / adjacent`Â on the right triangle. Result `number`Â value in radians in the range `-math.pi/2`Â to `+math.pi/2`. If the value can not be calculatedÂ `ValueError`Â occures. Description `atan`Â is a method that takes only one parameter and returns an approximation of the result of the mathematical function arctangent(x).

## 2. Working with degrees

``````import math

def calculateAngle(a, b):
return math.atan(a / b)

#   |\
#   | \ h - for this function this information is not necessary
# a |  \
#   |__*\ <- angle
#     b

# a, b and h build isosceles right triangle
a = 3
b = a
print(calculateAngle(a, b))  # 0.7853981633974483 <-  45 degrees

# a, b and h build half of equilateral triangle
a = 3
b = a * math.sqrt(3)
print(calculateAngle(a, b))  # 0.5235987755982987 <- ~30 degrees``````

## References

1. Inverse trigonometric functions - Wikipedia