Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 目标c因为sin返回的结果不同_C#_Ios_Objective C_Math - Fatal编程技术网

C# 目标c因为sin返回的结果不同

C# 目标c因为sin返回的结果不同,c#,ios,objective-c,math,C#,Ios,Objective C,Math,我需要你在操作系统开发方面的帮助。我将C#应用程序转换为Objective-C。iOS返回不同的结果: 在iOS中的结果: gety:-0.000048 标题x:-0.000087 iOS源代码: double rlatitude1 = [self toRadians:startLocation.latitude]; double rlongitude1 = [self toRadians:startLocation.longitude]; double rlatitude2 = [self

我需要你在操作系统开发方面的帮助。我将C#应用程序转换为Objective-C。iOS返回不同的结果:

在iOS中的结果:
gety:-0.000048
标题x:-0.000087

iOS源代码:

double rlatitude1 = [self toRadians:startLocation.latitude];
double rlongitude1 = [self  toRadians:startLocation.longitude];
double rlatitude2 = [self toRadians:endLocation.latitude];
double rlongitude2 = [self toRadians:endLocation.longitude];
double y = sin(rlongitude2- rlongitude1) * cos(rlatitude2);
NSLog([NSString stringWithFormat:@"GetHeading y: %f",y]);

double x = cos(rlatitude1) * sin(rlatitude2) -  sin(rlatitude1) * cos(rlatitude2) * cos(rlongitude2 - rlongitude1);
NSLog([NSString stringWithFormat:@"GetHeading x: %f",x]);
iOS圆环代码:

+(double) toRadians:(double) degree
{
    double retVal = (degree * 0.0174532925);
    NSLog([NSString stringWithFormat:@"toRadians: %f",retVal]);
    return retVal;
}

FYI-不要将
stringWithFormat
NSLog
一起使用,这是多余的。只需执行:
NSLog(@“GetHeading y:%f”,y)
y
的结果相同<代码>-0.000048和
-4.8E-05
是相同的数字。使用断点检查retVal的值,而使用%f打印它可能会将其转换为用于打印的浮点,并将
0.0174532925
替换为
M_PI/180
。将NSLogs中的
%f
替换为
.15e