Concepts / Introduction to the Math Module

Introduction to the Math Module

Python's trigonometric functions (sin, cos, tan) take arguments in radians, not degrees

  • Programming

The Angle-Unit Trap

When you use Python's trigonometric functions, the number you provide is interpreted as a radian measurement. It is not interpreted as a degree measurement. This matters because a value such as 45 may look like 45 degrees to a person, while Python interprets it as 45 radians. Passing degrees directly to a trigonometric function therefore produces an incorrect result for the intended angle.

same scalesame scaleaccepted input360 degreesfull circle45 degreesdegree measurementsin, cos, tanradian arguments2π radiansfull circle0.785 radiansequivalent angle
How does the same angle measurement map differently between degrees and radians, and why do Python's trigonometric functions expect radians?

From Degrees to Radians

The conversion is based on the fact that a full circle is 360 degrees and also 2π radians. To convert any degree measurement, divide the degree value by 360.0 and multiply by 2 * math.pi. This scales the measurement from the degree system into the radian system.

radians = degrees / 360.0 * 2 * math.pi

degree valuefraction of a full circleconverted value45 degreesstarting measurementDivide by 360.045 / 360.0Multiply by 2πscale to radians0.785 radiansequivalent measurement
What happens step by step when a degree value is converted into its equivalent radian value?

A 45-Degree Calculation

Converting 45 degrees before finding its sine

Find the radian equivalent of 45 degrees and use that value for a sine calculation.

Begin with the degree measurement: The starting angle is 45 degrees.

Apply the conversion formula: Calculate 45 / 360.0 * 2 * math.pi.

Read the converted angle: The result is approximately 0.785 radians.

Use the radian value: Pass approximately 0.785 radians to the sine function rather than passing 45 directly.

The sine calculation uses approximately 0.785 radians and produces approximately 0.707, the mathematically correct sine of 45 degrees.

What do you think happens?

If a trigonometric function receives 45 directly, will Python treat that value as 45 degrees or as 45 radians?

  • 45 degrees
  • 45 radians
Reveal answer

Answer: 45 radians

Python's trigonometric functions require radian arguments. Therefore, passing 45 directly does not calculate the trigonometric value for 45 degrees. Convert the degree value first.

The name radians is useful because it records the unit expected by the trigonometric function. After converting 45 degrees, the approximate value 0.785 is a radian measurement. That converted value is the one to use for the sine calculation, which gives approximately 0.707.

Why math.pi Matters

The conversion formula uses π because radians define a full circle as 2π. In Python, math.pi provides an approximation of π accurate to about 15 decimal places. This is more than sufficient for practical calculations and is more accurate than replacing π with a short hardcoded approximation such as 3.14159.

same full circlesame half circlerepresented by360 degreesfull circle180 degreeshalf circle2π radiansfull circleπ radianshalf circlemath.piapproximately 15-digitprecision
How does math.pi connect a full circle, 180 degrees, and π radians in a trigonometric calculation?

Degree-Radian Mistakes

passed without conversionconverted before use45 degreesintended angle45 degreesintended angle45interpreted as radians0.785 radiansconverted input
What changes when a degree value is passed directly to a function that expects radians?
  • Passing a degree value directly to sin, cos, or tan.

    Python interprets the argument as 45 radians, not 45 degrees, so the result is not the trigonometric value for the intended angle.

    Fix: Convert the degree value with degrees / 360.0 * 2 * math.pi before passing it to the function.

  • Using a hardcoded short approximation for π.

    The hardcoded value has less precision than the constant supplied by the math module.

    Fix: Use math.pi, which is accurate to about 15 decimal places.

  • Forgetting which unit a value represents.

    The value produced by the conversion is in radians, and the trigonometric function expects that radian value.

    Fix: Use clear names such as degrees and radians and keep track of the unit at each step.

Conversion Practice

EASY

A calculation needs the sine of a 90-degree angle. Describe the conversion you must perform before using the trigonometric function, and identify the Python constant you should use for π.

Hints
  • Python's trigonometric functions require radians.
  • Use degrees / 360.0 * 2 * math.pi.
  • The required constant is math.pi.
MEDIUM

A result seems wrong when calculating the sine of 45 degrees. Check whether the value 45 was passed directly to the trigonometric function. If it was, explain why that is a unit mistake and state the corrected approach.

Hints
  • Ask how Python interprets the number 45.
  • The direct value is treated as radians.
  • Convert 45 degrees to approximately 0.785 radians before calculating the sine.

Key Takeaways

  1. Python's trigonometric functions, including sin, cos, and tan, expect radians rather than degrees.
  2. Convert degrees with radians = degrees / 360.0 * 2 * math.pi.
  3. A 45-degree angle converts to approximately 0.785 radians, whose sine is approximately 0.707.
  4. Use math.pi instead of a hardcoded approximation for more accurate calculations.
  5. Passing degrees directly to a trigonometric function produces an incorrect result for the intended angle.

Key Takeaways

  • Python's trigonometric functions use radians, not degrees.
  • Convert a degree measurement by dividing by 360.0 and multiplying by 2 * math.pi.
  • Use math.pi for an accurate representation of π.
  • A direct degree value is interpreted as radians and can produce an incorrect result.
  • Track angle units carefully by naming and converting values before calculation.