5D Library › 玄空飞星置换代数、二十四山罗盘离散化与骨相比例计量 · English

第三章 二十四山的离散化与罗盘误差

一个连续的角度,一个离散的山

罗盘把 360 度分成二十四山,每山 15 度,三山为一卦(45 度)。真实的朝向是一个连续的角度,而排盘需要的是一个离散的山名。这一离散化使排盘对读数误差非常敏感:读数稍有偏差,就可能跨山(读成相邻的山)、出卦(读成相邻的宫)、改变盘面,或改变是否「兼向」(离交界 3 度以内,替卦适用的范围)与是否「空亡」(离交界 1.5 度以内)的判断。

程序设真实朝向在圆周上均匀分布,读数误差服从标准差为 σ\sigma 的正态分布,在 0.1 度的网格上精确积分。

推导

# Chapter 3. p05: Compass error and how often the chart changes.
# Twenty-four mountains of 15 degrees; ren is centred on 345 degrees.
# A true facing direction, uniform around the circle, is read with a
# normal error of standard deviation sigma (2 to 5 degrees covers
# a careful reading near steel, concrete and wiring). We report the
# probability that the reading
#   names a different mountain (kua shan);
#   names a different palace, that is trigram (chu gua);
#   changes the chart of period 9 (both side charts compared);
#   changes the "near an edge" status, within 3 degrees of a mountain
#     boundary (jian xiang, where replacement charts are used);
#   changes the "void" status, within 1.5 degrees of a boundary
#     (kong wang).
# Integration on a 0.1 degree grid of true angles and an 81-point grid
# of errors from -4 to +4 sigma.
import math

LOSHU = {"SE": 4, "S": 9, "SW": 2, "E": 3, "C": 5, "W": 7,
         "NE": 8, "N": 1, "NW": 6}
PALACE_OF = {v: k for k, v in LOSHU.items()}
PATH = ["C", "NW", "W", "NE", "S", "N", "SW", "E", "SE"]
OPP = {"N": "S", "S": "N", "E": "W", "W": "E", "NE": "SW", "SW": "NE",
       "NW": "SE", "SE": "NW"}
PAL_ORDER = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
MOUNTAINS = ("ren zi gui chou gen yin jia mao yi chen xun si bing wu "
             "ding wei kun shen geng you xin xu qian hai").split()

def norm(x):
    return (x - 1) % 9 + 1

def fly(c, sign):
    return {p: norm(c + sign * k) for k, p in enumerate(PATH)}

def polarity(number, pos):
    cardinal = number in (1, 3, 7, 9)
    return (1, -1, -1)[pos] if cardinal else (-1, 1, 1)[pos]

def side(base, pal, pos):
    n = base[pal]
    ref = LOSHU[pal] if n == 5 else n
    return fly(n, polarity(ref, pos))

