edu-analytic-geometry

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

解析几何解题 → 交互网页

Analytic Geometry Problem Solving → Interactive Webpage

这个技能产出什么

What This Skill Produces

一个可直接用浏览器打开的单页 HTML(三栏):
  • 左栏:题面 + 动态控制台 —— 一个可变参数滑块(如直线倾斜角 θ / 动点参数 t)驱动实时 重算的几何量(交点坐标、斜率、数量积、弦长、面积…),以及"理论范围条"或"定值指示"。
  • 中栏:分步解析(公式用 KaTeX),可一键收起把空间让给画板。
  • 右栏:2D Canvas 动态几何画板(圆锥曲线 + 动直线/动点 + 向量 + 点标注 + 网格坐标轴), 叠加画笔涂鸦工具栏。
形态与目标模板
/Users/wuyi/code/code2026/6/template/code_artifact.html
一致。
A single-page HTML file that can be directly opened in a browser (three-column layout):
  • Left Column: Problem statement + dynamic console — a variable parameter slider (such as line inclination angle θ / moving point parameter t) drives real-time recalculation of geometric quantities (intersection coordinates, slopes, dot products, chord lengths, areas…), along with a "theoretical range bar" or "fixed value indicator".
  • Middle Column: Step-by-step explanations (formulas rendered with KaTeX), which can be collapsed with one click to make space for the drawing board.
  • Right Column: 2D Canvas dynamic geometry drawing board (conic sections + moving lines/moving points + vectors + point annotations + grid coordinate axes), with an overlay brush doodling toolbar.
It has the same form as the target template
/Users/wuyi/code/code2026/6/template/code_artifact.html
.

依赖(重要)

Dependencies (Important)

计算核心
lib/analytic_kernel.py
依赖 sympy。运行脚本前先确认有能 import sympy 的 解释器:
python3 -c "import sympy"
(本机用
/opt/homebrew/bin/python3.11
,sympy 1.14)。
缺库时:若 import 报错(sympy 或后续任何库),先询问用户是否安装,同意后再装 (
python3 -m pip install <库名>
)或换一个已装该库的解释器;不要未经询问直接装。 下文
python3
均指这个能跑通依赖的解释器。
The calculation core
lib/analytic_kernel.py
depends on sympy. Before running the script, confirm you have an interpreter that can import sympy:
python3 -c "import sympy"
(local environment uses
/opt/homebrew/bin/python3.11
, sympy 1.14).
When libraries are missing: If an import error occurs (sympy or any subsequent library), first ask the user for permission to install, then install it (
python3 -m pip install <library name>
) or switch to an interpreter that already has the library installed; do not install without asking. The term
python3
below refers to this dependency-compatible interpreter.

工作流程

Workflow

第 1 步:得到 problem spec(三入口归一)

Step 1: Obtain problem spec (unify three entry points)

把题目整理成结构化 spec(曲线类型与参数、已知点/条件、所求类型与对象、语言)。
  • 文字题:直接抽取。
  • 图片:视觉读图抽取,并把识别到的题目回显给用户确认(题面/曲线/参数/所求/语言)再继续。
  • 随机出题:选曲线 + 题型,随机参数 → kernel 求解,用
    analytic_kernel.is_clean(...)
    判答案 是否规整,不规整就重抽。
输出语言跟随提示词语言:英文提示 → 英文网页,中文 → 中文。spec 记下
language
Organize the problem into a structured spec (curve type and parameters, known points/conditions, target type and object, language).
  • Text problems: Extract directly.
  • Images: Extract via visual reading, and echo the recognized problem to the user for confirmation (problem statement/curve/parameters/target/language) before proceeding.
  • Random problem generation: Select curve + problem type, generate random parameters → solve with kernel, use
    analytic_kernel.is_clean(...)
    to check if the answer is neat, re-select parameters if not.
Output language follows prompt language: English prompts → English webpage, Chinese prompts → Chinese webpage. Record
language
in the spec.

第 2 步:用 kernel 精确计算(不要心算)

Step 2: Perform precise calculations with kernel (do not calculate manually)

