[Tutor] Trigonometric Functions in Python

Peter Otten __peter__ at web.de
Tue May 26 03:43:38 EDT 2020


boB Stepp wrote:

> Greetings April!
> 
> On Sun, May 24, 2020 at 08:09:32PM -0400, April Morone wrote:
>>I signed up for the ITP100 Software Design (Python Programming) class for
>>this Summer. I have been working ahead through the book, but came across
>>an issue with understanding something within Chapter 4 of the book "Python
>>for Everybody: Exploring Data in Python 3" that is by the author Charles
>>Severance on page 45. Please explain for me how the following checks the
>>result of the conversion from degrees to radius to get  0.7071067811865476
>>to see if the result is correct:
>>
>>math.sqrt(2) / 2.
>>
>>of the following:
>>
>>>>> degrees = 45
>>>>> radians = degrees / 360.0 * 2 * math.pi
>>>>> math.sin(radians)
>>0.7071067811865475
> 
> It is not totally clear to me exactly where you are not following things.
> It appears that it is the math, not the Python, which is unclear.
> 
> By definition there will be 2 * pi radians in a full 360 degree angle, or
> pi radians for a half-circle angle.  So 2 * pi radians = 360 degrees.  So
> the line above might be rewritten:
> 
> 2 * pi radians = 360 degrees
> 1 radian = 360/(2 * pi) degrees, or
> 1 degree = (2 * pi)/360 radians
> 
> Does that make sense?  So if 1 degree is the above, then 45 degrees would
> be:
> 
> 45 * 1 degrees = (45 * 2 * pi)/360 radians, which simplifies to
> 45 degrees = pi/4 radians
> 
> For a right triangle (implying a 90 degree angle) if one of the other two
> angles is 45 degrees then the other one will be, too, as the sum of all
> angles in a triangle must add up to 180 degrees.  And the two 45 degree
> angles imply that the height of the right triangle will equal the width of
> the triangle.
> 
> Using the Pythagorean Theorem which states that the sum of the squares of
> the sides must equal the square of the hypotenuse, or, if the width of the
> side is x, the height y and the hypotenuse length r, then
> 
> x**2 + y**2 = r**2
> 
> If we arbitrarily choose x = y = 1 for our 45 degree angle we would have:

I think the usual approach is to choose r = 1. Then for a point on the unit 
circle the arc starting at three'o'clock (x=1, y=0) is the radians, y the 
sine, and x the cosine. Pythagoras applies all the same ;)

> r**2 = 1**2 + 1**2
> r**2 = 2, and taking the square root of both sides:
> r = sqrt(2)
> 
> Sine of an angle = height / hypotenuse, so
> 
> sine(45 degrees) = 1/sqrt(2)
> 
> If you multiply the top and bottom by sqrt(2) you get
> 
> sine(45 degrees) = (sqrt(2) * 1) / (sqrt(2) * sqrt(2)) = sqrt(2) / 2
> 
> If you divide that out you will get the result you stated.
> 
> 
>>How does the following check the result of the above conversion from
>>degrees to radius to see if the result is correct?
>>
>>>>> math.sqrt(2) / 2.0
> 
> See above.  Does any of this help?  Note that what I wrote above is not
> actual
> Python code statements.  I am just trying to help you see the math.
> 




More information about the Tutor mailing list