5D Library › Xuankong Flying-Star Permutations, Twenty-Four-Mountain Compass Discretization and Craniofacial Ratio Metrology · 中文

Chapter 3. Discretising Twenty-Four Mountains and Compass Error

A continuous angle, a discrete mountain

The luopan divides 360 degrees into twenty-four mountains of 15 degrees, three to a trigram (45 degrees). A real facing is a continuous angle, but a chart needs a discrete mountain. This discretisation makes charts very sensitive to reading error: a slight error can cross into the next mountain, leave the trigram for the next palace, change the chart, or change whether a facing counts as “near the edge” (within 3 degrees of a boundary, where replacement charts apply) or “void” (within 1.5 degrees).

The program lets the true facing be uniform around the circle and the reading error normal with standard deviation σ\sigma, and integrates exactly on a 0.1-degree grid.

Calculation

# 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.

At σ=1\sigma = 1 degree, 0.0531 of readings cross into another mountain, 0.0177 into another palace, and the period-9 chart changes for 0.0354; at σ=3\sigma = 3 degrees these are 0.1594, 0.0531 and 0.1063. The chance of crossing a mountain equals the expected absolute error divided by 15 degrees, σ2/π/15\sigma\sqrt{2/\pi}/15, which is 0.1596 at σ=3\sigma = 3, in agreement with the integral. The chart changes in two thirds of the crossings: the heaven and man mountains of one palace share a polarity, so crossing between them leaves the chart unchanged. Least stable of all is the “near the edge” call: an error of 3 degrees flips it for 0.3118 of houses, 5 degrees for 0.4389; the “void” call also flips for 0.3043 at 5 degrees.

Compass error and the probabilities of crossing a mountain, a palace, changing the chart and flipping the “near the edge” call.

Declination: a systematic rotation

A magnetic needle points to magnetic north, which differs from true north by the local declination. The World Magnetic Model gives its value at each place and its change over time (Chulliat et al. 2020). If one practitioner reads by the needle and another corrects to true north, their readings of every house differ by exactly the declination dd.

Calculation

# 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.

For facings uniform around the circle, the share that changes mountain is exactly d/15d/15: 0.1333 at a declination of 2 degrees, 0.3333 at 5 and 0.6667 at 10; the period-9 chart changes for two thirds of these, 0.0889, 0.2222 and 0.4444. Declination also drifts slowly: at 0.1 degrees a year, 0.133 of houses change mountain within one 20-year period.

Note

Practical consequence. Every reading should state whether it refers to true or magnetic north, which declination was used, how many readings were taken and how far from steel and wiring; a facing within 3 degrees of a boundary should be marked as such, rather than silently read as an ordinary or a replacement chart.

Summary

Discretising twenty-four mountains turns a few degrees of reading error into changed mountains, palaces and charts; the “near the edge” and “void” calls are the least stable. Declination is a systematic rotation, and without a stated north two careful readers will give many houses different charts.

References

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).