124 lines
3.4 KiB
PHP
124 lines
3.4 KiB
PHP
<?php
|
|
|
|
require_once 'constants.php';
|
|
|
|
function getPlanetName(string $planetKey, string $mode = NAME_MODE_MODERN): string
|
|
{
|
|
return PLANET_NAMES[$mode][$planetKey] ?? $planetKey;
|
|
}
|
|
|
|
function getPlanetShortName(string $planetKey): string
|
|
{
|
|
return PLANET_SHORT_NAMES[$planetKey] ?? strtoupper(substr($planetKey, 0, 2));
|
|
}
|
|
|
|
function getSignName(string $signKey, string $mode = NAME_MODE_MODERN): string
|
|
{
|
|
return SIGN_NAMES[$mode][$signKey] ?? $signKey;
|
|
}
|
|
|
|
function getNakshatraName(string $nakshatraKey, string $mode = NAME_MODE_MODERN): string
|
|
{
|
|
return NAKSHATRA_NAMES[$mode][$nakshatraKey] ?? $nakshatraKey;
|
|
}
|
|
|
|
function getSignKeyByIndex(int $index): string
|
|
{
|
|
return SIGN_KEYS[$index] ?? SIGN_KEYS[0];
|
|
}
|
|
|
|
function getNakshatraKeyByIndex(int $index): string
|
|
{
|
|
return NAKSHATRA_KEYS[$index] ?? NAKSHATRA_KEYS[0];
|
|
}
|
|
|
|
function formatDegree(float $degree): string
|
|
{
|
|
$deg = floor($degree);
|
|
$minutesFloat = ($degree - $deg) * 60;
|
|
$min = floor($minutesFloat);
|
|
$sec = floor(($minutesFloat - $min) * 60);
|
|
|
|
return $deg . ' deg ' . str_pad((string)$min, 2, '0', STR_PAD_LEFT) . "' " .
|
|
str_pad((string)$sec, 2, '0', STR_PAD_LEFT) . '"';
|
|
}
|
|
|
|
function normalizeLongitude(float $longitude): float
|
|
{
|
|
$result = fmod($longitude, 360);
|
|
if ($result < 0) {
|
|
$result += 360;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
function getSignIndexFromLongitude(float $longitude): int
|
|
{
|
|
$longitude = normalizeLongitude($longitude);
|
|
return (int) floor($longitude / 30);
|
|
}
|
|
|
|
function getSignKeyFromLongitude(float $longitude): string
|
|
{
|
|
$signIndex = getSignIndexFromLongitude($longitude);
|
|
return getSignKeyByIndex($signIndex);
|
|
}
|
|
|
|
function getDegreeWithinSign(float $longitude): float
|
|
{
|
|
$longitude = normalizeLongitude($longitude);
|
|
return fmod($longitude, 30);
|
|
}
|
|
|
|
function getNakshatraIndexFromLongitude(float $longitude): int
|
|
{
|
|
$longitude = normalizeLongitude($longitude);
|
|
$nakshatraSize = 360 / 27;
|
|
return (int) floor($longitude / $nakshatraSize);
|
|
}
|
|
|
|
function getNakshatraKeyFromLongitude(float $longitude): string
|
|
{
|
|
$nakshatraIndex = getNakshatraIndexFromLongitude($longitude);
|
|
return getNakshatraKeyByIndex($nakshatraIndex);
|
|
}
|
|
|
|
function buildPlanetDataFromLongitude(
|
|
string $planetKey,
|
|
float $longitude,
|
|
string $mode = NAME_MODE_MODERN
|
|
): array {
|
|
$normalizedLongitude = normalizeLongitude($longitude);
|
|
$signKey = getSignKeyFromLongitude($normalizedLongitude);
|
|
$nakshatraKey = getNakshatraKeyFromLongitude($normalizedLongitude);
|
|
$degreeWithinSign = getDegreeWithinSign($normalizedLongitude);
|
|
$segment = getSegmentFromLongitude($normalizedLongitude);
|
|
|
|
return [
|
|
'key' => $planetKey,
|
|
'name' => getPlanetName($planetKey, $mode),
|
|
'short' => getPlanetShortName($planetKey),
|
|
'house' => $segment,
|
|
'longitude' => $normalizedLongitude,
|
|
'sign_key' => $signKey,
|
|
'sign' => getSignName($signKey, $mode),
|
|
'degree_value' => $degreeWithinSign,
|
|
'degree' => formatDegree($degreeWithinSign),
|
|
'nakshatra_key' => $nakshatraKey,
|
|
'nakshatra' => getNakshatraName($nakshatraKey, $mode)
|
|
];
|
|
}
|
|
|
|
function sortPlanetsByLongitude(array $planets): array
|
|
{
|
|
usort($planets, function ($a, $b) {
|
|
return ($a['longitude'] ?? 0) <=> ($b['longitude'] ?? 0);
|
|
});
|
|
|
|
return $planets;
|
|
}
|
|
function getSegmentFromLongitude(float $longitude): int
|
|
{
|
|
$longitude = normalizeLongitude($longitude);
|
|
return ((int) floor($longitude / 30)) + 1;
|
|
} |