references/conventions.md
的解法配方,调用
lib/analytic_kernel.py
lib/conics.py
  • conics.ellipse/hyperbola/parabola/circle(...)
    得曲线对象(精确 a,b,c、焦点、顶点、准线、 渐近线、
    eq_latex
    、以及给前端引擎的
    board
    dict)。
  • chord_setup(conic, through)
    联立含参直线
    x=my+c
    得 y 的二次方程 + 韦达量(精确)。
  • 目标量:
    dot_product_expr
    /
    chord_len_sq_expr
    /
    triangle_area_expr
    /
    slope_product_central
  • 取值范围:
    range_over_m(expr, horizontal_valid=?)
    —— 含开闭端点判定(关键正确性点,见下)。
  • 定值:
    is_constant_in_m(expr)
可命令行自检 kernel:
bash
python3 lib/analytic_kernel.py      # 旗舰题内置断言自检
⚠️ 端点开闭 = 正确性命门:过焦点的弦,水平线(x 轴,θ=0)与竖直线(θ=90)都是合法直线, 它们取到的端点要计入。例:椭圆 MA·MB 题,x 轴取到 −3、竖直线取到 7/4,故答案是闭区间
[-3, 7/4]
(很多教辅误写成开的
(-3, 7/4]
)。
range_over_m
已据此判定,且这样答案与交互 工具一致——拖滑块到 0° 就读到 −3。抛物线焦点弦的"轴方向"是退化线(只交一点),其极限端点 不计入(
horizontal_valid=False
或限制 param 范围)。
Follow the solution recipe in
references/conventions.md
, call
lib/analytic_kernel.py
and
lib/conics.py
:
  • conics.ellipse/hyperbola/parabola/circle(...)
    to get curve objects (precise a,b,c, foci, vertices, directrices, asymptotes,
    eq_latex
    , and
    board
    dict for front-end engine).
  • chord_setup(conic, through)
    to set up simultaneous parametric line
    x=my+c
    and obtain quadratic equation in y + Vieta quantities (precise).
  • Target quantities:
    dot_product_expr
    /
    chord_len_sq_expr
    /
    triangle_area_expr
    /
    slope_product_central
  • Value ranges:
    range_over_m(expr, horizontal_valid=?)
    includes open/closed endpoint determination (key correctness point, see below).
  • Fixed values:
    is_constant_in_m(expr)
    .
Self-check the kernel via command line:
bash
python3 lib/analytic_kernel.py      # Built-in assertion self-check for flagship problems
⚠️ Endpoint open/closed = correctness critical point: For chords passing through foci, horizontal lines (x-axis, θ=0) and vertical lines (θ=90) are valid lines, and their endpoints should be included. Example: For an ellipse MA·MB problem, the x-axis gives −3 and the vertical line gives 7/4, so the answer is the closed interval
[-3, 7/4]
(many teaching materials incorrectly write it as the open interval
(-3, 7/4]
).
range_over_m
has already made this determination, and the answer is consistent with the interactive tool — drag the slider to 0° to read −3. The "axis direction" of a parabola's focal chord is a degenerate line (intersects at only one point), and its limit endpoints are not included (
horizontal_valid=False
or restrict param range).

第 3 步:组装数据并注入模板

Step 3: Assemble data and inject into template

📍 输出位置 & 唯一产物(最重要):交付给用户的只有一个
.html
,写到当前工作目录 (
Path.cwd()
(除非用户显式指定路径)。cwd 里不要留任何别的文件——构建脚本(
.py
)、
__pycache__
、自检截图(
.png
)、临时文件都不是交付物,一律放
/tmp
或用完即删。 也绝不要写进技能自身目录(
skills/edu-analytic-geometry/output/
是技能内部样例)。
把"组装数据 + 注入模板"的构建脚本写到临时目录(如
/tmp/ag_build.py
),让它只把
.html
写到 cwd
;脚本拼出
lesson
/
steps
/
board
数据(schema 见
references/problem-schema.md
), 调用
generate.render_html(data, out)
注入
template/board.html
跑完即删脚本
python
undefined
📍 Output Location & Unique Product (Most Important): The only deliverable to the user is a single
.html
file, written to the current working directory (
Path.cwd()
)
(unless the user explicitly specifies a path). Do not leave any other files in the cwd — build scripts (
.py
),
__pycache__
, self-check screenshots (
.png
), temporary files are not deliverables; place them in
/tmp
or delete them after use. Never write into the skill's own directory (
skills/edu-analytic-geometry/output/
is for internal skill samples).
Write the "assemble data + inject template" build script to a temporary directory (e.g.,
/tmp/ag_build.py
), make it only write the
.html
file to cwd
; the script constructs
lesson
/
steps
/
board
data (schema see
references/problem-schema.md
), calls
generate.render_html(data, out)
to inject into
template/board.html
, delete the script immediately after running:
python
undefined

