示例#1
0
/*******************************************************************************
*	NAME:
*		AppSolarCoordinates
*		
*	PURPOSE:
*		Computes the apparent coordinates of the sun
*		
*	REFERENCES;
*		Meeus, Jean. "Astronomical Algorithms, 1st ed." Willmann-Bell. Inc. 1991.
*			pp. 151-153
*			
*	INPUT ARGUMENTS:
*		JD (double)
*			Julian Day for day/time to calculate  at TD
*	
*	OUTPUT ARGUMENTS:
*	 	*alpha (double)
*	 		apparent right ascention in degrees
*	 	*delta (double)
*	 		apparent declination in degrees
*	 
*	RETURNED VALUE:
*	 	none yet
*	 
*	GLOBALS USED:
*	 	none
*	 
*	FUNCTIONS CALLED:
*	 	SinD, CosD, Revolution, atan2
*	 
*	DATE/PROGRAMMER/NOTE:
*	 	09-16-1999	Todd A. Guillory	created
*	 	07-04-2000	Todd A. Guillory	condensed equations some more
*	 	07-27-2000	Todd A. Guillory	checked with example 24.a
*
********************************************************************************/
void app_solar_coordinates( double JD, double *alpha, double *delta)
{
	double	T,		/* Julian Centuries */
			L0,		/* geometric mean longitude of the sun */
			M,		/* mean anomoly */
			e,		/* eccentricity of Earth's orbit */
			C,		/* Sun's equation of center */
			Long,	/* true longitude of the sun */
			v,		/* true anomaly of the sun */
			R,		/* Radius in AU */
			omega,	/* nutation */
			lamda,	/* apparent longitude of the sun */
			ep0;	/* mean obliquity of the ecliptic */

	/* Get Julian Centuries */
	T = julian_centuries(JD);
	
	/* calculate the geometric mean longitude of the sun */
	L0 = 280.46645 + 36000.76983 * T + 0.0003032 * T * T;
	
	/* calculate the mean anomaly of the sun */
	M = 357.52910 + 35999.05030 * T - 0.0001559 * T * T - 0.00000048 * T * T * T;
	
	/* calculate the eccentricity of the Earth's Orbit */
	e = 0.016708617 - 0.000042037 * T - 0.0000001236 * T * T;
	
	/* calculate the sun's equation of center */
	C = (1.914600 - 0.004817 * T - 0.000014 * T * T) * SinD(M)
		+ (0.019993 - 0.000101 * T) * SinD(2*M)
		+ 0.000290 * SinD(3*M);
	
	/* calculate the sun's true longitude */	
	Long = L0 + C;
	
	/* calculate the true anomaly */
	v = M + C;
	
	/* calculate the sun's radius vector, distance of the earth in AUs */
	R = (1.000001018 * ( 1 - e * e)) / ( 1 + e * CosD(v) );
	
	omega = 125.04 - 1934.136 * T;
	
	/* calculate the apparent longitude of the sun */
	lamda = Revolution(Long - 0.00569 - 0.00478 * SinD(omega));
	
	/* calculate the mean obliquity of the ecliptic */
	ep0 = ((23*60)+26)*60+21.448 - 46.8150 * T - 0.00059 * T * T + 0.001813 * T * T * T;
	ep0 /= 3600;
	
	/* correct mean obliquity of the ecliptic */
	ep0 = ep0 + 0.00256 * CosD(omega);

	/* calculate right ascension and declination */
	*alpha = Revolution(atan2(CosD(ep0) * SinD(lamda), CosD(lamda)) * kRadDeg);
	*delta = asin(SinD(ep0) * SinD(lamda)) * kRadDeg;
}
示例#2
0
void Rotate3D(int m, float Theta, Matx4x4 A)
{
  int   m1,m2;
  float c,s;

  ZeroMatrix(A);
  A[m-1][m-1]=1.0;
  A[3][3]=1.0;
  m1=(m % 3)+1;
  m2=(m1 % 3);
  m1-=1;
  c=CosD(Theta);
  s=SinD(Theta);
  A[m1][m1]=c;
  A[m1][m2]=s;
  A[m2][m2]=c;
  A[m2][m1]=-s;
}
示例#3
0
FRotator ATimeManager::CalculateSunAngle()
{
    if (!bIsCalendarInitialized)
    {
        return FRotator();
    }

    DayOfYear = InternalTime.GetDayOfYear() - 1;
    LSTM -= bAllowDaylightSavings && bDaylightSavingsActive ? 1 : 0;
    double lct = InternalTime.GetTimeOfDay().GetTotalHours();

    double eotBase = (DayOfYear - 81) * (360.0 / 365.242);
    double eot = (9.87 * SinD(eotBase * 2)) - (7.53 * CosD(eotBase)) - (1.5 * SinD(eotBase));

    double tcf = ((Longitude - LSTM) * 4) + eot;
    double solTime = lct + (tcf / 60);

    double hra = (solTime - 12) * 15;
    double decl = 23.452294 * SinD((360.0 / 365.242) * (DayOfYear - 81));

    double lat = (double)Latitude;
    double saa = ASinD((SinD(decl) * SinD(lat)) + (CosD(decl) * CosD(lat) * CosD(hra)));
    double saz = ACosD(((SinD(decl) * CosD(lat)) - (CosD(decl) * SinD(lat) * CosD(hra))) / CosD(saa));

    if (hra >= 0.0)
    {
        saz = saz * -1;
    }

    // TEMPORARY - For debug only
    LocalClockTime = (float)lct;
    EoT = (float)eot;
    TimeCorrection = (float)tcf;
    SolarTime = (float)solTime;
    SolarHRA = (float)hra;
    SolarDeclination = (float)decl;
    SolarAltAngle = (float)saa;
    SolarAzimuth = (float)saz;

    return FRotator(SolarAltAngle - 180, SolarAzimuth, 0);
}
示例#4
0
bool CircleConeIntersect(const Circle * c, const Cone * cone)
{
	Circle circle(cone->GetVertex(), cone->GetHeight());
	if (Intersect(c, &circle) == true)
	{
		if ((c->ContainsPoint(cone->GetVertex()) == true) || (cone->ContainsPoint(c->GetCenter()) == true))
		{
			return true;
		}


		Vector3D direction(cone->GetVertex(), cone->GetVertex() + cone->GetDirection());
		Vector3D centerDirection(cone->GetVertex(), c->GetCenter());
		Float angle = direction.GetZeroAngleD();
		Float angleDif = centerDirection.GetZeroAngleD() - angle;

		if (AbsVal(angleDif) < cone->GetAngle())
		{
			return true;
		}

		Float angle1 = angle + cone->GetAngle();
		Float angle2 = angle - cone->GetAngle();

		Float height = cone->GetHeight();
		Point3D vertex = cone->GetVertex();

		LineSegment line1(vertex, Point3D(vertex.GetX() + (CosD(angle1) * height), vertex.GetY() + (SinD(angle1) * height), 0));
		LineSegment line2(vertex, Point3D(vertex.GetX() + (CosD(angle2) * height), vertex.GetY() + (SinD(angle2) * height), 0));

		return ((Intersect(c, &line1) == true) || (Intersect(c, &line2) == true));
	}
	return false;
}
示例#5
0
bool RectConeIntersect(const Rect * rect, const Cone * cone)
{
	Circle circle(cone->GetVertex(), cone->GetHeight());
	if (Intersect(rect, &circle) == true)
	{
		Point2D corners[4] = 
		{
			Point2D(rect->GetLeft(),	rect->GetTop()),
			Point2D(rect->GetLeft(),	rect->GetBottom()),
			Point2D(rect->GetRight(),	rect->GetBottom()),
			Point2D(rect->GetRight(),	rect->GetTop()),
		};

		if (rect->ContainsPoint(cone->GetVertex()) == true)
		{
			return true;
		}
		for (uint8 i = 0; i < 4; i++)
		{
			if (cone->ContainsPoint(corners[i]) == true)
			{
				return true;
			}
		}

		Vector3D direction(cone->GetVertex(), cone->GetVertex() + cone->GetDirection());
		Float angle = direction.GetZeroAngleD();

		Float angle1 = angle + cone->GetAngle();
		Float angle2 = angle - cone->GetAngle();

		Float height = cone->GetHeight();
		Point3D vertex = cone->GetVertex();

		LineSegment line1(vertex, Point3D(vertex.GetX() + (CosD(angle1) * height), vertex.GetY() + (SinD(angle1) * height), 0));
		LineSegment line2(vertex, Point3D(vertex.GetX() + (CosD(angle2) * height), vertex.GetY() + (SinD(angle2) * height), 0));

		return ((Intersect(rect, &line1) == true) || (Intersect(rect, &line2) == true));
	}
	return false;
}
示例#6
0
bool LineSegConeIntersect(const LineSegment * line, const Cone * cone)
{
	Circle circle(cone->GetVertex(), cone->GetHeight());
	if (Intersect(line, &circle) == true)
	{
		if ((cone->ContainsPoint(line->GetPoint1()) == true) || (cone->ContainsPoint(line->GetPoint2()) == true) || (line->ContainsPoint(cone->GetVertex()) == true))
		{
			return true;
		}

		Vector3D direction(cone->GetVertex(), cone->GetVertex() + cone->GetDirection());
		Float angle = direction.GetZeroAngleD();

		Float angle1 = angle + cone->GetAngle();
		Float angle2 = angle - cone->GetAngle();

		Float height = cone->GetHeight();
		Point3D vertex = cone->GetVertex();

		LineSegment line1(vertex, Point3D(vertex.GetX() + (CosD(angle1) * height), vertex.GetY() + (SinD(angle1) * height), 0));
		LineSegment line2(vertex, Point3D(vertex.GetX() + (CosD(angle2) * height), vertex.GetY() + (SinD(angle2) * height), 0));

		return ((Intersect(line, &line1) == true) || (Intersect(line, &line2) == true));
	}
	return false;
}
示例#7
0
FRotator ATimeManager::CalculateMoonAngle()
{
    if (!bIsCalendarInitialized)
    {
        return FRotator();
    }

    double lct = InternalTime.GetTimeOfDay().GetTotalHours();
    double elapsed = InternalTime.GetJulianDay() - JD2000;
    double utc;

    if ((lct + SpanUTC.GetHours()) > 24.0)
    {
        utc = (lct + SpanUTC.GetHours()) - 24.0;
        elapsed++;
    }
    else
    {
        utc = lct + SpanUTC.GetHours();
    }

    elapsed += (utc / 24.0);

    // Approximations for Mean Ecliptic Longitude (L), Mean Anomaly (M), and Mean Distance (F)
    // c0 + c1 are charted values * (d - d0) which is the value of elapsed (days since JD2000 - JD2000)
    // values are modulated to 360, we only care about the remainder, container doubles can be discarded
    // The approximations for years 1950 to 2050 provide accuracy of:
    // ~ 2.57deg total deviation on Ecliptic Longitude (standard deviation 1.04deg)
    // ~ 0.81deg total deviation on Ecliptic Latitude (standard deviation 0.31deg)
    // ~ 7645km total deviation on Ecliptic Longitude (standard deviation 3388km)
    double partL = fmod(218.316 + (13.176396 * elapsed), 360.0);
    double partM = fmod(134.963 + (13.064993 * elapsed), 360.0);
    double partF = fmod(93.272 + (13.229350 * elapsed), 360.0);

    // Using the above approximations, calculate the Geocentric Ecliptic Coordinates (lambda, beta, large delta)
    double ecLong = partL + (6.289 * SinD(partM));
    double ecLat = 5.128 * SinD(partF);
    double ecDist = 385001 - (20905 * CosD(partM));

    // Convert to Observer->Sky coordinates (delta Declination, alpha Right Ascension) from Ecliptic Coordinates
    // ecLatitude, ecLongitude, and the obliquity of the ecliptic (epsilon 23.4397)
    double lunarDec = ASinD((SinD(ecLat) * CosD(EcObliquity)) + (CosD(ecLat) * SinD(EcObliquity) * SinD(ecLong)));
    double lunarRA = ATan2D((SinD(ecLong) * CosD(EcObliquity)) - (TanD(ecLat) * SinD(EcObliquity)), CosD(ecLong));

    // Calculate Sidereal time (theta) and the Hour Angle (tau)
    double lunarST = fmod((357.009 + 102.937) + (15 * (utc)) - Longitude, 360.0);
    double lunarHRA = lunarST - lunarRA;

    double lat = (double)Latitude;
    double lunarAA = ASinD((SinD(lat) * SinD(lunarDec)) + (CosD(lat) * CosD(lunarDec) * CosD(lunarHRA)));
    double lunarAz = ATan2D(SinD(lunarHRA), ((CosD(lunarHRA) * SinD(lat)) - (TanD(lunarDec) * CosD(lat))));

    lunarAA = lunarAA * -1;


    //for debug only:
    PartL = (float)partL;
    PartM = (float)partM;
    PartF = (float)partF;
    EcLongitude = (float)ecLong;
    EcLatitude = (float)ecLat;
    EcDistance = (float)ecDist;

    LunarElapsedDays = (float)elapsed;
    LocalClockTime = (float)lct;
    LunarAltAngle = (float)lunarAA;
    LunarAzimuth = (float)lunarAz;


    return FRotator(LunarAltAngle, LunarAzimuth, 0);
}
示例#8
0
Float RotateGameObject(Script * script)
{
	if (script->VerifyArguments(3) == true)
	{
		Word * rotatePosWord = script->GetNextWord();
		Point2D rotatePosition(0, 0);
		Point2D * rotatePos = (Point2D *)(uint32)rotatePosWord->value;
		if (rotatePos != NULL)
		{
			rotatePosition.SetValues(rotatePos->GetX(), rotatePos->GetY());
		}

		Word * angleWord = script->GetNextWord();

		Word * directionWord = script->GetNextWord();
		Vector3D direction(0, 0, 0);
		Point2D * dirVector = (Point2D *)(uint32)directionWord->value;
		if (dirVector != NULL)
		{
			direction.SetValues(dirVector->GetX(), dirVector->GetY(), 0);
		}

		GameObject * source = (GameObject *)script->GetSource();
		Shape * shape = source->GetShape();
		
		if ((rotatePos != NULL) && (source != NULL) && (source->CheckType(OBJ_TYPE_GAME_OBJECT) == true) && (shape != NULL))
		{
			Float distance = CalculateDistance(rotatePosition, source->GetPosition());
			if (angleWord->value != NULL)
			{
				Vector3D sourceDirection(rotatePosition, source->GetPosition());
				Float angle = sourceDirection.GetZeroAngleD() + angleWord->value;
				
				source->SetPosition(rotatePosition.GetX() + (distance * CosD(angle)),
									rotatePosition.GetY() + (distance * SinD(angle)));

				direction.SetValues(rotatePosition, source->GetPosition());
				direction.SetUnitVector();
			}
			else if (dirVector != NULL)
			{
				direction -= rotatePosition;
				direction.SetUnitVector();

				source->SetPosition(rotatePosition.GetX() + (direction.GetX() * distance),
									rotatePosition.GetY() + (direction.GetY() * distance));
			}
			else
			{
				return false;
			}

			if ((shape->GetType() == SHAPE_TYPE_LINE) || (shape->GetType() == SHAPE_TYPE_LINE_SEGMENT))
			{
				Line * line = (Line *)shape;
				Line * newLine = (Line *)line->CreateInstance();
				newLine->Translate(source->GetPosition());	

				Vector3D v1(rotatePosition, newLine->GetPoint1());
				Vector3D v2(rotatePosition, newLine->GetPoint2());

				Float baseAngle = direction.GetZeroAngleD();

				Float v1Length = v1.GetLength();
				Float v2Length = v2.GetLength();
				Float angle1 = v1.GetZeroAngleD() - baseAngle;
				Float angle2 = v2.GetZeroAngleD() - baseAngle;

				Point2D p1((v1Length * CosD(angle1)),
						   (v1Length * SinD(angle1)));
				Point2D p2((v2Length * CosD(angle2)),
						   (v2Length * SinD(angle2)));

				line->SetValues(p1 + rotatePosition, p2 + rotatePosition);

				line->Translate(!source->GetPosition());

				delete newLine;
			}
			else if (shape->GetType() == SHAPE_TYPE_CONE)
			{
				Cone * cone = (Cone *)shape;
				cone->SetValues(cone->GetVertex(), Vector3D(dirVector->GetX(), dirVector->GetY(), 0), cone->GetHeight(), cone->GetAngle());
			}
			return true;
		}
	}
	return false;
}