Get the App
SLTechnology News&Howtos  ›  Development  › 

How to calculate the length of the third side of a triangle by python

Shulou Source: shulou.com Published: 2022-05-31 16:54:38 09月17日 Update

This article mainly introduces the relevant knowledge of "how to solve the third side length of the triangle by python". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "how to solve the third side length of the triangle by python" can help you solve the problem.

Solve the import mathx=input of the third side of the triangle ('enter the length of both sides and the angle between them (degrees):') # use a space to separate three values. The split () method is used to segment the string c=math.sqrt (a**2+b**2-2*a*b*math.cos (theta*math.pi/180)) # cos () and the parameter is Radian print ('centering theta*math.pi/180 c).

Run screenshot

Usage of python trigonometric function

Trigonometric functions in python generally include:

Function description sin (x) returns the sine value of x radians cos (x) returns the cosine value of x radians tan (x) returns the tangent value of x radians asin (x) returns the arc value of x acos (x) returns the inverse cosine arc value of x atan (x) returns the arc value of x

The parameters of the above trigonometric function are: radians! It's not an angle!

In mathematics and physics, radians are the unit of measurement of angles.

It is a unit derived from the international unit, with the abbreviation rad. Definition: an arc whose length is equal to the radius and whose center angle is 1 degree.

360 °= 2 π radians, so 1 Radian is about 57.3 °, that is, 57 °17 °44.806 ".

1 °= π / 180 radians

180 °= π radians

(in python, pi = π, which is a mathematical constant, don't forget to quote math!)

When using trigonometric functions in python, you can't use them directly, you have to import the math module first.

As follows:

Import matha = math.cos (math.pi) # find cos (180 °) b = math.sin (math.pi/2) # find sin (90 °) print (AMO b) "output:-1.0"

In addition, there are two functions in the math module:

Degrees (x): converts radians to angles.

Radians (x): converts the angle to radians.

As follows:

Import matha = math.degrees (math.pi/2) print (a) b = math.radians (180) print (b) "" output: 90.03.141592653589793180 degrees is π. " This is the end of the introduction to "how to solve the third side length of a triangle by python". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Radians triangles functions triangles trigonometric functions units knowledge angles cosines parameters mathematics methods modules tangents sinusoids industries inputs outputs different Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Technology Linux Shulou Information NVidia