构建脚本放 /tmp(不要放 cwd):/tmp/ag_build.py

Build script placed in /tmp (not cwd): /tmp/ag_build.py

import sys; sys.dont_write_bytecode = True # 不生成 pycache sys.path.insert(0, "<技能目录>/scripts") import generate from pathlib import Path data = {"lesson": {...}, "steps": [...], "board": {...}} out = Path.cwd() / "solution-<题目简述>.html" # 唯一产物,落在用户当前目录 generate.render_html(data, out)

```bash
python3 -B /tmp/ag_build.py && rm -f /tmp/ag_build.py   # -B 不写字节码;跑完删临时脚本,cwd 只剩 .html
  • steps[*].content
    里的数值直接引用 kernel 结果(用
    K.tex(...)
    输出 LaTeX),模型只负责 组织讲解文字(按目标语言)。
  • board
    用 kernel 给的曲线
    board
    dict、精确点坐标、
    param
    derived
    构造序列、
    readouts
    rangeBar
    (范围题)/
    constant
    (定值题)/
    answerBand
    形状参数题,如离心率范围)。
  • 形状参数题(滑块=离心率 e 等):自然动态量是曲线本身的形状而非动直线/动点时,让滑块=该参数, 把曲线
    a/b/c
    、焦点、动点坐标写成
    @param
    表达式字符串(引擎每帧重绘曲线/焦点/渐近线), 配
    status
    读数显示不等式状态、
    answerBand
    在参数轴高亮答案区间。见 conventions「形状参数题」。
  • 可直接照抄的范本
    scripts/generate.py
    里 6 个
    build_*
    覆盖各类交互范式:
    ellipse_dot_range
    (范围条)、
    ellipse_chord_range
    ellipse_area_max
    ellipse_slopeprod_const
    (定值·中心对称)、
    parabola_dot_const
    (定值·抛物线)、
    hyperbola_ecc_range
    形状参数:滑块=e,曲线随之重绘 +
    status
    +
    answerBand
    )。
已注册题直接出(
-B
不写字节码;不传路径默认写技能 output,交付给用户时务必改成 cwd 下的
.html
):
bash
python3 -B scripts/generate.py list                      # 列出题型
python3 -B scripts/generate.py ellipse_dot_range ./sol.html
python3 -B scripts/generate.py all ./out_dir             # 全部题型
import sys; sys.dont_write_bytecode = True # Do not generate pycache sys.path.insert(0, "<skill directory>/scripts") import generate from pathlib import Path data = {"lesson": {...}, "steps": [...], "board": {...}} out = Path.cwd() / "solution-<problem brief>.html" # Unique product, located in user's current directory generate.render_html(data, out)

```bash
python3 -B /tmp/ag_build.py && rm -f /tmp/ag_build.py   # -B does not write bytecode; delete temporary script after running, only .html remains in cwd
  • Numerical values in
    steps[*].content
    directly reference kernel results (use
    K.tex(...)
    to output LaTeX), the model is only responsible for organizing explanatory text (in the target language).
  • board
    is constructed using the curve's
    board
    dict from kernel, precise point coordinates,
    param
    ,
    derived
    sequences,
    readouts
    ,
    rangeBar
    (range problems)/
    constant
    (fixed value problems)/
    answerBand
    (shape parameter problems, such as eccentricity ranges).
  • Shape parameter problems (slider = eccentricity e, etc.): When the natural dynamic quantity is the curve's own shape rather than moving lines/moving points, set the slider to this parameter, write the curve's
    a/b/c
    , foci, moving point coordinates as expression strings with
    @param
    (the engine redraws the curve/foci/asymptotes every frame), match with
    status
    reading to display inequality status, and
    answerBand
    to highlight the answer interval on the parameter axis. See conventions "Shape Parameter Problems".
  • Copyable templates: The 6
    build_*
    functions in
    scripts/generate.py
    cover various interaction paradigms:
    ellipse_dot_range
    (range bar),
    ellipse_chord_range
    ,
    ellipse_area_max
    ,
    ellipse_slopeprod_const
    (fixed value · central symmetry),
    parabola_dot_const
    (fixed value · parabola),
    hyperbola_ecc_range
    (shape parameter: slider = e, curve redraws accordingly +
    status
    +
    answerBand
    ).
