安星模块

按出生数据取某一组星耀的落宫。

不排整盘、只想知道「禄存落在哪一宫」或「这张盘的杂耀怎么分布」时用这一层。

所有索引都是宫位索引:0 为寅宫,11 为丑宫。

StarBirth

按出生数据安星的入口共用这一个参数结构。

type StarBirth struct {
    SolarDate  string
    TimeIndex  uint8
    Gender     string
    FixLeap    bool
    Language   string
    Config     *Config
    FromStem   string
    FromBranch string
}
字段类型说明
SolarDatestring公历日期,格式 YYYY-M-D
TimeIndexuint8时辰索引 0–12
Genderstring性别,决定长生与博士十二神的顺逆
FixLeapbool是否修正闰月
Languagestring星耀名称的输出语言,留空取 zh-CN
Config*Config排盘配置,nil 取默认
FromStem / FromBranchstring起五行局的干支;两者须同时给出
birth := iztro.StarBirth{
    SolarDate: "2000-8-16",
    TimeIndex: 2,
    Gender:    iztro.GenderFemale,
    FixLeap:   true,
}

本页示例统一用默认的 zh-CNLanguage 留空即取它),因此星名输出都是中文。

FromStem / FromBranch 只影响起五行局

两者同时给出后,五行局改由该干支推算,进而改变紫微天府落点与长生十二神。 其余各组星的起法不受影响。用它可以取到中州派地盘、人盘的安星结果。


GetStartIndex

用途 求紫微、天府的起始宫位。

斗数含义 紫微是全盘的锚点:由五行局与农历生日按「起紫微星诀」定位, 其余十三颗主星再依紫微与天府的位置铺开。天府与紫微的位置互为镜像。

签名

func GetStartIndex(birth StarBirth) (StartIndex, error)

返回值 StartIndex{ ZiweiIndex, TianfuIndex int }

示例

s, _ := iztro.GetStartIndex(birth)
fmt.Printf("%+v\n", s)

输出

{ZiweiIndex:4 TianfuIndex:8}

各组落宫索引

以下六个入口形状一致:收 StarBirth,返回一个字段全是宫位索引的结构体。

函数返回类型字段起法依据
GetLuYangTuoMaIndexLuYangTuoMaIndexLuIndex YangIndex TuoIndex MaIndex年干定禄存,禄前羊后陀;天马按年支
GetKuiYueIndexKuiYueIndexKuiIndex YueIndex年干
GetChangQuIndexChangQuIndexChangIndex QuIndex时支
GetKongJieIndexKongJieIndexKongIndex JieIndex时支
GetTimelyStarIndexTimelyStarIndexTaifuIndex FenggaoIndex时支
GetLuanXiIndexLuanXiIndexHongluanIndex TianxiIndex年支

示例

l, _ := iztro.GetLuYangTuoMaIndex(birth)
c, _ := iztro.GetChangQuIndex(birth)
lx, _ := iztro.GetLuanXiIndex(birth)

fmt.Printf("%+v\n%+v %+v\n", l, c, lx)

输出

{LuIndex:6 YangIndex:7 TuoIndex:5 MaIndex:0}
{ChangIndex:6 QuIndex:4} {HongluanIndex:9 TianxiIndex:3}

擎羊在禄存前一格、陀罗在后一格,这是「禄前羊刃当,禄后陀罗府」的直接体现。


GetDailyStarIndex / GetMonthlyStarIndex / GetYearlyStarIndex

用途 取按日、按月、按年起的杂耀落宫。

斗数含义 杂耀按起法分组:日系星从辅星位置起初一顺数到生日; 月系星按农历月份定位;年系星最多,按年干或年支起。

返回值

函数返回类型字段
GetDailyStarIndexDailyStarIndexSantaiIndex BazuoIndex EnguangIndex TianguiIndex
GetMonthlyStarIndexMonthlyStarIndexYuejieIndex TianyaoIndex TianxingIndex YinshaIndex TianyueIndex TianwuIndex
GetYearlyStarIndexYearlyStarIndex27 项:XianchiIndex HuagaiIndex GuchenIndex GuasuIndex TiancaiIndex TianshouIndex TianchuIndex PosuiIndex FeilianIndex LongchiIndex FenggeIndex TiankuIndex TianxuIndex TianguanIndex TianfuIndex TiandeIndex YuedeIndex TiankongIndex JieluIndex KongwangIndex XunkongIndex TianshangIndex TianshiIndex JiekongIndex JieshaAdjIndex NianjieIndex DahaoAdjIndex

