Advanced Question Get Sun intensity under vessel

zachary77

New member
Joined
Aug 31, 2017
Messages
80
Reaction score
1
Points
0
Hi, I'm developing a glider addon for O2016.
I'm wondering if there's a way to get sun angle (and thus intensity) where the craft is, for thermal strength. Currently the thermals are there at night, too :)
Any help would be appreciated.

Thanks,
zachary77
 
Hi,
an aproximate way to do it is:

Get position of Sun relative to Earth.
Get position of Glider relative to earth.
Calculate Angle between the two vectors (dot product).
Intensity is cos(Angle) * Solar Flux
Sun is below horizon if Angle > 90deg.

I think that should work.

EDIT: Dot product gives you the cos(angle) anyway so no need to calculate the angle really :-)
 
I have some very old and very undocumented code lying around that did that for a vessel, bit it's rather messy and rather specific. There's a few generic things I was able to extract from it on the quick that you should be able to use, though.
First, there's this bit that calculates the power of sunlight at the position of the vessel... In Watts per square meters, as far as I can still make that out? At least 3.827e26 is the solar luminosity in Watts, and the rest seems to be the sphere law applied to the vessels distance...

Code:
	vessel->GetGlobalPos(vesselGlobalPos);
	sunDist = length(vesselGlobalPos);
	sunEnergy = 3.827e26 / (4*PI*pow(sunDist,2));

There's also this bit of code to calculate if the vessel is shadowed by its reference body which might come in handy:

Code:
OBJHANDLE gravRef = vessel->GetGravityRef();
	VECTOR3 gravRefPos;
	oapiGetGlobalPos(gravRef, &gravRefPos);
	double gravRefDist = length(gravRefPos);
	if (gravRef == oapiGetGbodyByIndex(0)) {
		// the gravity reference is the sun, ergo no shadow
		return false;
	}

	else if (sunDist < gravRefDist) {
            // the vessel is between the sun and the reference body, ergo no shadow
            return false;
	}

       // trig magic that would take too long right now to understand what I was doing. Especially since I think this bit was written by vchamp originally?
	VECTOR3 perp = crossp(gravRefPos, _V(0, 0, 1));
	perp *= oapiGetSize(gravRef) / length(perp);
	VECTOR3 edgePos = gravRefPos + perp;
	double edgeDist = length(edgePos);
	
	double cosVessel = dotp(gravRefPos, vesselGlobalPos) / (gravRefDist * sunDist);
	double cosEdge = dotp(gravRefPos, edgePos) / (gravRefDist * edgeDist);
	return cosVessel > cosEdge;


But the toughest part of the problem is still calculating at what angle the sun is hitting the surface of your vessel. That depends on your vessels geometry, so I don't have a generic solution for that...
 
I'm wondering if there's a way to get sun angle (and thus intensity) where the craft is, for thermal strength.

To the accuracy solar flux is a proxy for thermal strength, simply taking the local time would suffice.

Otherwise you can compute the sun angle from local time, solar declination, latitude and longitude - here's a code snippet from my worldbuilder code

Code:
double Surface::solar_elevation_angle_sin (double solar_declination, double day_fraction)
{
double sin_Psi = sin(lat) * sin(solar_declination) - cos(lat) * cos(solar_declination) * cos(2.0 * pi * day_fraction - lon);
if (sin_Psi < 0) {return 0.0;} else {return sin_Psi;}
}

Note however that the convective potential in reality is not a function of the solar flux intensity but of the time history of it - and of the current temperature profile of the atmosphere. Here local elevation, slope, surface albedo and surface thermal inertia of the ground figure much more prominently than the sun angle.
 
Thanks for all your help. I'm going to try them out now.

---------- Post added at 12:54 PM ---------- Previous post was at 04:46 AM ----------

Well, I’ve tried, but the math is beyond me. Need to do more research...
 
...But the toughest part of the problem is still calculating at what angle the sun is hitting the surface of your vessel...
I think that it is behind zachary's scope.
AFAIK, he needs to know at what angle the Sun hits the ground directly below the glider.
 
Ah... that would be a lot simpler. In that case, just calculate the angle between the suns position and the earths surface you're at (I'd have to look it up too, but it sounds like it shouldn't be too crazy). Then use that angle and the solar constant to calculate the total energy.
 
Back
Top