Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
location.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TVector2.h"
4#include "Math/constant.h"
5#include "Math/time.h"
6
7#include <cmath>
8
9namespace ph::math
10{
11
22template<typename T>
24 const T solarTime24H,
25 const T julianDate,
26 const T siteLatitudeRadians)
27{
28 using namespace ph::math::constant;
29
30 // Approximated solar declination in radians
31 const T delta =
32 static_cast<T>(0.4093) * std::sin(two_pi<T> * (julianDate - static_cast<T>(81)) / static_cast<T>(368));
33
34 const T sinDelta = std::sin(delta);
35 const T cosDelta = std::cos(delta);
36 const T sinLatitude = std::sin(siteLatitudeRadians);
37 const T cosLatitude = std::cos(siteLatitudeRadians);
38
39 const T angleTerm = pi<T> * solarTime24H / static_cast<T>(12);
40 const T sinAngleTerm = std::sin(angleTerm);
41 const T cosAngleTerm = std::cos(angleTerm);
42
43 const T sunPhiPreetham = std::atan((-cosDelta * sinAngleTerm) / (cosLatitude * sinDelta - sinLatitude * cosDelta * cosAngleTerm));
44 const T sunTheta = pi<T> / static_cast<T>(2) - std::asin(sinLatitude * sinDelta - cosLatitude * cosDelta * cosAngleTerm);
45
46 // Note that <sunPhiPreetham> here has (CW order)
47 // 0 = south, pi/2 = west, pi = north and -pi/2 = east;
48 // convert it to engine order here.
49 T sunPhi = -sunPhiPreetham + static_cast<T>(3 / 2) * pi<T>;
50 sunPhi = sunPhi > two_pi<T> ? sunPhi - two_pi<T> : sunPhi;
51
52 return {sunPhi, sunTheta};
53}
54
55}// end namespace ph::math
Represents a 2-D vector.
Definition TVector2.h:19
Definition constant.h:10
Math functions and utilities.
Definition TransformInfo.h:10
TVector2< T > sun_sky_phi_theta(const T solarTime24H, const T julianDate, const T siteLatitudeRadians)
Locate spherical coordinates of the sun in sky.
Definition location.h:23