示例

d, _ := iztro.GetDailyStarIndex(birth)
m, _ := iztro.GetMonthlyStarIndex(birth)

fmt.Printf("%+v\n%+v\n", d, m)

输出

{SantaiIndex:0 BazuoIndex:10 EnguangIndex:9 TianguiIndex:7}
{YuejieIndex:0 TianyaoIndex:5 TianxingIndex:1 YinshaIndex:0 TianyueIndex:9 TianwuIndex:0}

边界与陷阱


GetMajorStar / GetMinorStar / GetAdjectiveStar

用途 取主星、辅星、杂耀在十二宫的完整分布。

签名

func GetMajorStar(birth StarBirth) ([][]Star, error)
func GetMinorStar(birth StarBirth) ([][]Star, error)
func GetAdjectiveStar(birth StarBirth) ([][]Star, error)

返回值 十二项切片,按宫位索引排列。每项是该宫的 Star 切片(可能为空)。

示例

major, _ := iztro.GetMajorStar(birth)

for i := 0; i < 5; i++ {
    names := []string{}
    for _, s := range major[i] {
        names = append(names, s.Name)
    }
    fmt.Println(i, names)
}

输出

0 [武曲 天相]
1 [太阳 天梁]
2 [七杀]
3 [天机]
4 [紫微]

边界与陷阱

返回的 Star 带亮度与生年四化标记,与整盘排出的完全一致—— 它们走的是同一段代码。要取整盘的话直接用 BySolar 更省事。


GetChangsheng12 / GetBoShi12 / GetYearly12

用途 取四组十二神在十二宫的排列。

斗数含义 这四组各是十二个标记排满十二宫,每宫恰好一个: 长生十二神按五行局起、随性别与年支阴阳定顺逆; 博士十二神从禄存起、同样定顺逆; 岁前十二神从年支起顺行;将前十二神按年支三合组起。

签名

func GetChangsheng12(birth StarBirth) ([]string, error)
func GetBoShi12(birth StarBirth) ([]string, error)
func GetYearly12(birth StarBirth) (Yearly12, error)

返回值 十二项标识切片,按宫位索引排列。 GetYearly12 返回 Yearly12{ Suiqian12, Jiangqian12 []string }

示例

cs, _ := iztro.GetChangsheng12(birth)
bs, _ := iztro.GetBoShi12(birth)
y, _ := iztro.GetYearly12(birth)

fmt.Println(cs[:4])
fmt.Println(bs[:4])
fmt.Println(y.Suiqian12[:4])
fmt.Println(y.Jiangqian12[:4])

输出

[jue mu si bing]
[faylian zhoushu jiangjun xiaohao]
[diaoke bingfu suijian huiqi]
[suiyi xiishen huagai jiesha]

返回的是标识而非译名,要展示用 Translate(key, language)


GetChangsheng12StartIndex / GetJiangqian12StartIndex

用途 只取两组十二神的起始宫位,不排整组。

斗数含义 长生起点由五行局定:水二局长生在申、木三局在亥、金四局在巳、 土五局在申、火六局在寅。将星起点由年支三合组定:寅午戌年在午、申子辰年在子、 巳酉丑年在酉、亥卯未年在卯。

签名

func GetChangsheng12StartIndex(fiveElementsClass string) (int, error)
func GetJiangqian12StartIndex(branchKey string) (int, error)

返回值 int,0–11。这两个函数不需要出生数据。

示例

a, _ := iztro.GetChangsheng12StartIndex(iztro.ClassWater2nd)
b, _ := iztro.GetChangsheng12StartIndex(iztro.ClassFire6th)
c, _ := iztro.GetJiangqian12StartIndex(iztro.BranchZi)
d, _ := iztro.GetJiangqian12StartIndex(iztro.BranchWu)

fmt.Println(a, b, c, d)

输出

6 0 10 4

水二局长生在申(索引 6),火六局在寅(索引 0)。


GetHoroscopeStar

用途 取某个运限层级的流耀分布。

