Memo using trigonometric functions

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_B I needed it for the question here

The values given in the sample are The length of a, the length of b, the size of C, 4 3 90 It has become. This is a sample value, and the angle between abs is 90 degrees, which is a very convenient angle, so there is no need to calculate sin or cos. In the test case, this is not the case, so it is necessary to calculate with sin and cos.

sankaku.py


#sin,Needed for cos
#The square root calculation is x**0.It seems that 5 can be used as a substitute
import math
 
#Receive value here
(a,b,C) = map(float, raw_input().split())
#Change the angle C to the number of radians.
#Unknown what the radian number is
cs=math.radians©
#Here, the length of the remaining third side is calculated by the cosine theorem.
#The formula is a^2=b^2+c^2-2ab*cosA
#Here math.The length of the side is immediately calculated by sqrt.
c=math.sqrt(a**2+b**2-2*a*b*math.cos(cs))
#The sine theorem gives the height when m is the base.
h=b*math.sin(c)
#The area of the triangle from the length of the three sides. Not used this time and in a graffiti state.
#ans=(s*(s-b)*(s-n)*(s-o))**0.5
#print ((a-o)**2 + (b-p)**2)**0.5
#print ans
#Calculate and output the total of area and side length.
S=h*n/2
L=a+b+c
print S
print L
print h

Image of this triangle 三角形

The three sides are defined by lowercase letters a, b, and c. I feel that I learned in junior high school and high school that the angle between sides a and b (facing side c) is defined as ∠C. And the sadness of forgetting to write the height h even though I started painting. I'll fix it someday. .. ..

It seems that radians are also called the arc degree method. ↓ Correspondence table with the frequency method.

Frequency method 30° 45° 60° 90° 180° 360°
Radian method 0 π/6 π/4 π/3 π/2 π

I wonder if the notation of this table will be bold in the upper row. Or maybe I have a workaround but I'll look it up. Well, the frequency method is familiar to you! By emphasizing. If you want to know why the radians were born and when and how to use them, please refer to the pass for details.

It seems that degrees and deg are sometimes used for notation in the degree system. If you see a variable called deg when you see someone who writes clean code, it's probably an angle in degrees. It seems that it is rad in the notation of the radian number of the arc degree method. Unfortunately, π is a character that cannot be used in the source code. Although it is pi in English notation, it seems that it is better to avoid using it for variable names because it is covered with math.pi.

Given the length of the two sides and the angle between them, I plan to write a little more than the area of the triangle and the length of the three sides.

13/10/15 Around 23:00 Correct the jumbled notation. A little supplement about the number of radians.

Scribbled so far 13/10/15 around 3 o'clock I will fix it later Note Unify the notation of n, m, o and a, b, c and so on. Without a diagram, it would be difficult for someone to read it. Even if you read it later, you won't understand it, so draw a diagram.

Recommended Posts

Memo using trigonometric functions
[Python] Memo about functions
[Azure] Try using Azure Functions
I tried using easydict (memo).
Python memo using perl --join
Python control syntax, functions (Python learning memo ②)
Variable scope when using internal functions
Using global variables in python functions
Data acquisition memo using Backlog API
This and that using NLTK (memo)
Information recording memo using session in Django
Python memo using perl --format is convenient.
[Control engineering] Graphing transfer functions using Python
Try using Python with Google Cloud Functions
Graph trigonometric functions with numpy and matplotlib
I tried using pipenv, so a memo