专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > C++ Builder

救命,小弟我晕了,Cos(15)为负数?

发布时间:2011-06-28 13:42:37 文章来源:www.iduyao.cn 采编人员:星星草
救命,我晕了,Cos(15)为负数??
因为需要坐标点定位,用到了三角函数,却发现Cos和Sin都不正常,然后试写出最简单的代码测试这两函数,得出的结果非常古怪,问题出在哪?!

代码如下:(窗体上有一Button1和一个RichEdit1)


#include <vcl.h>
#include <math.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
float CosMe;
String JDStr,CosMeStr,AllStr;
RichEdit1->Lines->Clear();
for(int i = 0;i <= 360;i=i+5){
CosMe = Cos(i);
JDStr = IntToStr(i);
CosMeStr = FloatToStr(CosMe);
AllStr = "角度:"+JDStr+" Cos值为:" + CosMeStr;
RichEdit1->Lines->Add(AllStr);
}
}
//---------------------------------------

*****************************************************************************
运行结果:
角度:0 Cos值为:1
角度:5 Cos值为:0.28366219997406
角度:10 Cos值为:-0.83907151222229
角度:15 Cos值为:-0.759687900543213
角度:20 Cos值为:0.408082067966461
角度:25 Cos值为:0.991202831268311
角度:30 Cos值为:0.154251456260681
角度:35 Cos值为:-0.903692185878754
角度:40 Cos值为:-0.666938066482544
角度:45 Cos值为:0.525321960449219
角度:50 Cos值为:0.964965999126434
角度:55 Cos值为:0.0221267566084862
角度:60 Cos值为:-0.952412962913513
角度:65 Cos值为:-0.562453866004944
角度:70 Cos值为:0.633319199085236
角度:75 Cos值为:0.921751260757446
角度:80 Cos值为:-0.110387243330479
角度:85 Cos值为:-0.984376668930054
角度:90 Cos值为:-0.448073625564575
角度:95 Cos值为:0.730173587799072
角度:100 Cos值为:0.862318873405457
角度:105 Cos值为:-0.240959048271179
角度:110 Cos值为:-0.99902081489563
角度:115 Cos值为:-0.325809806585312
角度:120 Cos值为:0.814180970191956
角度:125 Cos值为:0.787714540958405
角度:130 Cos值为:-0.367291331291199
角度:135 Cos值为:-0.996087849140167
角度:140 Cos值为:-0.19781357049942
角度:145 Cos值为:0.883863389492035
角度:150 Cos值为:0.699250817298889
角度:155 Cos值为:-0.487161338329315
角度:160 Cos值为:-0.975629329681396
角度:165 Cos值为:-0.0663369372487068
角度:170 Cos值为:0.937994778156281
角度:175 Cos值为:0.598484218120575
角度:180 Cos值为:-0.598460078239441
角度:185 Cos值为:-0.938005208969116
角度:190 Cos值为:0.066306859254837
角度:195 Cos值为:0.975622713565826
角度:200 Cos值为:0.487187683582306
角度:205 Cos值为:-0.69922924041748
角度:210 Cos值为:-0.883877456188202
角度:215 Cos值为:0.197784021496773
角度:220 Cos值为:0.996085166931152
角度:225 Cos值为:0.367319375276566
角度:230 Cos值为:-0.787695944309235
角度:235 Cos值为:-0.81419849395752
角度:240 Cos值为:0.325781315565109
角度:245 Cos值为:0.999022126197815
角度:250 Cos值为:0.240988299250603
角度:255 Cos值为:-0.862303614616394
角度:260 Cos值为:-0.73019415140152
角度:265 Cos值为:0.448046654462814
角度:270 Cos值为:0.984381973743439
角度:275 Cos值为:0.110417202115059
角度:280 Cos值为:-0.92173957824707
角度:285 Cos值为:-0.633342504501343
角度:290 Cos值为:0.562428951263428
角度:295 Cos值为:0.952422142028809
角度:300 Cos值为:-0.0220966190099716
角度:305 Cos值为:-0.964958131313324
角度:310 Cos值为:-0.525347650051117
角度:315 Cos值为:0.666915595531464
角度:320 Cos值为:0.90370512008667
角度:325 Cos值为:-0.154221668839455
角度:330 Cos值为:-0.991198837757111
角度:335 Cos值为:-0.408109575510025
角度:340 Cos值为:0.759668290615082
角度:345 Cos值为:0.839087903499603
角度:350 Cos值为:-0.283633291721344
角度:355 Cos值为:-1
角度:360 Cos值为:-0.283691078424454
*****************************************************************************

真叫出鬼了!!!!!


------解决方案--------------------
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: