我有一个实例,它根据一年中的哪一天返回地球与太阳的距离。因为它在内部计算今天的日期,所以它是独立的。但我想改变它,所以我将它作为整数传递一年中的某一天。最好的方法是什么?我有什么选择吗?
-(double) calculateDistranceFromSun
{
// Calculate Day of the Year
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
setDayOfYear = dayOfYear;
// Source: curious.astro.cornell.edu/question.php?number=582
double Rad2Deg = Pi/180;
double Theta = (dayOfYear/(DaysInYear/360)*Rad2Deg);
double CC = cos(Theta);
setDistanceFromSun = SemiMajorAxis*(1-pow(Eccentricy,2))/(1+Eccentricy*CC);
return setDistanceFromSun;
}