getSoulAndBody function

SoulAndBody getSoulAndBody(
  1. AstrolabeParams params
)

获取命宫以及身宫数据

  1. 定寅首
  • 甲己年生起丙寅,乙庚年生起戊寅,
  • 丙辛年生起庚寅,丁壬年生起壬寅,
  • 戊癸年生起甲寅。
  1. 安命身宫诀
  • 寅起正月,顺数至生月,逆数生时为命宫。
  • 寅起正月,顺数至生月,顺数生时为身宫。

@param solarDate 公历日期,用公历日期比较方便,因为农历日期需要考虑闰月问题,如果得到的数据是农历,可以用 lunar2solar 方法得到公历日期 @param timeIndex 出生时索引 @param fixLeap 是否修正闰月,若修正,则闰月前15天按上月算,后15天按下月算 @returns SoulAndBody

Implementation

SoulAndBody getSoulAndBody(AstrolabeParams params) {
  final heavenlyStemEarthlyBranch = getHeavenlyStemAndEarthlyBranchSolarDate(
    params.solarDate,
    params.timeIndex,
    getConfig().yearDivide,
  );
  final earthlyBranchOfTime = getMyEarthlyBranchNameFrom(
    heavenlyStemEarthlyBranch.hourly[1],
  );
  final heavenlyStemOfYear = getMyHeavenlyStemNameFrom(
    heavenlyStemEarthlyBranch.yearly[0],
  );

  // 紫薇斗数以寅宫位第一个宫位
  final firstIndex = earthlyBranches.indexOf('yinEarthly');
  final monthIndex = fixLunarMonthIndex(
    params.solarDate,
    params.timeIndex,
    params.fixLeap,
  );

  // 命宫索引,以寅宫为0,顺时针数到生月地支索引,再逆时针数到生时地支索引
  // 此处数到生月地支索引其实就是农历月份,所以不再计算生月地支索引
  var soulIndex = fixIndex(
    monthIndex - earthlyBranches.indexOf(earthlyBranchOfTime.key),
  );
  // 身宫索引,以寅宫为0,顺时针数到生月地支索引,再顺时针数到生时地支索引
  // 与命宫索引一样,不再赘述
  var bodyIndex = fixIndex(
    monthIndex + earthlyBranches.indexOf(earthlyBranchOfTime.key),
  );
  if (params.from?.heavenlyStem != null && params.from?.earthlyBranch != null) {
    soulIndex = fixEarthlyBranchIndex(params.from!.earthlyBranch);
    final bodyOffset = [0, 2, 4, 6, 8, 10, 0, 2, 4, 6, 8, 10, 0];
    bodyIndex = fixIndex(bodyOffset[params.timeIndex] + soulIndex);
  }
  // 用五虎盾取得寅宫的天干
  final startHevenlyStem = tigerRules[heavenlyStemOfYear.key];
  // 获取命宫天干索引,起始天干索引加上命宫的索引即是
  final heavenlyStemOfSoulIndex = fixIndex(
    heavenlyStems.indexOf(startHevenlyStem!) + soulIndex,
    max: 10,
  );
  // 命宫的天干
  final heavenlyStemOfSoul = getMyHeavenlyStemNameFrom(
    heavenlyStems[heavenlyStemOfSoulIndex],
  );

  // 命宫的地支
  final earthlyBranchOfSoul = getMyEarthlyBranchNameFrom(
    earthlyBranches[fixIndex(soulIndex + firstIndex)],
  );

  return SoulAndBody(
    soulIndex: soulIndex,
    bodyIndex: bodyIndex,
    heavenlyStenName: heavenlyStemOfSoul,
    earthlyBranchName: earthlyBranchOfSoul,
  );
}