Trignometry Python
Trignometry Python
INTRODUCTION 2
CHAPTER - 2 PYTHON 15
3.1 Pi (π) 21
3.2ANGLE CONVERSION BETWEEN RADIANS AND DEGREES:
MATH.DEGREES(), MATH.RADIANS() 22
3.3 SINE AND ARC SINE: MATH.SIN(), MATH.ASIN() 22
3.4 COSINE AND ARC COSINE: MATH.COS(), MATH.ACOS() 24
3.5 TANGENT AND ARC TANGENT: MATH.TAN(), MATH.ATAN(), MATH.ATAN2() 25
3.6 NEGATIVE ZERO 25
3.7 TRIGONOMETRIC FUNCTIONS 28
CONCLUSION 30
REFERENCE: 31
INTRODUCTION
The word “Trigonometry” comes from the Greek “trigonon” (meaning triangle) and “metron”
(meaning measure). So, simply put, Trigonometry is the study of the measures of triangles.
This includes the lengths of the sides, the measures of the angles and the relationships
between the sides and angles. The modern approach to Trigonometry also deals with how
right triangles interact with circles, especially the Unit Circle, i.e., a circle of radius 1.
Although the basic concepts are simple, the applications of Trigonometry are far reaching,
from cutting the required angles in kitchen tiles to determining the optimal trajectory for a
rocket to reach the outer planets. The modern definition of the sine is first attested in the
Surya Siddhanta, and its properties were further documented in the 5th century (AD) by
Indian mathematician and astronomer Aryabhata.[13] These Greek and Indian works were
By the 10th century AD, in the work of Persian mathematician Abū al-Wafā' al-Būzjānī, all
six trigonometric functions were used.[16] Abu al-Wafa had sine tables in 0.25° increments,
to 8 decimal places of accuracy, and accurate tables of tangent values.[16] He also made
Din al-Tusi has been described as the creator of trigonometry as a mathematical discipline in
its own right.[20][21][22] He was the first to treat trigonometry as a mathematical discipline
independent from astronomy, and he developed spherical trigonometry into its present form
2
CHAPTER - 1.TRIGNOMETRY (BASIC ANGLE DEFINITIONS)
A few definitions relating to angles are useful when beginning the study of Trigonometry.
Angle: A measure of the space between rays with a common endpoint. An angle is typically
Initial Side: The side of an angle from which it’s rotational measure begins.
Terminal Side: The side of an angle at which it’s rotational Measure ends.
Vertex: The vertex of an angle is the common endpoint of the two rays that define the angle.
Standard Position: An angle is in standard position if its vertex is the origin (i.e., the
Polar Axis: The Polar Axis is the positive axis. It is the initial side of all angles in standard
position. Polar Angle: For an angle in standard position, its polar angle is the angle measured
from the polar axis to its terminal side. If measured in a counter‐clockwise direction, the
polar angle is positive; if measured in a clockwise direction, the polar angle is negative.
Reference Angle: For an angle in standard position, its reference angle is the angle between
0° and 90° measured from the axis (positive or negative) to its terminal side. The reference
3
1.1GRAPHS OF BASIC (PARENT) TRIGONOMETRIC FUNCTIONS
It is instructive to view the parent trigonometric functions on the same axes as their reciprocal
Identifying patterns between the two functions can be helpful in graphing them.
Looking at the sine and cosecant functions, we see that they intersect at their maximum and
4
Looking at the cosine and secant functions, we see that
zero.
shown) of the each function occur when the other function is zero.
All trigonometric functions are periodic, meaning that they repeat the pattern of the
curve (called a cycle) on a regular basis. The key characteristics of each curve, along with
knowledge of the parent curves are sufficient to graph many trigonometric functions. Let’s
Amplitude
Amplitude is the measure of the distance of peaks and troughs from the midline (i.e., center)
of a sine or cosine function; amplitude is always positive. The other four functions do not
5
have peaks and troughs, so they do not have amplitudes. For the general function,f(x)
Period
Period is the horizontal width of a single cycle or wave, i.e., the distance it travels before it re
peats. Every trigonometric function has a period. The periods of the parent functions are as
follows: for sine, cosine, secant and cosecant, period is 2π; for tangent and cotangent, period
= π.
Frequency
Frequency is most useful when used with the sine and cosine functions. It is the reciprocal of
Frequency is typically discussed in relation to the sine and cosine functions when considering
harmonic motion or waves. In Physics, frequency is typically measured in Hertz, i.e., cycles
6
Phase Shift
Phase shift is how far has the function been shifted horizontally
(left or right) from its parent function. For the general function,
A positive phase shift indicates a shift to the right relative to the graph of the parent function;
a negative phase shift indicates a shift to the left relative to the graph of the parent function.
A trick for calculating the phase shift is to set the argument of the trigonometric function
Vertical Shift
Vertical shift is the vertical distance that the midline of a curve lies
above or below the midline of its parent function (i.e., the axis). For
single graph.
7
8
1.3 GRAPH OF A GENERAL SINE FUNCTION
General Form
The general form of a sine function is in this equation, we find several parameters of the
Amplitude: The amplitude is the magnitude of the stretch or compression of the function
Period
The period of a trigonometric function is the horizontal distance over which the curve travels
before it begins to repeat itself (i.e., begins a new cycle). For a sine or cosine function, this is
Phase Shift:
translation of the function. Note that the value of in the general form has a minus sign in
front of it, just like does in the vertex form of a quadratic equation So, A minus sign in front
A plus sign in front of the implies a implies a translation to the left. Vertical Shift:. This is
the distance of the vertical translation of the function. This is equivalent to in the vertex form
of a quadratic equation
9
1.4 GRAPH OF A GENERAL COSINE FUNCTION
General Form
The general form of a cosine function In this equation, we find several parameters of the
Period The period of a trigonometric function is the horizontal distance over which
the curve travels before it begins to repeat itself (i.e., begins a new cycle). For a sine or
cosine function, this is the length of one complete wave; it can be measured from peak to
Phase Shift
The phase shift is the distance of the horizontal translation of the function. Note that the
value of in the general form has a minus sign in front of it, just like does in the vertex form
10
1.5 GRAPH OF A GENERAL TANGENT FUNCTION
General Form
The general form of a tangent function is in this equation, we find several parameters of the
function which will help us graph it. In particular Scale factor. The tangent function does not
have amplitude. is the magnitude of the stretch or compression of the function from its parent
function Period The period of a trigonometric function is the horizontal distance over which
period of Phase Shift. The phase shift is the distance of the horizontal translation of the
function. Note that the value of in the general form has a minus sign in front of it, just like
does in the vertex form of a quadratic equation So, A minus sign in front of the implies a
translation to the right, and A plus sign in front of the implies a implies a translation to the
left.
Vertical Shift. This is the distance of the vertical translation of the function. This is
11
1.6 GRAPH OF A GENERAL COTANGENT FUNCTION
General Form
The general form of a cotangent function isIn this equation, we find several parameters of the
Scale factor: The cotangent function does not have amplitude. is the magnitude of the stretch
Period: The period of a trigonometric function is the horizontal distance over which the
curve travels before it begins to repeat itself (i.e., begins a new cycle). For a tangent or
cotangent function, this is the horizontal distance between consecutive asymptotes (it is also
Phase Shift: The phase shift is the distance of the horizontal translation of the function. Note
Vertical Shift: This is the distance of the vertical translation of the function. This is
12
1.7 GRAPH OF A GENERAL SECANT FUNCTION
General Form
The general form of a secant function is in this equation, we find several parameters of the
Scale factor: The secant function does not have amplitude.is the magnitude of the stretch or
Period: The period of a trigonometric function is the horizontal distance over which the
curve travels before it begins to repeat itself (i.e., begins a new cycle). For a secant or
cosecant function, this is the horizontal distance between consecutive maxima or minima (it
is also the distance between every second asymptote). Note that 2π is the period.
Phase Shift: The phase shift is the distance of the horizontal translation of the function. Note
that the value of in the general form has a minus sign in front of it, just like does in the vertex
form of a quadratic equation. So, A minus sign in front of the implies a translation to the
translation of the function. This is Equivalent in the vertex form of a quadratic equation
13
1.8 GRAPH OF A GENERAL COSECANT FUNCTION
General Form
The general form of a cosecant function is. In this equation, we find several parameters of the
function which will help us graph it. In particular Scale factor. The cosecant function does
not have amplitude.is the magnitude of the stretch or compression of the function from its
parent function:
Period:
The period of a trigonometric function is the horizontal distance over which the curve travels
before it begins to repeat itself (i.e., begins a new cycle). For a secant or cosecant function,
this is the horizontal distance between consecutive maxima or minima (it is also the distance
between every second asymptote). Note that 2π is the period of Phase Shift:. The phase
shift is the distance of the horizontal translation of the function. Note that the value of in the
general form has a minus sign in front of it, just like does in the vertex form of a quadratic
equation: A minus sign in front of the implies a translation to the right, and
translation of the function. This is equivalent to in the vertex form of a quadratic equation:
14
CHAPTER - 2 PYTHON
Python is a high-level scripting language which can be used for a wide variety of text
processing, system administration and internet-related tasks. Unlike many similar languages,
it’s core language is very small and easy to master, while allowing the addition of modules to
perform a virtually limitless variety of tasks. Python is a true object-oriented language, and is
available on a wide variety of platforms. There’s even a python interpreter written entirely in
Java, further enhancing python’s position as an excellent solution for internet-based problems.
Python was developed in the early 1990’s by Guido van Rossum, then at CWI in Amsterdam,
and currently at CNRI in Virginia. In some ways, python grew out of a project to design a
computer language which would be easy for beginners to learn, yet would be powerful enough
for even advanced users. This heritage is reflected in python’s small, clean syntax and the
eliminating the ability to program in a more traditional style. So python is an excellent choice
as a first programming language without sacrificing the power and advanced capabilities that
users will eventually need. Although pictures of snakes often appear on python books and
websites, the name is derived from Guido van Rossum’s favorite TV show, “Monty Python’s
Flying Circus”. For this reason, lots of online and print documentation for the language has a
light and humorous touch. Interestingly, many experienced programmers report that python has
brought back a lot of the fun they used to have programming, so van Rossum’s inspiration may
15
2.1 BASICS OF PYTHON
There are a few features of python which are different than other programming languages, and
which should be mentioned early on so that subsequent examples don’t seem confusing. Further
information on all of these features will be provided later, when the topics are covered in depth.
Python statements do not need to end with a special character – the python interpreter knows
that you are done with an individual statement by the presence of a newline, which will be
generated when you press the “Return” key of your keyboard. If a statement spans more than
one line, the safest course of action is to use a backslash (\) at the end of the line to let python
know that you are going to continue the statement on the next line; you can continue using
backslashes on additional continuation lines. (There are situations where the backslashes are
not needed which will be discussed later.) Python provides you with a certain level of freedom
when composing a program, but there are some rules which must always be obeyed. One of
these rules, which some people find very surprising, is that python uses indentation (that is, the
amount of white space before the statement itself) to indicate the presence of loops, instead of
using delimiters like curly braces ({}) or keywords (like “begin” and “end”) as in many other
languages. The amount of indentation you use is not important, but it must be consistent within
a given depth of a loop, and statements which are not indented must begin in the first column.
Most python programmers prefer to use an editor like emacs, which automatically provides
consistent indentation; you will probably find it easier to maintain your programs if you use
consistent indentation in every loop, at all depths, and an intelligent editor is very useful in
achieving this.
16
2.2 PRINCIPLES OF PYTHON
Python has many features that usually are found only in languages which are much more
complex to learn and use. These features were designed into python from its very first
beginnings, rather than being accumulated into an end result, as is the case with many other
scripting languages. If you’re new to programming, even the basic descriptions which follow
may seem intimidating. But don’t worry – all of these ideas will be made clearer in the chapters
which follow. The idea of presenting these concepts now is to make you aware of how python
works, and the general philosophy behind python programming. If some of the concepts that
Python is designed so that there really isn’t that much to learn in the basic language. For
example, there is only one basic structure for conditional programming (if/else/elif), two
looping commands (while and for), and a consistent method of handling errors (try/except)
which apply to all python programs. This doesn’t mean that the language is not flexible and
powerful, however. It simply means that you’re not confronted with an overwhelming choice
of options at every turn, which can make programming a much simpler task.
2.4 MODULES
Python relies on modules, that is, self-contained programs which define a variety of functions
and data types, that you can call in order to do tasks beyond the scope of the basic core
language by using the import command. For example, the core distribution of python contains
17
modules for processing files, accessing your computer’s operating system and the internet,
writing CGI scripts (which handle communicating with pages displayed in web browsers),
string handling and many other tasks. Optional modules, available on the Python web site
data bases, process image files, and so on. This structure makes it easy to get started with
python, learning specific skills only as you need them, as well as making python run more
Regardless how carefully you write your programs, when you start using them in a variety of
situations, errors are bound to occur. Python provides a consistent method of handling errors,
a topic often refered to as exception handling. When you’re performing an operation that
might result in an error, you can surround it with a try loop, and provide an except clause to
tell python what to do when a particular error arises. While this is a fairly advanced concept,
usually found in more complex languages, you can start using it in even your earliest python
programs. As a simple example, consider dividing two numbers. If the divisor is zero, most
programs (python included) will stop running, leaving the user back at a system shell prompt,
or with nothing at all. Here’s a little python program that illustrates this concept; assume
div.py:
#!/usr/local/bin/python
x=7
18
y=0
print x/y
When we run this program, we don’t get to the line which prints the message,
% div.py
print x/y
ZeroDivisionError: integer division or modulo While the message may look a little
complicated, the main point to notice is that the last line of the message tells us the name of
the exception that occured. This allows us to construct an except clause to handle the
problem:
x=7
y=0
try:
print x/y
except ZeroDivisionError:
19
print "Oops - I can’t divide by zero, sorry!"
% div.py
Now we’re done! Since each exception in python has a name, it’s very easy to modify your
program to handle errors whenever they’re discovered. And of course, if you can think ahead,
you can construct try/except clauses to catch errors before they happen.
20
CHAPTER – 3 TRIGONOMETRIC FUNCTIONS IN PYTHON
This module provides access to common mathematical functions and constants, including
These functions cannot be used with complex numbers; use the functions of the same name
from the cmath module if you require support for complex numbers. The distinction between
functions which support complex numbers and those which don’t is made since most users do
not want to learn quite as much mathematics as required to understand complex numbers.
Receiving an exception instead of a complex result allows earlier detection of the unexpected
complex number used as a parameter, so that the programmer can determine how and why it
In Python, you can calculate trigonometric functions (sin, cos, tan) and inverse trigonometric
The mathematical constant pi (π) is available as a constant in the math module and is
represented by math.pi.
print(math.pi)
# 3.141592653589793
21
3.2ANGLE CONVERSION BETWEEN RADIANS AND DEGREES:
MATH.DEGREES(), MATH.RADIANS()
In the math module, trigonometric and inverse trigonometric functions use radians as the unit
of angles.
print(math.degrees(math.pi))
# 180.0
print(math.radians(180))
# 3.141592653589793
Use math.sin() for the sine function and math.asin() for its inverse.
Here's an example of finding the sine of 30 degrees. Use math.radians() to convert degrees to
radians.
sin30 = math.sin(math.radians(30))
print(sin30)
# 0.49999999999999994
22
The sine of 30 degrees should be 0.5, but since pi is an irrational number, there
specific number of decimal places, use the round() function, specifying the
desired decimal places as the second argument. Note that this function employs
"round half to even" or "bankers' rounding", meaning it rounds to the nearest even
number.
print(round(sin30, 1))
# 0.5
To compare values while accounting for potential errors, you can use
math.isclose().
print(math.isclose(sin30, 0.5))
# True
Similarly, here's an example of finding the inverse sine of 0.5. Since math.asin()
asin05 = math.degrees(math.asin(0.5))
23
print(asin05)
# 29.999999999999996
print(round(asin05, 1))
# 30.0
Use math.cos() for the cosine function and math.acos() for its inverse.
Here's an example of finding the cosine of 60 degrees and the arc cosine of 0.5.
print(math.cos(math.radians(60)))
# 0.5000000000000001
print(math.degrees(math.acos(0.5)))
# 59.99999999999999
24
3.5 TANGENT AND ARC TANGENT: MATH.TAN(), MATH.ATAN(),
MATH.ATAN2()
Use math.tan() for the tangent function. The inverse functions are math.atan() and
Here's an example of finding the tangent of 45 degrees and the arc tangent of 1.
print(math.tan(math.radians(45)))
# 0.9999999999999999
print(math.degrees(math.atan(1)))
# 45.0
is negative zero, the angle is -pi (-180 degrees). Be cautious if you need to handle
print(math.degrees(math.atan2(-0.0, -1)))
25
# -180.0
print(-1 / math.inf)
# -0.0
print(-1.0 * 0.0)
# -0.0
print(-0.0)
# -0.0
print(-0)
#0
For cases when both x and y are zero (origin), the result may differ depending on
their signs.
print(math.degrees(math.atan2(0.0, 0.0)))
# 0.0
print(math.degrees(math.atan2(-0.0, 0.0)))
26
# -0.0
print(math.degrees(math.atan2(-0.0, -0.0)))
# -180.0
print(math.degrees(math.atan2(0.0, -0.0)))
# 180.0
math.atan() can produce results with different signs due to negative zero.
print(math.sin(0.0))
# 0.0
print(math.sin(-0.0))
# -0.0
print(math.asin(0.0))
# 0.0
print(math.asin(-0.0))
# -0.0
print(math.tan(0.0))
27
# 0.0
print(math.tan(-0.0))
# -0.0
print(math.atan(0.0))
# 0.0
print(math.atan(-0.0))
# -0.0
print(math.atan2(0.0, 1.0))
# 0.0
print(math.atan2(-0.0, 1.0))
# -0.0
import math as mt
x=0
28
N = 100
xdata = []
ydata = []
x = x + 0.1
xdata.append(x)
y = mt.sin(x)
ydata.append(y)
plt.plot(xdata, ydata)
plt.show()
The problem with using the Trigonometric functions in the the Math module
from the Python Standard Library is that they don't handle an array as input.
29
CONCLUSION
application aligns with legal and ethical standards. With the knowledge gained
from this guide, you’re well-equipped to tackle real-world problems that involve
library. It includes sine, cosine, tangent, inverse sine, inverse cosine, and inverse
tangent.
30
REFERENCE:
July 2024.
"Python 0.9.1 part 01/21". alt.sources archives. Archived from the original on 11
"Why is Python a dynamic language and also a strongly typed language". Python
Wiki. Archived from the original on 14 March 2021. Retrieved 27 January 2021.
"PEP 483 – The Theory of Type Hints". Python.org. Archived from the original
31