Zi Wei Dou Shu Calculation Algorithm

.zwds-calculator { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; max-width: 800px; margin: 20px auto; padding: 25px; border: 1px solid #e1e1e1; border-radius: 12px; background-color: #f9f9f9; color: #333; line-height: 1.6; } .zwds-calculator h2 { color: #4b0082; text-align: center; margin-bottom: 25px; font-size: 28px; } .zwds-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; } .zwds-field { display: flex; flex-direction: column; } .zwds-field label { font-weight: 600; margin-bottom: 8px; font-size: 14px; color: #555; } .zwds-field select, .zwds-field input { padding: 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; } .zwds-btn { background-color: #4b0082; color: white; border: none; padding: 15px 30px; border-radius: 6px; font-size: 18px; font-weight: bold; cursor: pointer; width: 100%; transition: background 0.3s; } .zwds-btn:hover { background-color: #6a0dad; } #zwds-result { margin-top: 25px; padding: 20px; background-color: #fff; border: 2px solid #4b0082; border-radius: 8px; display: none; } .result-item { display: flex; justify-content: space-between; border-bottom: 1px border #eee; padding: 10px 0; } .result-label { font-weight: bold; color: #4b0082; } .zwds-article { margin-top: 40px; } .zwds-article h3 { color: #4b0082; margin-top: 25px; } .zwds-article p { margin-bottom: 15px; } @media (max-width: 600px) { .zwds-grid { grid-template-columns: 1fr; } }

Zi Wei Dou Shu Algorithm Calculator

Calculate Life Palace, Element Phase, and Zi Wei Star Position using authentic lunar logic.

Jia (Wood+) Yi (Wood-) Bing (Fire+) Ding (Fire-) Wu (Earth+) Ji (Earth-) Geng (Metal+) Xin (Metal-) Ren (Water+) Gui (Water-)
Zi (11pm-1am) Chou (1am-3am) Yin (3am-5am) Mao (5am-7am) Chen (7am-9am) Si (9am-11am) Wu (11am-1pm) Wei (1pm-3pm) Shen (3pm-5pm) You (5pm-7pm) Xu (7pm-9pm) Hai (9pm-11pm)
1st Month2nd Month 3rd Month4th Month 5th Month6th Month 7th Month8th Month 9th Month10th Month 11th Month12th Month
Life Palace (Ming Gong) Location:
Five Elements Phase (Ju):
Zi Wei Star Position:
Palace Heavenly Stem:

Understanding the Zi Wei Dou Shu Calculation Algorithm

Zi Wei Dou Shu (Purple Star Astrology) is one of the most respected forms of Chinese divination. Unlike the Four Pillars of Destiny (Bazi), Zi Wei Dou Shu uses a complex algorithm to map 108 stars across twelve palaces. The calculation begins by establishing the Life Palace (Ming Gong) and the Five Element Phase (Wu Xing Ju).

The Core Mathematical Logic

The algorithm follows a strict sequence:

  • Life Palace: Calculated by starting at the 'Yin' branch, moving clockwise by the Lunar Birth Month, and then moving counter-clockwise by the Birth Hour.
  • The Five Element Phase: This determines the "starting age" of your major luck cycles. It is derived from the interaction between the Heavenly Stem of your birth year and the Earthly Branch of your Life Palace.
  • Zi Wei Star Placement: Once the Element Phase and Lunar Day are known, a specific mathematical formula (Day / Phase) is used to find the coordinate of the "Emperor Star" (Zi Wei).

Example Calculation Case

If a person is born in the Year of Jia (Stem 0), in the 1st Lunar Month, during the Zi Hour (Hour 0):

  1. Life Palace: Start at Yin (3), move forward 1 month (Yin), move back 0 hours = Yin Palace.
  2. Palace Stem: For a Jia Year, the Yin palace stem is Bing.
  3. Element Phase: Bing + Yin = Fire 6 Phase.
  4. Zi Wei Star: If the Lunar Day is the 1st, the algorithm places the Zi Wei star based on the Fire 6 remainder logic.

Why the Algorithm Matters

Accuracy in the Zi Wei Dou Shu algorithm is vital. A mistake in the lunar conversion or the phase calculation will shift every single star in the chart, leading to an entirely different destiny reading. This tool automates the foundational math to ensure your chart starts with the correct structure.

function calculateZWDS() { var yearStem = parseInt(document.getElementById('yearStem').value); var hourBranch = parseInt(document.getElementById('birthHour').value); var month = parseInt(document.getElementById('lunarMonth').value); var day = parseInt(document.getElementById('lunarDay').value); var branches = ["Zi", "Chou", "Yin", "Mao", "Chen", "Si", "Wu", "Wei", "Shen", "You", "Xu", "Hai"]; var stems = ["Jia", "Yi", "Bing", "Ding", "Wu", "Ji", "Geng", "Xin", "Ren", "Gui"]; // 1. Calculate Life Palace (Ming Gong) // Formula: Yin (index 2) + (Month – 1) – Hour. Use modulo 12. var palaceIndex = (2 + (month – 1) – hourBranch); while (palaceIndex < 0) palaceIndex += 12; palaceIndex = palaceIndex % 12; // 2. Calculate Palace Stem // Based on Year Stem and Palace Branch var startStem = (yearStem % 5) * 2 + 2; // Formula for Yin palace stem var palaceStemIndex = (startStem + (palaceIndex – 2)) % 10; if (palaceStemIndex < 0) palaceStemIndex += 10; // 3. Five Element Phase (Ju) // Derived from Palace Stem and Palace Branch var phaseMap = { "Water 2": [ [0,1,6,7], [2,3,8,9], [4,5,10,11] ], // Simplified logic representation "Wood 3": [ [0,1,2,3], [4,5,6,7] ], "Metal 4": [ [0,1,4,5], [6,7,8,9] ], "Earth 5": [ [2,3,4,5], [8,9,10,11] ], "Fire 6": [ [0,1,8,9], [2,3,10,11], [4,5,6,7] ] }; // Actual ZWDS Ju determination matrix (Stem vs Branch) var juTable = [ [4, 4, 6, 6, 2, 2, 4, 4, 6, 6, 2, 2], // Jia/Ji [3, 3, 5, 5, 4, 4, 3, 3, 5, 5, 4, 4], // Yi/Geng [5, 5, 2, 2, 3, 3, 5, 5, 2, 2, 3, 3], // Bing/Xin [2, 2, 3, 3, 5, 5, 2, 2, 3, 3, 5, 5], // Ding/Ren [6, 6, 4, 4, 2, 2, 6, 6, 4, 4, 2, 2] // Wu/Gui ]; var row = yearStem % 5; var phaseValue = juTable[row][palaceIndex]; var phaseName = ""; if(phaseValue == 2) phaseName = "Water 2 Phase"; if(phaseValue == 3) phaseName = "Wood 3 Phase"; if(phaseValue == 4) phaseName = "Metal 4 Phase"; if(phaseValue == 5) phaseName = "Earth 5 Phase"; if(phaseValue == 6) phaseName = "Fire 6 Phase"; // 4. Zi Wei Star Position Algorithm // Logic: Day / Phase. If remainder, move forward/backward based on odd/even. var x = Math.ceil(day / phaseValue); var remainder = (phaseValue * x) – day; var ziWeiPos; if (remainder % 2 === 0) { ziWeiPos = (x + 2 + remainder) % 12; } else { ziWeiPos = (x + 2 – remainder) % 12; } if (ziWeiPos < 0) ziWeiPos += 12; // Display Results document.getElementById("resPalace").innerText = branches[palaceIndex] + " Palace"; document.getElementById("resPhase").innerText = phaseName; document.getElementById("resZiWei").innerText = branches[ziWeiPos] + " Palace"; document.getElementById("resPalaceStem").innerText = stems[palaceStemIndex]; document.getElementById("zwds-result").style.display = "block"; }

Leave a Reply

Your email address will not be published. Required fields are marked *