斗数含义 流耀是随运限产生的十颗星:魁钺昌曲禄羊陀马鸾喜。 它们的落宫由该层级的干支决定,名字随层级变化。流年层级额外多一颗年解。

签名

func GetHoroscopeStar(stemKey, branchKey, scope string, language Language) ([][]Star, error)

参数

参数类型必填默认说明
stemKeystring该层级的天干标识
branchKeystring该层级的地支标识
scopestring运限层级,决定星名
languageLanguage盘面语言

返回值 十二项切片,按宫位索引排列。

各层级的星名对照

本命大限流年流月流日流时
天魁运魁流魁月魁日魁时魁
天钺运钺流钺月钺日钺时钺
文昌运昌流昌月昌日昌时昌
文曲运曲流曲月曲日曲时曲
禄存运禄流禄月禄日禄时禄
擎羊运羊流羊月羊日羊时羊
陀罗运陀流陀月陀日陀时陀
天马运马流马月马日马时马
红鸾运鸾流鸾月鸾日鸾时鸾
天喜运喜流喜月喜日喜时喜

标识形如 yunlu(运禄)、liulu(流禄)、yuelu(月禄)、rilu(日禄)、shilu(时禄)。

示例

decadal, _ := iztro.GetHoroscopeStar(iztro.StemJia, iztro.BranchZi, iztro.ScopeDecadal, iztro.LanguageZhCN)

for i := 0; i < 4; i++ {
    names := []string{}
    for _, s := range decadal[i] {
        names = append(names, s.Name)
    }
    fmt.Println(i, names)
}

输出

0 [运禄 运马]
1 [运羊 运鸾]
2 []
3 [运昌]

边界与陷阱

流年层级多一颗年解

ScopeYearly 的结果里额外含年解,按流年地支定位,安放在十颗流耀之前。 其余层级没有这一颗。


低层落宫

上面的函数都从出生数据起算,内部先推出年干支、命宫、修正后的农历月,再落宫。 这一组则直接收那些中间量,自建流程时可以复用。

函数出(字段全为宫位索引 int
GetZuoYouIndex(lunarMonth)修正后的农历月 1–12ZuoYouIndex{ZuoIndex, YouIndex}
GetHuoLingIndex(branchKey, timeIndex)年支、时辰HuoLingIndex{HuoIndex, LingIndex}
GetHuagaiXianchiIndex(branchKey)年支HuagaiXianchiIndex{HuagaiIndex, XianchiIndex}
GetGuGuaIndex(branchKey)年支GuGuaIndex{GuchenIndex, GuasuIndex}
GetJieshaAdjIndex(branchKey)年支int,劫煞宫位索引
GetDahaoIndex(branchKey)年支int,大耗宫位索引
GetNianjieIndex(branchKey)年支int,年解宫位索引
GetTianshiTianshangIndex(gender, branchKey, soulIndex, config)性别、年支、命宫索引TianshiTianshangIndex{TianshangIndex, TianshiIndex}
GetChangQuIndexByHeavenlyStem(stemKey)天干ChangQuIndex{ChangIndex, QuIndex}

示例

chart, _ := iztro.BySolar("2000-8-16", 2, iztro.GenderFemale, true, iztro.LanguageZhCN, nil)
yearBranch := chart.RawDates.ChineseDate.YearlyKeys[1]

hl, _ := iztro.GetHuoLingIndex(yearBranch, 2)
gg, _ := iztro.GetGuGuaIndex(yearBranch)
cq, _ := iztro.GetChangQuIndexByHeavenlyStem(iztro.StemJia)

fmt.Println(hl, gg, cq)

输出

{2 10} {3 11} {3 7}

边界与陷阱

农历月要先修正

GetZuoYouIndex 收的是修正闰月之后的月份,即 FixLunarMonthIndex(...) + 1, 不是农历原始月份。闰月盘直接传原始月份会落错宫。

天伤天使分派别

GetTianshiTianshangIndex 的结果随 config.Algorithm 变:中州派在阴男阳女 (生年地支阴阳与性别阴阳不同)时天伤天使对调,通行派不对调;confignil 取默认。

GetChangQuIndexByHeavenlyStem 按天干起昌曲,用于运限层级的流昌流曲; 本命盘的文昌文曲按时支走 GetChangQuIndex

本页目录