Concepts / Basic Mathematical Functions

Basic Mathematical Functions

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

  • Programming

The Unit Hidden in an Angle

An angle such as 45 can be written in degrees, but Python's trigonometric functions interpret a number as radians. This means math.sin(45) does not calculate the sine of 45 degrees. It calculates the sine of 45 radians. Before calling math.sin(), math.cos(), or math.tan(), make sure the value is expressed in radians.

convertmath.sinmath.sin45 degreesdegree measurement0.785 radiansconverted input0.707sine result45 radiansdirect inputdifferent resultnot sine of 45 degrees
What changes when the same number is interpreted as degrees instead of radians by a Python trigonometric function?

A 45-Degree Trace

What do you think happens?

A 45-degree angle is converted to radians and then passed to math.sin(). What result should the calculation approach?

  • Approximately 0.707
  • Exactly 45
  • A result based on treating 45 as 45 radians
Reveal answer

Answer: Approximately 0.707

The 45-degree value is first converted to approximately 0.785 radians. The sine of that radian value is approximately 0.707.

import math radians = 45 / 360.0 * 2 * math.pi result = math.sin(radians) print(result)

Converting 45 Degrees

Find the radian equivalent of 45 degrees and use it as the input to a sine calculation.

Start with the degree measurement: The angle is 45 degrees.

Scale to the radian measurement: Use 45 / 360.0 * 2 * math.pi. Since a full circle is 360 degrees and 2π radians, this preserves the angle's position within a full circle.

Evaluate the converted angle: The conversion produces approximately 0.785 radians. Passing this value to math.sin() produces approximately 0.707.

The sine of 45 degrees is calculated by passing its radian equivalent, approximately 0.785, to math.sin(). The result is approximately 0.707.

divide by 360.0multiply by 2 * math.pi45degrees45 / 360.0fraction of a full circle0.785radians
How does a degree measurement map to its equivalent radian measurement using radians = degrees / 360.0 * 2 * π?

The Conversion Formula

The conversion works because a full circle has two equivalent descriptions: 360 degrees and 2π radians. Dividing a degree measurement by 360.0 finds what fraction of a full circle it represents. Multiplying that fraction by 2π expresses the same position on the radian scale.

radians = degrees / 360.0 * 2 * math.pi

math.pi is Python's representation of π. The source describes it as accurate to about 15 decimal places, making it suitable for practical trigonometric calculations.

same full rotationforms 2 * math.piprovides scale360 degreesfull circlemath.piPython's π value2π radiansfull circleradian inputfor math.sin, math.cos, ormath.tan
How does math.pi connect a full 360-degree rotation to 2π radians?

Repairing Unit Mix-Ups

passed directlyevaluatesconvertmath.sin45intended as degreesmath.sinreceives radiansincorrect resultnot sine of 45 degrees45 degreesoriginal measurement0.785 radiansconverted input0.707approximately
What happens when a degree value is passed directly to a Python trigonometric function instead of being converted first?
  • Passing a degree value directly to a trigonometric function.

    Python interprets 45 as 45 radians, not 45 degrees.

    Fix: Convert the degree value first, then pass the radian result to the function.

  • Assuming a variable's numeric value reveals its unit.

    The number 45 does not tell Python whether the intended unit is degrees or radians.

    Fix: Use a clear name such as radians after conversion, and keep track of the unit at every step.

  • Hardcoding a rough value for π.

    A typed approximation is less accurate than Python's math.pi constant.

    Fix: Use math.pi in the conversion formula.

Treat unit conversion as a separate step. Start with the degree measurement, calculate radians using degrees / 360.0 * 2 * math.pi, and only then call math.sin(), math.cos(), or math.tan(). Naming the converted value radians makes the expected input unit visible in the calculation.

Practice Check

EASY

A calculation needs the sine of 90 degrees. Write the conversion step that produces radians, then identify which value should be passed to math.sin().

Hints
  • Use radians = degrees / 360.0 * 2 * math.pi.
  • Substitute 90 for degrees.
  • Pass the converted radian value to math.sin(), not the original 90.
MEDIUM

A learner writes math.cos(45) while intending to calculate the cosine of 45 degrees. Explain the unit mistake and describe the correction without changing the intended angle.

Hints
  • Ask what unit math.cos() expects.
  • Convert 45 degrees to radians before calling math.cos().
  • Use math.pi rather than a manually typed approximation of π.

Takeaways

  1. Python's trigonometric functions take radians, not degrees.
  2. Convert degrees with radians = degrees / 360.0 * 2 * math.pi.
  3. A full circle is 360 degrees or 2π radians.
  4. Use math.pi for an accurate representation of π.
  5. Passing degrees directly to math.sin(), math.cos(), or math.tan() produces an incorrect result for the intended degree measurement.

Key Takeaways

  • Python's trigonometric functions interpret their arguments as radians.
  • Convert a degree measurement before using it in a trigonometric calculation.
  • The conversion formula is radians = degrees / 360.0 * 2 * math.pi.
  • math.pi provides an accurate value for π and should be preferred over a hardcoded approximation.
  • Clear unit tracking prevents incorrect results caused by mixing degrees and radians.