Generate registered problems directly (
-B
does not write bytecode; default writes to skill output if no path is passed, must change to
.html
in cwd when delivering to users):
bash
python3 -B scripts/generate.py list                      # List problem types
python3 -B scripts/generate.py ellipse_dot_range ./sol.html
python3 -B scripts/generate.py all ./out_dir             # All problem types

第 4 步:自检(正确性方案)

Step 4: Self-check (Correctness Plan)

  • kernel 答案 == 答案卡
    lesson.answer
    == 末步骤展示值 == JS 标准位/扫段重算值,四者一致 (
    build_*
    内已加
    assert
    )。
  • rangeBar
    端点来自 kernel 的
    range_over_m
    constant
    值来自 kernel 的定值。
  • 起本地静态服务(服务输出文件所在目录,即 cwd)用预览检查:无控制台报错、KaTeX 正常、 滑块实时重算正确、范围条/定值/定点/轨迹行为符合、画笔与收起面板可用。 (技能仓库内开发时可用
    .claude/launch.json
    ag-preview
    ,端口 4601;别处运行就对 cwd 起 一个临时静态服务。)
  • 自检截图只给你自己看:preview 工具直接返回图像,不要把
    .png
    存到 cwd
    ;本地静态服务只读不写、 不产生文件。自检产生的任何临时文件(构建脚本
    .py
    、截图
    .png
    __pycache__
    等)交付前一律清掉。
⚠️ 必须关闭你开过的端口/服务:预览一结束立即停掉,绝不留占用端口的进程
  • preview 工具开的:
    preview_stop
    (传 serverId)。
  • 直接起的
    http.server
    :用完
    kill
    ,或
    lsof -nP -iTCP:<port> -sTCP:LISTEN
    确认已释放。
  • 交付前确认端口已释放再告诉用户。开了不关 = 未完成自检。
  • Kernel answer == answer card
    lesson.answer
    == final step display value == JS standard bit/segment scan recalculation value, all four are consistent (
    assert
    has been added in
    build_*
    ).
  • rangeBar
    endpoints come from kernel's
    range_over_m
    ;
    constant
    value comes from kernel's fixed value.
  • Start a local static server (serving the directory where the output file is located, i.e., cwd) to preview and check: no console errors, KaTeX renders normally, slider recalculates in real-time correctly, range bar/fixed value/fixed point/locus behavior is correct, brush and panel collapse are usable. (When developing in the skill repository, use
    ag-preview
    in
    .claude/launch.json
    , port 4601; when running elsewhere, start a temporary static server for cwd.)
  • Self-check screenshots are for your own viewing only: The preview tool returns images directly, do not save
    .png
    to cwd
    ; the local static server is read-only, no files are generated. Delete any temporary files generated during self-check (build scripts
    .py
    , screenshots
    .png
    ,
    __pycache__
    , etc.) before delivery.
⚠️ Must close any ports/services you opened: Stop the server immediately after preview, never leave port-occupying processes running.
  • Opened by preview tool:
    preview_stop
    (pass serverId).
  • Directly started
    http.server
    : Use
    kill
    after use, or
    lsof -nP -iTCP:<port> -sTCP:LISTEN
    to confirm release.
  • Confirm ports are released before notifying the user. Not closing ports = incomplete self-check.

