Trigonometric functions (Python, machine learning)

Side lengths and included angles of right triangles

A right triangle is a triangle in which one angle is 90 degrees.

Side length: There are 3 side lengths a, b, c, etc.

Nouns for side lengths: a is height, b is base, and c is hypotenuse.

Right angle: The angle between a (height) and b (base) is a right angle.

\theta: The angle between b and c is pronounced Theta.

The three angles of a triangle add up to 180 degrees. Subtracting the right angles, we can get that the angle between a and c is 90^{\circ}- \theta.

 

Definition of trigonometric functions

sin\theta =\frac{a}{c}        a=height c=hypotenuse

con\theta =\frac{b}{c}        b=bottom c=hypotenuse

tan\theta =\frac{a}{b}        a=high b=bottom

Calculate the area of ​​a triangle

omission

angles and radians

Radian is also called diameter and is generally represented by rad.

The angle corresponding to 360 degrees is 2 radian\pi

Common angle and radian conversion tables
Angle value radian value Angle value radian value
30 \frac{\pi }{6} 120 \frac{2\pi }{3}
45 \frac{\pi }{4} 135 \frac{3\pi }{4}
60 \frac{\pi }{3} 150 \frac{5\pi }{6}
90 \frac{\pi }{2} 180 \pi

List the radian values ​​of angles with angle values ​​30, 45, 60, 120, 135, 150, and 180.

import math

degrees = [30, 45, 60, 90, 120, 135, 150, 180]
for degree in degrees:
    print('角度 = {0:3d},   弧度 = {1:6.3f}'.format(degree, math.pi*degree/180))

The running results are as follows:

[Running] python -u "c:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\tempCodeRunnerFile.py"
角度 =  30,   弧度 =  0.524
角度 =  45,   弧度 =  0.785
角度 =  60,   弧度 =  1.047
角度 =  90,   弧度 =  1.571
角度 = 120,   弧度 =  2.094
角度 = 135,   弧度 =  2.356
角度 = 150,   弧度 =  2.618
角度 = 180,   弧度 =  3.142

[Done] exited with code=0 in 0.296 seconds

Arc length refers to the length of the curve on the circumference of the circle.

General formula for calculating the arc length of a circle, assuming the angle is \theta:2*\pi *r*\frac{\theta }{360}=\frac{\theta}{180}\pi r

The calculated radius is 10 cm, and the angle values ​​are the corresponding arc length values ​​of 30, 60, 90, and 120.

import math

degrees = [30, 60, 90, 120]
r = 10
for degree in degrees:
    curve = 2 * math.pi * r * degree / 360
    print('角度 = {0:3d},   弧长 = {1:6.3f}'.format(degree, curve))

The running results are as follows:

[Running] python -u "c:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\tempCodeRunnerFile.py"
角度 =  30,   弧长 =  5.236
角度 =  60,   弧长 = 10.472
角度 =  90,   弧长 = 15.708
角度 = 120,   弧长 = 20.944

[Done] exited with code=0 in 0.301 seconds

Assume that the radius of the circle is r, the sector angle is \theta, and the sector area calculation formula is:\pi*r^2*\frac{\theta }{360}

Calculate the corresponding sector area values ​​​​when the radius is 10 cm and the angle values ​​​​are 30, 60, 90, and 120.

import math

degrees = [30, 60, 90, 120]
r = 10
for degree in degrees:
    area = math.pi * r * r * degree / 360
    print('角度 = {0:3d},   扇形面积 = {1:6.3f}'.format(degree, area))

operation result:

[Running] python -u "c:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\tempCodeRunnerFile.py"
角度 =  30,   扇形面积 = 26.180
角度 =  60,   扇形面积 = 52.360
角度 =  90,   扇形面积 = 78.540
角度 = 120,   扇形面积 = 104.720

[Done] exited with code=0 in 0.425 seconds

 

Programs to handle trigonometric functions

Every other time 30^{\circ}, list the degrees of angle and the values ​​of sin() and cos(). 

import math

degrees = [x*30 for x in range(0,13)]
for d in degrees:
    rad = math.radians(d)
    sin = math.sin(rad)
    cos = math.cos(rad)
    print('角度={0:3d}, 弧度={1:5.2f}, sin{2:3d}={3:5.2f}, cos{4:3d}={5:5.2f}'
          .format(d, rad, d, sin, d, cos))

The running results are as follows:

[Running] python -u "c:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\tempCodeRunnerFile.py"
角度=  0, 弧度= 0.00, sin  0= 0.00, cos  0= 1.00
角度= 30, 弧度= 0.52, sin 30= 0.50, cos 30= 0.87
角度= 60, 弧度= 1.05, sin 60= 0.87, cos 60= 0.50
角度= 90, 弧度= 1.57, sin 90= 1.00, cos 90= 0.00
角度=120, 弧度= 2.09, sin120= 0.87, cos120=-0.50
角度=150, 弧度= 2.62, sin150= 0.50, cos150=-0.87
角度=180, 弧度= 3.14, sin180= 0.00, cos180=-1.00
角度=210, 弧度= 3.67, sin210=-0.50, cos210=-0.87
角度=240, 弧度= 4.19, sin240=-0.87, cos240=-0.50
角度=270, 弧度= 4.71, sin270=-1.00, cos270=-0.00
角度=300, 弧度= 5.24, sin300=-0.87, cos300= 0.50
角度=330, 弧度= 5.76, sin330=-0.50, cos330= 0.87
角度=360, 弧度= 6.28, sin360=-0.00, cos360= 1.00

[Done] exited with code=0 in 1.662 seconds

Looking at trigonometric functions from the unit circle

Suppose there is a circle with a radius of 1, a point P on the circumference, and the coordinates of point P are (con \theta,sin\theta).

Label every other point on the fillet 30^{\circ}.

import matplotlib.pyplot as plt
import math

degrees = [x*15 for x in range(0,25)]
x = [math.cos(math.radians(d)) for d in degrees]
y = [math.sin(math.radians(d)) for d in degrees]

plt.scatter(x,y)
plt.axis('equal')
plt.grid()
plt.show()

The running results are as follows:

 

Use trigonometric functions to draw a circle with radius 1.

import matplotlib.pyplot as plt
import numpy as np

degrees = np.arange(0, 360)
x = np.cos(np.radians(degrees))
y = np.sin(np.radians(degrees))

plt.plot(x,y)
plt.axis('equal')
plt.grid()
plt.show()

The running results are as follows:

 

Guess you like

Origin blog.csdn.net/DXB2021/article/details/127185389