Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update panchanga.h #27

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions panchanga.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

#include <cmath>
#include <string>
#include <iostream>

#define PI 3.14159265358979323846
#define r2d 180.0 / PI
#define d2r PI / 180.0

// Tithi names in Nepali
static const char tithi[][30] = { "प्रथमा", "द्वितीया", "तृतीया", "चतुर्थी", "पंचमी", "षष्ठी", "सप्तमी", "अष्टमी",
"नवमी", "दशमी", "एकादशी", "द्वादशी", "त्रयोदशी", "चतुर्दशी", "पूर्णिमा", "प्रथमा",
"द्वितीया", "तृतीया", "चतुर्थी", "पंचमी", "षष्ठी", "सप्तमी", "अष्टमी", "नवमी", "दशमी",
"एकादशी", "द्वादशी", "त्रयोदशी", "चतुर्दशी", "अमावस्या" };
"नवमी", "दशमी", "एकादशी", "द्वादशी", "त्रयोदशी", "चतुर्दशी", "पूर्णिमा", "प्रथमा",
"द्वितीया", "तृतीया", "चतुर्थी", "पंचमी", "षष्ठी", "सप्तमी", "अष्टमी", "नवमी", "दशमी",
"एकादशी", "द्वादशी", "त्रयोदशी", "चतुर्दशी", "अमावस्या" };

class Panchang {
public:
double tdays;
double t, tithi_index/*, nakshatra_index, yoga_index*/;
double t, tithi_index;
std::string paksha;


Panchang(double julianDate) {
tdays = julianDate - 2451545.0; // Days since J2000.0
t = tdays / 36525.0;
Expand All @@ -30,27 +31,24 @@ class Panchang {
calculateTithi();
}


private:
void calculateTithi() {
double moon_longitude = getMoonLongitude();
double sun_longitude = getSunLongitude();


double difference = moon_longitude - sun_longitude;
if (difference < 0) difference += 360.0;

tithi_index = std::floor(difference / 12.0);

// Round the tithi index according to the specified rules
tithi_index = std::round(difference / 12.0);
tithi_index = static_cast<int>(tithi_index) % 30; // Wrap around to ensure valid index

paksha = (tithi_index < 15) ? "शुक्ल पक्ष" : "कृष्ण पक्ष";
//debug print
//std::cout << "Tithi: " << tithi[(int)tithi_index] << " (" << paksha << ")" << std::endl;

// Debug print
std::cout << "Tithi: " << tithi[static_cast<int>(tithi_index)] << " (" << paksha << ")" << std::endl;
}




double getSunLongitude() {
double l0 = 280.4665 + 36000.7698 * t;
double m = 357.5291 + 35999.0503 * t;
Expand All @@ -65,17 +63,14 @@ class Panchang {
double getMoonLongitude() {
double L1 = 218.316 + 481267.8813 * t;
double M1 = 134.963 + 477198.8676 * t;
// double F = 93.272 + 483202.0175 * t; the Moon's argument of latitude Not used now

L1 = fmod(L1, 360.0);
M1 = fmod(M1, 360.0);
// F = fmod(F, 360.0); the Moon's argument of latitude Not used now

double longitude = L1 + 6.289 * sin(M1 * d2r);
longitude = fmod(longitude, 360.0);
return longitude;
}

};

double gregorianToJulian(int year, int month, int day);
Expand Down