Languages
[Edit]
EN

Python - math.atan() method example

0 points
Created by:
Admin Dirask Community
1270

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

Python - math module

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

â€ïžđŸ’» 🙂

Join