def chart(period, i):
    base = fly(period, 1)
    sit = PAL_ORDER[i // 3]
    face = OPP[sit]
    return base, side(base, sit, i % 3), side(base, face, i % 3), sit, face

def category(period, i):
    base, m, f, sit, face = chart(period, i)
    if m[sit] == period and f[face] == period:
        return "wang shan wang xiang"
    if m[face] == period and f[sit] == period:
        return "shang shan xia shui"
    if m[face] == period and f[face] == period:
        return "shuang xing hui xiang"
    return "shuang xing hui zuo"

def m_index(deg):
    return int(((deg - 337.5) % 360) // 15)

def edge_dist(deg):
    x = (deg - 337.5) % 15
    return min(x, 15 - x)

CHARTS = [chart(9, i)[1:3] for i in range(24)]

def rates(sigma):
    errs = [-4 * sigma + 0.1 * sigma * k for k in range(81)]
    w = [math.exp(-0.5 * (e / sigma) ** 2) for e in errs]
    sw = sum(w)
    tot = [0.0] * 5
    n = 0
    for t10 in range(3600):
        t = t10 / 10 + 0.05
        mi, ed = m_index(t), edge_dist(t)
        for e, wt in zip(errs, w):
            r = t + e
            mj, er = m_index(r), edge_dist(r)
            tot[0] += wt * (mi != mj)
            tot[1] += wt * (mi // 3 != mj // 3)
            tot[2] += wt * (CHARTS[mi] != CHARTS[mj])
            tot[3] += wt * ((ed < 3) != (er < 3))
            tot[4] += wt * ((ed < 1.5) != (er < 1.5))
        n += 1
    return [x / (sw * n) for x in tot]

if __name__ == "__main__":
    print("   sigma   mountain   palace   chart (p9)   jian xiang"
          "   kong wang")
    for s in (1, 2, 3, 4, 5):
        r = rates(float(s))
        print("   {:5d} {:10.4f} {:8.4f} {:12.4f} {:12.4f} {:11.4f}".format(
            s, *r))
    print("   check: mountain rate = E|error| / 15")
    print("   = sigma sqrt(2 / pi) / 15,")
    print("   which is {:.4f} at sigma 3".format(
        3 * math.sqrt(2 / math.pi) / 15))
    print("\nReading: with an error of 2 to 3 degrees, one reading in")
    print("nine to one in six names the wrong mountain, and the chart")
    print("for period 9 changes two times in three of those. The status")
    print("of being near an edge, which decides whether replacement")
    print("charts apply, is the least stable of all: an error of 3")
    print("degrees flips it for 0.3118 of houses.")
#    sigma   mountain   palace   chart (p9)   jian xiang   kong wang
#        1     0.0531   0.0177       0.0354       0.1063      0.1062
#        2     0.1063   0.0354       0.0708       0.2124      0.1970
#        3     0.1594   0.0531       0.1063       0.3118      0.2524
#        4     0.2125   0.0708       0.1417       0.3896      0.2848
#        5     0.2655   0.0886       0.1770       0.4389      0.3043
#    check: mountain rate = E|error| / 15
#    = sigma sqrt(2 / pi) / 15,
#    which is 0.1596 at sigma 3
#
# Reading: with an error of 2 to 3 degrees, one reading in
# nine to one in six names the wrong mountain, and the chart
# for period 9 changes two times in three of those. The status
# of being near an edge, which decides whether replacement
# charts apply, is the least stable of all: an error of 3
# degrees flips it for 0.3118 of houses.

σ=1\sigma = 1 度时,0.0531 的读数跨山,0.0177 出卦,九运盘面改变 0.0354;σ=3\sigma = 3 度时分别为 0.1594、0.0531 与 0.1063。跨山的概率等于误差绝对值的期望除以 15 度,即 σ2/π/15\sigma\sqrt{2/\pi}/15,在 σ=3\sigma = 3 时为 0.1596,与积分一致。盘面改变的概率是跨山的三分之二:同一宫内天元与人元两山的阴阳相同,在两者之间跨山不改变盘。最不稳定的是「兼向」的判断:3 度的误差就使 0.3118 的房子在兼与不兼之间翻转,5 度时为 0.4389;「空亡」的判断在 5 度时也有 0.3043 被翻转。

罗盘误差标准差与跨山、出卦、换盘、兼向判定翻转的概率。

磁偏角:一个系统性的旋转

磁针指向磁北,与真北相差当地的磁偏角。世界磁场模型逐点给出这一数值及其随时间的变化 (Chulliat et al. 2020)。若一位师傅直接按针读数,另一位改正到真北,两人对每座房子的读数都恰好相差磁偏角 dd。

推导

# Chapter 3. p06: Magnetic declination: a systematic rotation.
# A magnetic compass points to magnetic north, which differs from true
# north by the local declination d (degrees, east positive). If one
# practitioner reads facings by the needle and another corrects them
# to true north, every reading differs by exactly d. For a facing
# uniform around the circle, the share whose mountain, palace or
# period-9 chart differs between the two conventions is computed on a
# 0.01 degree grid; for d below 15 the mountain share is d / 15.
# Declination also drifts slowly (secular variation). At a drift of
# r degrees a year, the share of houses whose mountain changes within
# one 20-year period is 20 r / 15 (capped at 1).

LOSHU = {"SE": 4, "S": 9, "SW": 2, "E": 3, "C": 5, "W": 7,
         "NE": 8, "N": 1, "NW": 6}
PALACE_OF = {v: k for k, v in LOSHU.items()}
PATH = ["C", "NW", "W", "NE", "S", "N", "SW", "E", "SE"]
OPP = {"N": "S", "S": "N", "E": "W", "W": "E", "NE": "SW", "SW": "NE",
       "NW": "SE", "SE": "NW"}
PAL_ORDER = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
MOUNTAINS = ("ren zi gui chou gen yin jia mao yi chen xun si bing wu "
             "ding wei kun shen geng you xin xu qian hai").split()

def norm(x):
    return (x - 1) % 9 + 1

def fly(c, sign):
    return {p: norm(c + sign * k) for k, p in enumerate(PATH)}

def polarity(number, pos):
    cardinal = number in (1, 3, 7, 9)
    return (1, -1, -1)[pos] if cardinal else (-1, 1, 1)[pos]

def side(base, pal, pos):
    n = base[pal]
    ref = LOSHU[pal] if n == 5 else n
    return fly(n, polarity(ref, pos))

def chart(period, i):
    base = fly(period, 1)
    sit = PAL_ORDER[i // 3]
    face = OPP[sit]
    return base, side(base, sit, i % 3), side(base, face, i % 3), sit, face

def category(period, i):
    base, m, f, sit, face = chart(period, i)
    if m[sit] == period and f[face] == period:
        return "wang shan wang xiang"
    if m[face] == period and f[sit] == period:
        return "shang shan xia shui"
    if m[face] == period and f[face] == period:
        return "shuang xing hui xiang"
    return "shuang xing hui zuo"

def m_index(deg):
    return int(((deg - 337.5) % 360) // 15)

CHARTS = [chart(9, i)[1:3] for i in range(24)]

if __name__ == "__main__":
    print("   d (deg)   mountain   d / 15   palace   chart (p9)")
    for d in (0.5, 2.0, 5.0, 10.0):
        mt = pa = ch = 0
        for k in range(36000):
            t = k / 100 + 0.005
            a, b = m_index(t), m_index(t + d)
            mt += a != b
            pa += a // 3 != b // 3
            ch += CHARTS[a] != CHARTS[b]
        print("   {:7.1f} {:10.4f} {:8.4f} {:8.4f} {:12.4f}".format(
            d, mt / 36000, d / 15, pa / 36000, ch / 36000))
    print("\n   drift (deg/yr)   share changing mountain in 20 years")
    for r in (0.02, 0.05, 0.1, 0.2):
        print("   {:14.2f} {:24.3f}".format(r, min(1.0, 20 * r / 15)))
    print("\nReading: a declination of a few degrees, unstated, makes")
    print("two careful readers disagree on the mountain of one house in")
    print("several; the chart differs for two thirds of those. Which")
    print("north is meant must be fixed before any reading is compared.")
#    d (deg)   mountain   d / 15   palace   chart (p9)
#        0.5     0.0333   0.0333   0.0111       0.0222
#        2.0     0.1333   0.1333   0.0444       0.0889
#        5.0     0.3333   0.3333   0.1111       0.2222
#       10.0     0.6667   0.6667   0.2222       0.4444
#
#    drift (deg/yr)   share changing mountain in 20 years
#              0.02                    0.027
#              0.05                    0.067
#              0.10                    0.133
#              0.20                    0.267
#
# Reading: a declination of a few degrees, unstated, makes
# two careful readers disagree on the mountain of one house in
# several; the chart differs for two thirds of those. Which
# north is meant must be fixed before any reading is compared.

对均匀分布的朝向,换山的比例恰为 d/15d/15:磁偏角 2 度时为 0.1333,5 度时为 0.3333,10 度时为 0.6667;九运盘面改变的比例是其三分之二,分别为 0.0889、0.2222 与 0.4444。磁偏角还会缓慢漂移:每年漂移 0.1 度时,一个 20 年的元运中有 0.133 的房子换山。

注

操作上的含义。 每次读数都应注明:以真北还是磁北为准,当地磁偏角取何值,测了几次、离钢筋与电线多远;朝向离交界 3 度以内时应明确标出,而不是默默选用下卦或替卦。

小结

二十四山的离散化把几度的读数误差放大成换山、出卦与换盘;最不稳定的是兼向与空亡的判断。磁偏角是一个系统性的旋转,不说明以哪一个北为准,两位细心的读者就会对很多房子得出不同的盘。

参考文献

Chulliat, A., W. Brown, P. Alken, et al. 2020. The US/UK World Magnetic Model for 2020-2025: Technical Report. National Centers for Environmental Information, NOAA.

Fan, Y. (2026). Xuankong Flying-Star Permutations, Twenty-Four-Mountain Compass Discretization and Craniofacial Ratio Metrology: Lo-Shu Orbit Cycles, Magnetic Declination Flip Rates and Landmark Measurement Error Propagation [玄空飞星置换代数、二十四山罗盘离散化与骨相比例计量] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090215 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).