Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/constant.h"
4
5#include <cmath>
6#include <array>
7#include <chrono>
8#include <ratio>
9
10namespace ph::math
11{
12
13template<typename TimeType, typename UnitType>
14inline auto duration_to_HMS(const std::chrono::duration<TimeType, UnitType>& totalTime)
15-> std::array<TimeType, 3>
16{
17 auto hours = std::chrono::duration_cast<std::chrono::hours>(totalTime);
18 auto minutes = std::chrono::duration_cast<std::chrono::minutes>(totalTime - hours);
19 auto seconds = std::chrono::duration_cast<std::chrono::seconds>(totalTime - hours - minutes);
20
21 return {
22 static_cast<TimeType>(hours.count()),
23 static_cast<TimeType>(minutes.count()),
24 static_cast<TimeType>(seconds.count())};
25}
26
27template<typename TimeType>
28inline auto milliseconds_to_HMS(const TimeType& totalTime)
29-> std::array<TimeType, 3>
30{
31 return duration_to_HMS(std::chrono::duration<TimeType, std::milli>(totalTime));
32}
33
34template<typename TimeType>
35inline auto seconds_to_HMS(const TimeType& totalSeconds)
36-> std::array<TimeType, 3>
37{
38 return duration_to_HMS(std::chrono::duration<TimeType>(totalSeconds));
39}
40
52template<typename T>
54 const T standardTime24H,
55 const T standardMeridianRadians,
56 const T siteLongitudeRadians,
57 const T julianDate)
58{
59 using namespace ph::math::constant;
60
61 const T term1 = static_cast<T>(0.170) * std::sin(four_pi<T> * (julianDate - static_cast<T>(80)) / static_cast<T>(373));
62 const T term2 = static_cast<T>(-0.129) * std::sin(two_pi<T> * (julianDate - static_cast<T>(8)) / static_cast<T>(355));
63 const T term3 = static_cast<T>(12) * (standardMeridianRadians - siteLongitudeRadians) * rcp_pi<T>;
64
65 return standardTime24H + term1 + term2 + term3;
66}
67
68}// end namespace ph::math
Definition constant.h:10
Math functions and utilities.
Definition TransformInfo.h:10
auto seconds_to_HMS(const TimeType &totalSeconds) -> std::array< TimeType, 3 >
Definition time.h:35
T mean_solar_time_to_solar_time_24H(const T standardTime24H, const T standardMeridianRadians, const T siteLongitudeRadians, const T julianDate)
Convert mean solar time to solar time.
Definition time.h:53
auto duration_to_HMS(const std::chrono::duration< TimeType, UnitType > &totalTime) -> std::array< TimeType, 3 >
Definition time.h:14
auto milliseconds_to_HMS(const TimeType &totalTime) -> std::array< TimeType, 3 >
Definition time.h:28