C语言怎样表示三角函数计算(注:要用“角度制”表示)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言怎样表示三角函数计算(注:要用“角度制”表示)相关的知识,希望对你有一定的参考价值。

    C语言的三角函数库采用的单位都是弧度,如果要使用角度,就必须转换,从角度转换成弧度,或者是重写一个三角函数库。

    方法一,在调用三角函数之前先把角度换算成弧度,调用反三角函数之后把弧度换算成角度就可以了。可以用 pi = 4.0 * atan(1) 算出pi,用 a = d /180.0*pi 转换角度到弧度。

    例如: sin(45 /180.0*pi); 就是计算的sin45。

    方法二,直接覆写三角函数。

    例如sin函数:

    double dsin(double d)

         return sin(45 /180.0*pi); //原理和方法一样,调用的时候直接使用dsin(45)即可



参考技术A 在调用三角函数之前先把角度换算成弧度,调用反三角函数之后把弧度换算成角度就可以了。可以用 pi = 4.0 * atan(1) 算出pi,用 a = h * 180.0/pi 算角度,用 h = a * pi /180 算弧度。本回答被提问者采纳 参考技术B 换算呗。。。

角度制下的反三角函数计算程序

VB.NET

Module ArcTrigono Dim F, o, x, d, m, s As Primitive Sub Main() F(1) = "arcsin(x) = " F(2) = "arcsec(x) = " F(3) = "arccos(x) = " F(4) = "arccsc(x) = " F(5) = "arctan(x) = " F(6) = "arccot(x) = "Start: TextWindow.Clear() TextWindow.WriteLine("① arcsin(x)") TextWindow.WriteLine("② arcsec(x)") TextWindow.WriteLine("③ arccos(x)") TextWindow.WriteLine("④ arccsc(x)") TextWindow.WriteLine("⑤ arctan(x)") TextWindow.WriteLine("⑥ arccot(x)") TextWindow.Write("请选择:") o = TextWindow.ReadNumber() If o = 1 Then Input() If Microsoft.SmallBasic.Library.Math.Abs(x) > 1 Then TextWindow.WriteLine("定义域错误!") Else d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcSin(x)) Output() End If ElseIf o = 2 Then Input() If Microsoft.SmallBasic.Library.Math.Abs(x) < 1 Then TextWindow.WriteLine("定义域错误!") Else d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcCos(1 / x)) Output() End If ElseIf o = 3 Then Input() If Microsoft.SmallBasic.Library.Math.Abs(x) > 1 Then TextWindow.WriteLine("定义域错误!") Else d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcCos(x)) Output() End If ElseIf o = 4 Then Input() If Microsoft.SmallBasic.Library.Math.Abs(x) < 1 Then TextWindow.WriteLine("定义域错误!") Else d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcSin(1 / x)) Output() End If ElseIf o = 5 Then Input() d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcTan(x)) Output() ElseIf o = 6 Then Input() d = 90 - Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcTan(x)) End If Output() Else Goto Start End If End Sub Sub Input() TextWindow.Clear() TextWindow.Write("x = ") x = TextWindow.ReadNumber() End Sub Sub Output() TextWindow.Write(F(o)) TextWindow.ForegroundColor = "Red" TextWindow.Write(d + "度") TextWindow.ForegroundColor = "Gray" TextWindow.Write(" = ") TextWindow.ForegroundColor = "Red" If d < 0 Then TextWindow.Write("-") d = -d End If m = (d - Microsoft.SmallBasic.Library.Math.Floor(d)) * 60 d = Microsoft.SmallBasic.Library.Math.Floor(d) s = (m - Microsoft.SmallBasic.Library.Math.Floor(m)) * 60 m = Microsoft.SmallBasic.Library.Math.Floor(m) TextWindow.Write(d + "度") TextWindow.ForegroundColor = "Yellow" TextWindow.Write(m + "分") TextWindow.ForegroundColor = "Green" TextWindow.WriteLine(s + "秒") TextWindow.ForegroundColor = "Gray" End SubEnd Module


Module ArcTrigono Dim F, o, x, d, m, s As Primitive Sub Main() F(1) = "arcsin(x) = " F(2) = "arcsec(x) = " F(3) = "arccos(x) = " F(4) = "arccsc(x) = " F(5) = "arctan(x) = " F(6) = "arccot(x) = "Start: TextWindow.Clear() TextWindow.WriteLine("① arcsin(x)") TextWindow.WriteLine("② arcsec(x)") TextWindow.WriteLine("③ arccos(x)") TextWindow.WriteLine("④ arccsc(x)") TextWindow.WriteLine("⑤ arctan(x)") TextWindow.WriteLine("⑥ arccot(x)") TextWindow.Write("请选择:") o = TextWindow.ReadNumber() If o = 1 Then Input() If (x < -1) Or (x > 1) Then TextWindow.WriteLine("定义域错误!") Else d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcSin(x)) Output() End If ElseIf o = 2 Then Input() If (x > -1) And (x < 1) Then TextWindow.WriteLine("定义域错误!") Else d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcCos(1 / x)) Output() End If ElseIf o = 3 Then Input() If (x < -1) Or (x > 1) Then TextWindow.WriteLine("定义域错误!") Else d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcCos(x)) Output() End If ElseIf o = 4 Then Input() If (x > -1) And (x < 1) Then TextWindow.WriteLine("定义域错误!") Else d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcSin(1 / x)) Output() End If ElseIf o = 5 Then Input() d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcTan(x)) Output() ElseIf o = 6 Then Input() d = 90 - Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcTan(x)) End If Output() Else Goto Start End If End Sub Sub Input() TextWindow.Clear() TextWindow.Write("x = ") x = TextWindow.ReadNumber() End Sub Sub Output() TextWindow.Write(F(o)) TextWindow.ForegroundColor = "Red" TextWindow.Write(d) TextWindow.Write("度") TextWindow.ForegroundColor = "Gray" TextWindow.Write(" = ") TextWindow.ForegroundColor = "Red" If d < 0 Then TextWindow.Write("-") d = -d End If m = (d - Microsoft.SmallBasic.Library.Math.Floor(d)) * 60 d = Microsoft.SmallBasic.Library.Math.Floor(d) s = (m - Microsoft.SmallBasic.Library.Math.Floor(m)) * 60 m = Microsoft.SmallBasic.Library.Math.Floor(m) TextWindow.Write(d) TextWindow.Write("度") TextWindow.ForegroundColor = "Yellow" TextWindow.Write(m) TextWindow.Write("分") TextWindow.ForegroundColor = "Green" TextWindow.Write(s) TextWindow.WriteLine("秒") TextWindow.ForegroundColor = "Gray" End SubEnd Module

