码迷,mamicode.com
首页 > 其他好文 > 详细

[从头学数学] 第179节 三角初等变换

时间:2016-04-16 11:01:33      阅读:655      评论:0      收藏:0      [点我收藏+]

标签:

剧情提要:
[机器小伟]在[工程师阿伟]的陪同下进入了结丹中期的修炼,
这次要修炼的目标是[三角初等变换]。

正剧开始:

星历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.707

cos45° = 0.707

tan45° = 1.0

sin30° = 0.5

cos30° = 0.866

tan30° = 0.577

sin75° = 0.966

cos75° = 0.259

tan75° = 3.732

sin15° = 0.259

cos15° = 0.966

tan15° = 0.268

sin90° = 1.0

cos90° = 0.0

tan90° = 1.633123935319537e+16

sin135° = 0.707

cos135° = -0.707

tan135° = -1.0

sin22.5° = 0.383

cos22.5° = 0.924

tan22.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节 三角初等变换

标签:

原文地址:http://blog.csdn.net/mwsister/article/details/51162065

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!