Skip to content

Add real-time 3D solar system simulator with ephemeris calculations - #1

Open
yipeng0428 wants to merge 4 commits into
masterfrom
claude/festive-wozniak-3626nl
Open

yipeng0428 wants to merge 4 commits into
masterfrom
claude/festive-wozniak-3626nl

Conversation

@yipeng0428

Copy link
Copy Markdown
Owner

Summary

This PR introduces a complete, single-page solar system simulator that calculates planetary positions in real-time using JPL analytical ephemeris. The application requires no build tools or external dependencies (three.js is bundled) and runs directly from file:// by double-clicking index.html.

Key Changes

  • Ephemeris Engine (src/ephemeris.js): Implements Standish/JPL Keplerian element model (1800–2050) with Newton-Raphson Kepler equation solver. Converts orbital elements to J2000 heliocentric ecliptic coordinates with ~10 arcsecond accuracy for inner planets.

  • Scene Architecture (src/app.js):

    • Three-layer coordinate mapping: J2000 ecliptic → three.js scene (y-up) with configurable distance/size scaling
    • Dual visualization modes: schematic (√r distance, R^0.4 radius) and true-to-scale with ×1–×3000 boost slider
    • Procedural starfield (7000 stars with color temperature variation)
    • Per-frame orbit line updates and camera-facing selection halos
  • Procedural Textures (src/textures.js):

    • 3D value noise + fBm for rocky planets with impact crater highlights
    • Specialized Mars (polar caps), Earth (ocean/land/clouds), gas giants (banded), and sun (glow layers)
    • All textures generated at runtime via Canvas; zero external image files
  • UI Layer (src/ui.js):

    • Real-time state display (UTC/local time, Julian day, simulation speed)
    • Body selection panel with live ephemeris (distance, light-time, apparent size, orbital velocity)
    • Ranking table sorted by Earth distance
    • Time controls: real-time sync, 1 min–1 year per second playback, date picker, ±1 day/year steps
    • Text updates throttled to ~9 Hz; label positions updated every frame
  • Camera Controller (src/controls.js): Custom orbit camera (no external dependencies) with precise click/drag distinction (<6 px, <450 ms = click), supporting rotate/pan/zoom via mouse and touch.

  • Static Data (src/data.js): Physical parameters (radius, mass, tilt, rotation period), orbital elements, color palettes, and descriptive facts for 10 bodies (Sun through Pluto).

  • Styling (styles.css): Dark theme with low saturation, monospace numerics for frame-by-frame readability, responsive layout with collapsible dock.

  • Testing (tests/smoke.mjs): Playwright-based smoke test verifying WebGL rendering, ephemeris sanity (perihelion/aphelion bounds), and UI interactivity.

  • Build Tooling (tools/make-three-bundle.mjs): Converts three.js ESM to IIFE global script by rewriting export statement, enabling file:// execution without a dev server.

Notable Implementation Details

  • Coordinate System: Maps J2000 heliocentric ecliptic (x, y, z) → three.js (x, z, −y) preserving handedness; z-axis points to ecliptic north.
  • Precision Trade-offs: Analytical ephemeris (not numerical integration); no TT−UTC correction (~69 s) or planetary perturbations; suitable for visualization, not astrometry.
  • Scale Compression: Default schematic mode uses √r for distances and R^0.4 for radii to keep all bodies visible; true-to-scale mode available with size boost slider; automatic capping prevents sun from occluding inner planets.
  • Seamless Textures: Cylindrical sampling (cos θ, sin θ) for equirectangular maps ensures u-direction wrapping without seams.
  • Keyboard Shortcuts: 0–9 for body selection, Space to pause, F/R/O/L for focus/reset/orbits/labels, Esc to deselect.

https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY

基于 three.js 的单页太阳系模拟,行星位置按当前真实时刻由 JPL
Standish 解析星历(1800–2050 六要素线性模型)计算,支持点选天体
查看实时量(日心距、与地球距离、光行时、轨道速度、相位角、近日点
日期等)与物理参数。

实现要点:
- 零安装、零外部请求:three.js r169 以全局脚本形式内置(由
  tools/make-three-bundle.mjs 从官方 ESM 构建机械改写),行星纹理
  运行时用 Canvas 值噪声程序化生成,双击 index.html 即可运行。
- 自写轨道相机,精确区分拖拽与点击;拾取改用屏幕空间像素距离,
  解决小目标(2–8 px)难以点中的问题。
- 三套比例映射(示意 √r / 真实距离 / 真实尺寸可调放大),并对
  天体半径做轨道比例限幅,限幅生效时在界面明确标注。
- 时间控制:实时同步、1 分–1 年每秒流速、暂停、日期跳转与步进;
  自转相位以 J2000 为零点计算,时间回拖可复现。
- tests/smoke.mjs:Playwright 冒烟测试 22 项断言,当前全部通过。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY
@kilo-code-bot

kilo-code-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

Kilo Code Review could not run — your account is out of credits.

Add credits or switch to a free model to enable reviews on this change.

Copy link
Copy Markdown
Owner Author

CI 状态说明:Kilo Code Review 失败与本 PR 的改动无关

当前 head 1f173a7 上唯一的检查 Kilo Code Review 结论为 action_required,其输出为:

Insufficient credits to run review — Review could not start because the account has insufficient credits.

即该第三方评审应用根本没有开始评审,失败原因是账号额度不足(账户计费状态),与本 PR 的代码无关:

  • 该结果与 diff 内容无关,在任何提交上都会相同;本仓库没有 .github/workflows,不存在其它 CI。
  • 任何代码改动都无法清除它,重跑也不会改变结果(额度不会因重跑而恢复),因此不做重跑、不改代码。
  • 解决方式在仓库之外:为 Kilo 账号补充额度,或在仓库设置中移除该检查。