JScript.NET

import System;var F=["定义域错误!","arcsin(x) = ","arcsec(x) = ","arccos(x) = ","arccsc(x) = ","arctan(x) = ","arccot(x) = "],o,x,d,m,s;for(;;){ Console.Clear(); Console.Write("① arcsin(x)\n② arcsec(x)\n③ arccos(x)\n④ arccsc(x)\n⑤ arctan(x)\n⑥ arccot(x)\n请选择:"); o=Console.ReadLine(); if(o==1) { Input(); if(Math.abs(x)>1) Console.WriteLine(F[0]); else { d=Math.asin(x)/Math.PI*180; Output(); } break; } if(o==2) { Input(); if(Math.abs(x)<1) Console.WriteLine(F[0]); else { d=Math.acos(1/x)/Math.PI*180; Output(); } break; } if(o==3) { Input(); if(Math.abs(x)>1) Console.WriteLine(F[0]); else { d=Math.acos(x)/Math.PI*180; Output(); } break; } if(o==4) { Input(); if(Math.abs(x)<1) Console.WriteLine(F[0]); else { d=Math.asin(1/x)/Math.PI*180; Output(); } break; } if(o==5) { Input(); d=Math.atan(x)/Math.PI*180; Output(); break; } if(o==6) { Input(); d=90-Math.atan(x)/Math.PI*180; Output(); break; }}function Input(){ Console.Clear(); Console.Write("x = "); x=Console.ReadLine();}function Output(){ Console.Write(F[o]); Console.ForegroundColor=12; Console.Write(d+"度"); Console.ForegroundColor=7; Console.Write(" = "); Console.ForegroundColor=12; if(d<0) { Console.Write("-"); d=-d; } m=(d-Math.floor(d))*60; d=Math.floor(d); s=(m-Math.floor(m))*60; m=Math.floor(m); Console.Write(d+"度"); Console.ForegroundColor=14; Console.Write(m+"分"); Console.ForegroundColor=10; Console.WriteLine(s+"秒"); Console.ForegroundColor=7;}


import System;var F=["定义域错误!","arcsin(x) = ","arcsec(x) = ","arccos(x) = ","arccsc(x) = ","arctan(x) = ","arccot(x) = "],o,x,d,m,s;for(;;){ Console.Clear(); Console.Write("① arcsin(x)\n② arcsec(x)\n③ arccos(x)\n④ arccsc(x)\n⑤ arctan(x)\n⑥ arccot(x)\n请选择:"); o=Console.ReadLine(); if(o==1) { Input(); if(x<-1||x>1) Console.WriteLine(F[0]); else { d=Math.asin(x)/Math.PI*180; Output(); } break; } if(o==2) { Input(); if(x>-1&&x<1) Console.WriteLine(F[0]); else { d=Math.acos(1/x)/Math.PI*180; Output(); } break; } if(o==3) { Input(); if(x<-1||x>1) Console.WriteLine(F[0]); else { d=Math.acos(x)/Math.PI*180; Output(); } break; } if(o==4) { Input(); if(x>-1&&x<1) Console.WriteLine(F[0]); else { d=Math.asin(1/x)/Math.PI*180; Output(); } break; } if(o==5) { Input(); d=Math.atan(x)/Math.PI*180; Output(); break; } if(o==6) { Input(); d=90-Math.atan(x)/Math.PI*180; Output(); break; }}function Input(){ Console.Clear(); Console.Write("x = "); x=Console.ReadLine();}function Output(){ Console.Write(F[o]); Console.ForegroundColor=12; Console.Write(d);Console.Write("度"); Console.ForegroundColor=7; Console.Write(" = "); Console.ForegroundColor=12; if(d<0) { Console.Write("-"); d=-d; } m=(d-Math.floor(d))*60; d=Math.floor(d); s=(m-Math.floor(m))*60; m=Math.floor(m); Console.Write(d);Console.Write("度"); Console.ForegroundColor=14; Console.Write(m);Console.Write("分"); Console.ForegroundColor=10; Console.Write(s);Console.WriteLine("秒"); Console.ForegroundColor=7;}

Forse altri canterà con miglior plettro.


以上是关于C语言怎样表示三角函数计算(注:要用“角度制”表示)的主要内容,如果未能解决你的问题,请参考以下文章

在c语言里怎么办输入的弧度制转化为角度值

在C语言中,输入一个数值,将它转换成弧度,怎么转换?

想用单片机测量温度,热电阻温度计算公式为:T1=1/[ln(Rt / R)/B+1/T2],怎样用C语言表示此公式?

弧度制与角度制的换算公式

怎样用C语言判断一个整数中有没有重复的数

2的n次方用c语言怎么表示