Skip to content

Commit

Permalink
#2 Adding all solar system planets
Browse files Browse the repository at this point in the history
WIP: The calculations seem to be retrieving a different value than expected when using my own test data. A closer look is required in the formula to detect where the problem could be
  • Loading branch information
gabcvit committed Feb 25, 2025
1 parent bdc3a86 commit e351856
Show file tree
Hide file tree
Showing 13 changed files with 737 additions and 17 deletions.
77 changes: 77 additions & 0 deletions src/hooks/useBirthChartCalculator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Sun } from '../utils/classes/Sun';
import { Mars } from '../utils/classes/Mars';
import { Mercury } from '../utils/classes/Mercury';
import { Moon } from '../utils/classes/Moon';
import { Venus } from '../utils/classes/Venus';
import { Jupiter } from '../utils/classes/Jupiter';
import { Saturn } from '../utils/classes/Saturn';
import { Uranus } from '../utils/classes/Uranus';
import { Neptune } from '../utils/classes/Neptune';
import { Pluto } from '../utils/classes/Pluto';

export default function useBirthChartCalculator(
date: string,
Expand Down Expand Up @@ -34,11 +41,81 @@ export default function useBirthChartCalculator(
};
};

const calculateVenusSign = () => {
const venus = new Venus(date, time, timeZone);

return {
sign: venus.getZodiacSign(),
longitude: Math.round(venus.getGeocentricLongitude())
};
};

const calculateMarsSign = () => {
const mars = new Mars(date, time, timeZone);

return {
sign: mars.getZodiacSign(),
longitude: Math.round(mars.getGeocentricLongitude())
};
};

const calculateJupiterSign = () => {
const jupiter = new Jupiter(date, time, timeZone);

return {
sign: jupiter.getZodiacSign(),
longitude: Math.round(jupiter.getGeocentricLongitude())
};
};

const calculateSaturnSign = () => {
const saturn = new Saturn(date, time, timeZone);

return {
sign: saturn.getZodiacSign(),
longitude: Math.round(saturn.getGeocentricLongitude())
};
};

const calculateUranusSign = () => {
const uranus = new Uranus(date, time, timeZone);

return {
sign: uranus.getZodiacSign(),
longitude: Math.round(uranus.getGeocentricLongitude())
};
};

const calculateNeptuneSign = () => {
const neptune = new Neptune(date, time, timeZone);

return {
sign: neptune.getZodiacSign(),
longitude: Math.round(neptune.getGeocentricLongitude())
};
};

const calculatePlutoSign = () => {
const pluto = new Pluto(date, time, timeZone);

return {
sign: pluto.getZodiacSign(),
longitude: Math.round(pluto.getGeocentricLongitude())
};
};

const calculate = () => {
return {
sun: calculateSunSign(),
moon: calculateMoonSign(),
mercury: calculateMercurySign(),
venus: calculateVenusSign(),
mars: calculateMarsSign(),
jupiter: calculateJupiterSign(),
saturn: calculateSaturnSign(),
uranus: calculateUranusSign(),
neptune: calculateNeptuneSign(),
pluto: calculatePlutoSign(),
};
}

Expand Down
5 changes: 2 additions & 3 deletions src/utils/classes/Earth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { simplifyAngle } from '../helpers';
import { CelestialBody } from './CelestialBody';