第 5 步:交付

Step 5: Delivery

成品写在用户当前工作目录(cwd),命名形如
solution-<题目简述>.html
,把路径告诉用户, 可直接浏览器打开。交付前确认:(1) 成品在 cwd、不在技能目录;(2) 没有遗留本次预览 开启的本地服务/端口;(3) cwd 里只新增了这一个
.html
——没有
.py
/
.png
/
__pycache__
/ 临时文件(用
git status
ls
核一眼,有就删掉)。
The finished product is written to the user's current working directory (cwd), named like
solution-<problem brief>.html
. Inform the user of the path, which can be directly opened in a browser. Before delivery, confirm: (1) The finished product is in cwd, not in the skill directory; (2) No local services/ports opened during this preview are left running; (3) Only this single
.html
file is newly added
in cwd — no
.py
/
.png
/
__pycache__
/ temporary files (check with
git status
or
ls
, delete if any).

扩展

Expansion

  • 加题型:在
    analytic_kernel.py
    加目标量函数(写成 m 的表达式)+ 复用
    range_over_m
    /
    is_constant_in_m
    ;在
    generate.py
    加一个
    build_*
    ,选定交互范式(范围条 / 定值 / 定点 / 轨迹 trace / 形状参数 answerBand)。见
    references/conventions.md
    配方表。
  • 加曲线
    conics.py
    已有椭圆/双曲线/抛物线/圆;前端
    board.html
    引擎已支持四类渲染、 渐近线、准线方向。新曲线在两处各加一份即可。
  • 加交互构造
    board.html
    buildScene
    switch 是构造库(
    line_through_angle
    intersect_line_conic
    point_on_conic
    point_reflect
    tangent_at
    foot_perp
    …), 按需扩充并在 schema 文档登记。
  • Add problem types: Add target quantity functions (written as expressions of m) in
    analytic_kernel.py
    + reuse
    range_over_m
    /
    is_constant_in_m
    ; add a
    build_*
    function in
    generate.py
    , select an interaction paradigm (range bar / fixed value / fixed point / locus trace / shape parameter answerBand). See the recipe table in
    references/conventions.md
    .
  • Add curves:
    conics.py
    already has ellipse/hyperbola/parabola/circle; the front-end
    board.html
    engine already supports rendering of four types, asymptotes, and directrix directions. Just add new curves in both places.
  • Add interactive constructions: The
    buildScene
    switch in
    board.html
    is a construction library (
    line_through_angle
    ,
    intersect_line_conic
    ,
    point_on_conic
    ,
    point_reflect
    ,
    tangent_at
    ,
    foot_perp
    …), expand as needed and register in the schema document.

目录

Directory

  • template/board.html
    — 数据驱动模板(通用 2D 渲染器 + 参数引擎 + 数据岛
    __LESSON_DATA__
  • lib/conics.py
    — 圆锥曲线 sympy 定义库(特殊点 / LaTeX / board dict)
  • lib/analytic_kernel.py
    — sympy 精确求解核心(联立·韦达·范围·定值)
  • scripts/generate.py
    — 注入模板 + 5 个 build_* 范本 + 批量/单题出题
  • references/problem-schema.md
    — 数据格式(board 引擎 schema)
  • references/conventions.md
    — 标准式、解法配方表、韦达/换元套路、端点开闭、自检
  • template/board.html
    — Data-driven template (universal 2D renderer + parameter engine + data island
    __LESSON_DATA__
    )
  • lib/conics.py
    — sympy definition library for conic sections (special points / LaTeX / board dict)
  • lib/analytic_kernel.py
    — sympy precise calculation core (simultaneous equations · Vieta's formulas · ranges · fixed values)
  • scripts/generate.py
    — Template injection + 5 build_* templates + batch/single problem generation
  • references/problem-schema.md
    — Data format (board engine schema)
  • references/conventions.md
    — Standard forms, solution recipes, Vieta/substitution routines, endpoint open/closed rules, self-check