標籤:
劇情提要:
[機器小偉]在[工程師阿偉]的陪同下進入了結丹中期的修鍊,
這次要修鍊的目標是[三角初等變換]。
正劇開始:
星曆2016年04月15日 15:32:35, 銀河系厄爾斯星球中華帝國江南行省。
[工程師阿偉]正在和[機器小偉]一起研究[三角初等變換]。
<span style="font-size:18px;">if (1) {var mathText = new MathText();var s = ['和角、差角公式','sin(A+B) = sinAcosB+sinBcosA','sin(A-B) = sinAcosB-sinBcosA',' ','cos(A+B) = cosAcosB-sinAsinB','cos(A-B) = cosAcosB+sinAsinB',' ','tan(A+B) = (tanA+tanB)/(1-tanA*tanB)','tan(A-B) = (tanA-tanB)/(1+tanA*tanB)',];var x =40, y=40;var r1 = 40;var len = s.length;for (var i = 0; i < len; i++) {if (s[i] == '') {if (x < 100) {x += 300;y-=r1*3;}else {x = 20;y += r1;}}else {mathText.print(s[i], x, y);y+=r1;}}}</span>
<span style="font-size:18px;">var s = ['倍角公式','sin2a = 2sinacosa','cos2a = cos^[2]a-sin^[2]a','tan2a = 2tana/(1-tan^[2]a)',' ','cos2a = 2cos^[2]a-1','cos2a = 1-2sin^[2]a',];</span>
<span style="font-size:18px;">var s = ['半形公式','sin(a/2) = ±((1-cosa)/2)^[0.5]','cos(a/2) = ±((1+cosa)/2)^[0.5]','tan(a/2) = ±((1-cosa)/(1+cosa))^[0.5] ','= sina/(1+cosa) ','= (1-cosa)/sina',];</span>
以前這種公式還有很多,都是前人的經驗和智囊的結晶,
可是時過境遷哪,現在不管怎麼算,哪比得上先求出角度,
再直接算來得准和快呢。所以[人叫板老師]也覺得這些公式
點到為止就行了。
當然,小偉還是做了一個工具,一般來說應該夠用了:
<span style="font-size:18px;">>>> sin45° = 0.707cos45° = 0.707tan45° = 1.0sin30° = 0.5cos30° = 0.866tan30° = 0.577sin75° = 0.966cos75° = 0.259tan75° = 3.732sin15° = 0.259cos15° = 0.966tan15° = 0.268sin90° = 1.0cos90° = 0.0tan90° = 1.633123935319537e+16sin135° = 0.707cos135° = -0.707tan135° = -1.0sin22.5° = 0.383cos22.5° = 0.924tan22.5° = 0.414#三角恒等式def tmp(angle1, angle2 = 0): task = [ #第一個角的三角函數值 ['sin', angle1], ['cos', angle1], ['tan', angle1], #第二個角的三角函數值 ['sin', angle2], ['cos', angle2], ['tan', angle2], #和角公式 ['sin', angle1+angle2], ['cos', angle1+angle2], ['tan', angle1+angle2], #差角公式 ['sin', angle1-angle2], ['cos', angle1-angle2], ['tan', angle1-angle2], #二倍角 ['sin', angle1*2], ['cos', angle1*2], ['tan', angle1*2], #三倍角 ['sin', angle1*3], ['cos', angle1*3], ['tan', angle1*3], #半形 ['sin', angle1/2], ['cos', angle1/2], ['tan', angle1/2] ]; triFun(task);if __name__ == '__main__': tmp(45, 30);</span>
<span style="font-size:18px;">>>> 5400[0.0002908882045634, 0.00058178, 0.00087266, 0.00116355, 0.00145444, 0.00174533, 0.00203622, 0.0023271, 0.00261799, 0.00290888, 0.00319976, 0.00349065, 0.00378154, 0.00407242, 0.00436331, 0.00465419, 0.00494508, 0.00523596, 0.00552685, 0.00581773, 0.00610861, 0.0063995, 0.00669038, 0.00698126, 0.00727214, 0.00756302, 0.0078539, 0.00814478, 0.00843566, 0.00872654, 0.00901741, 0.00930829, 0.00959916, 0.00989004, 0.01018091, 0.01047178, 0.01076266, 0.01105353, 0.0113444, 0.01163527, 0.01192613, 0.012217, 0.01250787, 0.01279873, 0.0130896, 0.01338046, 0.01367132, 0.01396218, 0.01425304, 0.0145439, 0.01483475, 0.01512561, 0.01541646, 0.01570732, 0.01599817, 0.01628902, 0.01657987, 0.01687072, 0.01716156, 0.01745241, 0.01774325, 0.01803409, 0.01832493, 0.01861577, 0.01890661, 0.01919744, 0.01948828, 0.01977911, 0.02006994, 0.02036077, 0.02065159, 0.02094242, 0.02123324, 0.02152407, 0.02181489, 0.0221057, 0.02239652, 0.02268733, 0.02297815, 0.02326896, 0.02355976, 0.02385057, 0.02414138, 0.02443218, 0.02472298, 0.02501378, 0.02530457, 0.02559537, 0.02588616, 0.02617695, 0.02646774, 0.02675852, 0.0270493, 0.02734008, 0.02763086, 0.02792164, 0.02821241, 0.02850318, 0.02879395, 0.02908472]#[0, 90]度角範圍內正弦三角函數表def triTable(): import math; #1'角的三角函數值 sin1 = 0.0002908882045634; cos1 = math.sqrt(1-sin1*sin1); #90度內 sin = sin1; cos = cos1; #存放值 array = []; array.append(sin); while (sin < 1): sin = sin1*cos+cos1*sin; cos = math.sqrt(1-sin*sin); array.append(round(sin, 8)); #每次1'角遞增,array數組應有元素90*60=5400個 print(len(array));#看看前100個元素 print(array[:100]);</span>
<span style="font-size:18px;">#### @usage 三角函數調用封裝# @author mw# @date 2016年04月05日 星期二 09:36:50 # @param# @return####def triFun(task, prec = 3): #需要計算的任務 #輸入量為角度制,依次為度,分,秒 #可輸出顯示度、分、秒的運算式 #用於計算銳角三角函數 #對於角度變換,還沒有經過測試 #以後可擴充添加其它多種數學函數 size = len(task); result = []; import math; precision = max(prec, 3); for i in range(size): if task[i][0] == 'sin' or task[i][0] == 'cos' or task[i][0] == 'tan' or task[i][0] == 'cot': taskNew = task[i]; part1 = angleTransfer(taskNew[1:]); len1 = len(part1); taskNew = [taskNew[0]]; for n in range(len1): taskNew.append(part1[n]); size_1 = len(task[i]); angle = 0; if size_1 == 2: angle = taskNew[1]; elif size_1 == 3: angle = taskNew[1]+taskNew[2]/60; elif size_1 == 4: angle = taskNew[1]+taskNew[2]/60+taskNew[3]/3600; angle = angle/180*math.pi; if task[i][0] == 'sin': s = ''; if size_1 == 2: s = task[i][0]+str(task[i][1])+'°'; elif size_1 == 3: s = task[i][0]+str(task[i][1])+'°'+str(task[i][2])+'\''; elif size_1 == 4: s = task[i][0]+str(task[i][1])+'°'+str(task[i][2])+'\''+str(task[i][3])+'″'; s += ' = '; s += str(round(math.sin(angle), precision)); s += '\n'; result.append(s); elif task[i][0] == 'cos': s = ''; if size_1 == 2: s = task[i][0]+str(task[i][1])+'°'; elif size_1 == 3: s = task[i][0]+str(task[i][1])+'°'+str(task[i][2])+'\''; elif size_1 == 4: s = task[i][0]+str(task[i][1])+'°'+str(task[i][2])+'\''+str(task[i][3])+'″'; s += ' = '; s += str(round(math.cos(angle), precision)); s += '\n'; result.append(s); elif task[i][0] == 'tan': s = ''; if size_1 == 2: s = task[i][0]+str(task[i][1])+'°'; elif size_1 == 3: s = task[i][0]+str(task[i][1])+'°'+str(task[i][2])+'\''; elif size_1 == 4: s = task[i][0]+str(task[i][1])+'°'+str(task[i][2])+'\''+str(task[i][3])+'″'; s += ' = '; s += str(round(math.tan(angle), precision)); s += '\n'; result.append(s); elif task[i][0] == 'cot': s = ''; if size_1 == 2: s = task[i][0]+str(task[i][1])+'°'; elif size_1 == 3: s = task[i][0]+str(task[i][1])+'°'+str(task[i][2])+'\''; elif size_1 == 4: s = task[i][0]+str(task[i][1])+'°'+str(task[i][2])+'\''+str(task[i][3])+'″'; s += ' = '; s += str(round(1/math.tan(angle), precision)); s += '\n'; result.append(s); else: if task[i][0] == 'asin': s = ''; s = task[i][0]+str(task[i][1])+' = '; res = math.asin(task[i][1])/math.pi*180; if res < 0: s += '-'; absres = abs(res); s += str(math.floor(absres))+'°'+str(math.floor(absres*60)%60)+'\''+str(round(absres*3600)%60)+'″'; s += '\n'; result.append(s); elif task[i][0] == 'acos': s = ''; s = task[i][0]+str(task[i][1])+' = '; res = math.acos(task[i][1])/math.pi*180; if res < 0: s += '-'; absres = abs(res); s += str(math.floor(absres))+'°'+str(math.floor(absres*60)%60)+'\''+str(round(absres*3600)%60)+'″'; s += '\n'; result.append(s); elif task[i][0] == 'atan': s = ''; s = task[i][0]+str(task[i][1])+' = '; res = math.atan(task[i][1])/math.pi*180; if res < 0: s += '-'; absres = abs(res); s += str(math.floor(absres))+'°'+str(math.floor(absres*60)%60)+'\''+str(round(absres*3600)%60)+'″'; s += '\n'; result.append(s); elif task[i][0] == 'acot': s = ''; s = task[i][0]+str(task[i][1])+' = '; res = 90-math.atan(task[i][1])/math.pi*180; if res < 0: s += '-'; absres = abs(res); s += str(math.floor(absres))+'°'+str(math.floor(absres*60)%60)+'\''+str(round(absres*3600)%60)+'″'; s += '\n'; result.append(s); else: pass; size = len(result); for i in range(size): print(result[i]); return result; #把任意角轉化成[0, 360]度範圍內的角度。#傳入[度, 分,秒]#傳出[度, 分,秒]def angleTransfer(a): #傳入的角度可以只有度,也可也有分,也可以有秒 #這樣會造成數組的大小變動 accuracy = len(a); if (a[0] < 0): if accuracy == 2: if (a[1] != 0): a[0]-=1; a[1] = 60-a[1]; elif accuracy == 3: if (a[1] != 0 or a[2] != 0): a[0] -=1; if (a[2] != 0): a[1] = 59-a[1]; a[2] = 60-a[2]; else: a[1] = 60-a[1]; while a[0] < 0: a[0]+=360; elif (a[0] >= 360): while a[0] >= 360: a[0]-=360; return a;</span>
本節到此結束,欲知後事如何,請看下回分解。
[從頭學數學] 第179節 三角初等變換