export class Earth extends CelestialBody {
Expand All @@ -7,7 +6,7 @@ export class Earth extends CelestialBody {

constructor(date: string, time: string, timeZone: string) {
super(date, time, timeZone);
this.calculateHeliocentricPosition();
this.calculateHeliocentricLongitude();
}

getHeliocentricDistance() {
Expand All @@ -18,7 +17,7 @@ export class Earth extends CelestialBody {
return this.heliocentricLongitude;
}

calculateHeliocentricPosition() {
calculateHeliocentricLongitude() {
const daysFromEpoch = this.julianDate - 2451545.0;

const meanAnomaly = 357.52911 + 35999.05029 * daysFromEpoch;
Expand Down
89 changes: 89 additions & 0 deletions src/utils/classes/Jupiter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { simplifyAngle, radToDeg } from '../helpers';
import { CelestialBody } from './CelestialBody';
import { Earth } from './Earth';

export class Jupiter extends CelestialBody {
private heliocentricDistance: number = 0;
private heliocentricLongitude: number = 0;

constructor(date: string, time: string, timeZone: string) {
super(date, time, timeZone);
this.calculateHeliocentricLongitude();
this.calculateGeocentricLongitude();
}

getHeliocentricDistance() {
return this.heliocentricDistance;
}

getHeliocentricLongitude() {
return this.heliocentricLongitude;
}

getGeocentricLongitude() {
return this.geocentricLongitude;
}

calculateHeliocentricLongitude() {
const daysFromEpoch = this.julianDate - 2451545.0;

// Eccentricity (e)
const eccentricity = 0.048498 + 4.469E-9 * daysFromEpoch;

// Semi-Major Axis (a)
const semiMajorAxis = 5.20256

// Argument of Perihelion (w)
const argumentOfPerihelion = 273.8777 + 1.64505E-5 * daysFromEpoch;

// Longitude of Ascending Node (O)
const longitudeOfAscendingNode = 100.464441 + 0.176682 * daysFromEpoch;

// Perihelion (q)
const longitudeOfPerihelion = argumentOfPerihelion + longitudeOfAscendingNode;

// Mean longitude (L)
const a0 = 238.049257;
const a1 = 3036.301986;
const a2 = 0.0003347;
const a3 = 0.00000165;
const meanLongitude = a0 + (a1 * daysFromEpoch) + (a2 * Math.pow(daysFromEpoch, 2)) + (a3 * Math.pow(daysFromEpoch, 3));

// Mean anomaly (M)
const meanAnomaly = meanLongitude - longitudeOfPerihelion;

// Kepler's Equation for Eccentric Anomaly
let eccentricAnomaly = meanAnomaly; // Initial guess
for (let i = 0; i < 10; i++) {
eccentricAnomaly = meanAnomaly + eccentricity * Math.sin(eccentricAnomaly);
}

// True Anomaly
const trueAnomaly = 2 * Math.atan(Math.sqrt((1 + eccentricity) / (1 - eccentricity)) * Math.tan(eccentricAnomaly / 2));

this.heliocentricDistance = semiMajorAxis * (1 - eccentricity * Math.cos(eccentricAnomaly));
this.heliocentricLongitude = trueAnomaly + longitudeOfPerihelion;
}

calculateGeocentricLongitude() {
const earth = new Earth(this.date, this.time, this.timeZone)

const earthCartesianAngles = {
x: earth.getHeliocentricDistance() * Math.cos(earth.getHeliocentricLongitude()),
y: earth.getHeliocentricDistance() * Math.sin(earth.getHeliocentricLongitude()),
}

const selfCartesianAngles = {
x: this.heliocentricDistance * Math.cos(this.heliocentricLongitude),
y: this.heliocentricDistance * Math.sin(this.heliocentricLongitude),
}

const relativeCartesianAngles = {
x: selfCartesianAngles.x - earthCartesianAngles.x,
y: selfCartesianAngles.y - earthCartesianAngles.y,
}

const convertedToDegree = radToDeg(Math.atan2(relativeCartesianAngles.y, relativeCartesianAngles.x))
this.geocentricLongitude = simplifyAngle(convertedToDegree);
}
}
88 changes: 88 additions & 0 deletions src/utils/classes/Mars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { simplifyAngle, radToDeg } from '../helpers';
import { CelestialBody } from './CelestialBody';
import { Earth } from './Earth';

export class Mars extends CelestialBody {
private heliocentricDistance: number = 0;
private heliocentricLongitude: number = 0;

constructor(date: string, time: string, timeZone: string) {
super(date, time, timeZone);
this.calculateHeliocentricLongitude();
this.calculateGeocentricLongitude();
}

getHeliocentricDistance() {
return this.heliocentricDistance;
}

getHeliocentricLongitude() {
return this.heliocentricLongitude;
}

getGeocentricLongitude() {
return this.geocentricLongitude;
}

calculateHeliocentricLongitude() {
const daysFromEpoch = this.julianDate - 2451545.0;

// Eccentricity (e)
const eccentricity = 0.093405 + 2.516E-9 * daysFromEpoch;

// Semi-Major Axis (a)
const semiMajorAxis = 1.523688

// Argument of Perihelion (w)
const argumentOfPerihelion = 286.5016 + 2.92961E-5 * daysFromEpoch;

// Longitude of Ascending Node (O)
const longitudeOfAscendingNode = 49.558093 - 0.29257343 * daysFromEpoch;

// Perihelion (q)
const longitudeOfPerihelion = argumentOfPerihelion + longitudeOfAscendingNode;

// Mean longitude (L)
const a0 = 293.737334;
const a1 = 19141.69551;
const a2 = 0.0003107;
const meanLongitude = a0 + (a1 * daysFromEpoch) + (a2 * Math.pow(daysFromEpoch, 2));

// Mean anomaly (M)
const meanAnomaly = meanLongitude - longitudeOfPerihelion;

// Kepler's Equation for Eccentric Anomaly
let eccentricAnomaly = meanAnomaly; // Initial guess
for (let i = 0; i < 10; i++) {
eccentricAnomaly = meanAnomaly + eccentricity * Math.sin(eccentricAnomaly);
}

// True Anomaly
const trueAnomaly = 2 * Math.atan(Math.sqrt((1 + eccentricity) / (1 - eccentricity)) * Math.tan(eccentricAnomaly / 2));

this.heliocentricDistance = semiMajorAxis * (1 - eccentricity * Math.cos(eccentricAnomaly));
this.heliocentricLongitude = trueAnomaly + longitudeOfPerihelion;
}

calculateGeocentricLongitude() {
const earth = new Earth(this.date, this.time, this.timeZone)

const earthCartesianAngles = {
x: earth.getHeliocentricDistance() * Math.cos(earth.getHeliocentricLongitude()),
y: earth.getHeliocentricDistance() * Math.sin(earth.getHeliocentricLongitude()),
}

const selfCartesianAngles = {
x: this.heliocentricDistance * Math.cos(this.heliocentricLongitude),
y: this.heliocentricDistance * Math.sin(this.heliocentricLongitude),
}

const relativeCartesianAngles = {
x: selfCartesianAngles.x - earthCartesianAngles.x,
y: selfCartesianAngles.y - earthCartesianAngles.y,
}

const convertedToDegree = radToDeg(Math.atan2(relativeCartesianAngles.y, relativeCartesianAngles.x))
this.geocentricLongitude = simplifyAngle(convertedToDegree);
}
}
10 changes: 5 additions & 5 deletions src/utils/classes/Mercury.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Mercury extends CelestialBody {

constructor(date: string, time: string, timeZone: string) {
super(date, time, timeZone);
this.calculateHeliocentricPosition();
this.calculateHeliocentricLongitude();
this.calculateGeocentricLongitude();
}

Expand All @@ -24,20 +24,20 @@ export class Mercury extends CelestialBody {
return this.geocentricLongitude;
}

calculateHeliocentricPosition() {
calculateHeliocentricLongitude() {
const daysFromEpoch = this.julianDate - 2451545.0;

// Eccentricity (e)
const eccentricity = 0.205630 + 0.00002 * daysFromEpoch;
const eccentricity = 0.205630 + 5.59E-10 * daysFromEpoch;

// Semi-Major Axis (a)
const semiMajorAxis = 0.387098

// Argument of Perihelion (w)
const argumentOfPerihelion = 77.4577 + 0.1594 * daysFromEpoch;
const argumentOfPerihelion = 29.1241 + 1.01444E-5 * daysFromEpoch;

// Longitude of Ascending Node (O)
const longitudeOfAscendingNode = 48.3308 + 0.1258 * daysFromEpoch;
const longitudeOfAscendingNode = 48.33167 - 0.1253408 * daysFromEpoch;

// Perihelion (q)
const longitudeOfPerihelion = argumentOfPerihelion + longitudeOfAscendingNode;
Expand Down
5 changes: 2 additions & 3 deletions src/utils/classes/Moon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { simplifyAngle } from '../helpers';
import { CelestialBody } from './CelestialBody';

export class Moon extends CelestialBody {
private geocentricLongitude: number = 0;

constructor(date: string, time: string, timeZone: string) {
super(date, time, timeZone);
this.calculateLongitude();
this.calculateGeocentricLongitude();
}

getGeocentricLongitude() {
return this.geocentricLongitude;
}

calculateLongitude() {
calculateGeocentricLongitude() {
// Number of days from epoch J2000.0
const daysFromEpoch = this.julianDate - 2451545.0;

Expand Down
Loading

0 comments on commit e351856

Please sign in to comment.