分支基于最新 master(e0286ba)快进,无合并冲突;暂无评审意见待处理。

本地验证(node tests/smoke.mjs,Playwright + Chromium 软件渲染)22 项断言全部通过:WebGL 出图、各行星日心距落在自身近/远日距之间、地球公转速度 29.852 km/s、实时模式与系统时钟偏差 0.038 s、画布点击选中、拖拽不被误判为点击、流速与暂停生效、两种距离映射下海王星/地球距离比分别为 29.94 与 5.47(≈√30)、运行期间无 JS 异常。


Generated by Claude Code

新增 tools/build-single-file.mjs:按 index.html 原有加载顺序,把
styles.css 与全部脚本内联成单个 HTML。由于项目本就不用 ES module、
不请求任何外部资源,内联后行为与多文件版完全一致。

- dist/solar-system.html(约 765 KB):零外部引用(0 个 link href /
  script src / url()),双击即可离线运行。
- tests/smoke.mjs 支持传入目标路径,可用同一套断言验证打包版;
  多文件版与单文件版 22 项断言均全部通过。
- 内联时对字面量 </script 做防御性转义,避免日后源码中出现该串时
  静默截断宿主标签。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY
内容深度:
- 月球:ELP2000-82B 截断式(Meeus 第 47 章,黄经 19 项 / 黄纬 13 项 /
  距离 13 项)。对 Meeus 例 47.a 黄经差 0.0054°、距离差 17 km;139 个
  朔望月平均 29.53095 天(理论 29.530588,差 0.5 分钟)。对黄经做一阶
  总岁差改正,与行星的 J2000 框架对齐。
- 实时月相:相位名称、照亮比例、月龄、下次朔/望时刻,并绘制月相图
  (北半球视角,8 个相位有像素级方向断言)。相位命名不按 45° 均分,
  朔望弦各取 ±7.5° 窄窗口,避免把 110° / 照亮 68% 叫成"上弦"。
- 场景中的月球:方向真实、间距按母星放大倍数反向压缩,并按潮汐锁定
  使月海密集的近地面始终朝向地球。
- 视星等:Astronomical Almanac 经典式;天王星 +5.6、海王星 +7.8、
  冥王星 +14.5 与实际量级一致。土星未计环的贡献,界面已标注。

交互(借鉴外部参考页的信息设计,物理模型不借):
- 左侧天体目录:固定顺序的导航锚点,编号与数字键快捷键同源。
- 定位标记:固定像素大小的空心环,真实比例下行星缩成亚像素点时
  仍可定位与点击;天体够大时自动淡出。
- 屏幕比例尺:按割线而非导数计算——压缩映射在太阳处 dr/dd→0,
  取导数会给出"100 px ≈ 33 km"的荒谬读数。
- 标签防重叠:按选中优先、近者优先摆放,重叠者退化为圆点。

诚实性与可访问性:
- 越界警告:时间超出 Standish 根数表 1800–2050 的标称区间时明确提示
  结果不可信;日期输入框按此设 min/max。
- WCAG 2.1 AA:次要文字对比度 4.22→5.4:1、canvas 可聚焦且方向键可
  转动视角、统一 focus-visible、标签与目录改为真 button、开关加
  role=switch。面板刻意不加 aria-live(9 Hz 刷新会让读屏器持续念数字),
  改为仅在选中项变化时向专用状态区播报一次。
- 界面内直接给出数据来源链接。

测试:tests/smoke.mjs 断言 22 → 48 项,多文件版与单文件打包版均全通过。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY
1) 平移修复(架构问题,不是事件问题)
   主循环每帧调用 setTarget() 重设注视点,右键拖出的偏移在同一帧被
   覆盖,所以平移此前完全不生效。改为:
     注视点 = 基准点(场景每帧给,可能跟随天体)+ 平移偏移(用户拖的,持久)
   平移量按目标平面上每像素的世界单位换算(2·tan(fov/2)·d / 视口高),
   画面 1:1 跟随光标。右键 / 中键 / Shift+左键均可平移。

2) 锁定跟随
   - 悬浮时提示下一步操作,文案随状态变化(未选 / 已选 / 已锁定)。
   - 第一次单击选中,再次单击锁定;标签加锁定标记,面板按钮变为
     "已锁定 · 解除"(aria-pressed)。
   - 锁定后镜头持续跟随天体,但旋转、平移、缩放全部照常可用,
     不会因交互而解除锁定。
   - 解除锁定时把当前注视点转存进平移偏移,画面原地不动;只有显式
     点「回到太阳」才重新取景,避免镜头被吸回太阳的突兀滑动。

3) 比例改为三挡互斥模型:简化示意 / 真实距离 / 完全真实
   原先两个复选框可拼出"真实尺寸 + 压缩距离"这类自相矛盾的组合。
   新增对"完全真实确实是 1:1"的逐项验证:直接量场景几何与真实公里数
   对账,八大行星的半径/日心距比值、太阳半径/地球轨道半径、地月距离/
   地球半径共 11 项,相对误差 <1e-9;同时断言简化示意模式下地球半径
   确实被放大约 891 倍(模式语义自洽)。
   太阳限幅阈值由 35% 调到 42%:示意太阳半径恰为水星轨道的 39.7%,
   默认模式因此不再误触发限幅提示。

4) 移除尺寸放大滑杆(完全真实模式即 ×1,无需放大系数)。

测试:48 → 71 项,多文件版与单文件打包版均全通过。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants