将高中物理题的示意图(位图)转换为精确的矢量图形代码,全程分 6 步完成任务。本技能为物理动画制作提供前期准备工作。
根据图像内容建立坐标系,并记录关键参数:
读取并分析用户提供的图像,识别以下元素:
完成后向用户描述识别到的内容。
获取用户提供的物理题目文字,逐项核对:
此步不可跳过,必须与用户交互完成。
根据校对后的元素列表,生成矢量图形代码:
默认使用 HTML Canvas(方便后续生成动画)
检查:物品 ✓、位置 ✓、关系 ✓ 三者与原图一致
注意事项(务必遵守):
如图像标注不清晰,可先描述识别到的结构,请用户确认后再绘制
与用户交互,逐项检查:
此步必须与客户交互完成。
根据客户需求导出:
javascript
// 坐标转换:数学坐标 → Canvas坐标
// 数学坐标 (mx, my) → Canvas坐标 (cx, cy)
// cx = originX + mx * scale
// cy = originY - my * scale // 注意y轴方向反转
// 常用绘制方法
ctx.beginPath();
ctx.arc(cx, cy, radius, startAngle, endAngle); // 圆弧
ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); // 直线
ctx.strokeStyle = '#333'; ctx.lineWidth = 2;
ctx.stroke();
// 虚线
ctx.setLineDash([5, 5]);
ctx.stroke();
ctx.setLineDash([]); // 恢复实线
// 箭头
function drawArrow(ctx, fromX, fromY, toX, toY) {
const headLen = 10;
const angle = Math.atan2(toY - fromY, toX - fromX);
ctx.beginPath();
ctx.moveTo(fromX, fromY);
ctx.lineTo(toX, toY);
ctx.lineTo(toX - headLen * Math.cos(angle - Math.PI/6), toY - headLen * Math.sin(angle - Math.PI/6));
ctx.moveTo(toX, toY);
ctx.lineTo(toX - headLen * Math.cos(angle + Math.PI/6), toY - headLen * Math.sin(angle + Math.PI/6));
ctx.stroke();
}
javascript
// 半圆弧,圆心在 (cx, cy),半径 R
// 在Canvas中:从 π 到 0(顺时针方向)
ctx.arc(cx, cy, R, Math.PI, 0, false); // 下半圆(Canvas中y向下)
javascript
// x轴
drawArrow(ctx, 30, originY, width-20, originY);
ctx.fillText('x', width-15, originY+5);
// y轴(物理向上,Canvas向下绘制)
drawArrow(ctx, originX, height-20, originX, 20);
ctx.fillText('y', originX-15, 25);
javascript
// 虚线从点到坐标轴
ctx.setLineDash([4, 4]);
ctx.beginPath();
ctx.moveTo(px, py);
ctx.lineTo(px, originY); // 垂直虚线到x轴
ctx.stroke();
ctx.setLineDash([]);
// 标注点(实心圆)
ctx.beginPath();
ctx.arc(px, py, 4, 0, 2 * Math.PI);
ctx.fillStyle = 'black';
ctx.fill();
physics_shapes.md:常见物理图形的 Canvas/SVG 代码片段(圆弧、力箭头、弹簧等)坐标系Y轴方向角度正方向CanvasY轴向下(y增大=向下)顺时针数学/物理Y轴向上(y增大=向上)逆时针
arc(cx, cy, R, 0, Math.PI, true),下半圆是 arc(cx, cy, R, Math.PI, 0, false)text
数学坐标 (mx, my) → Canvas坐标 (cx, cy)
cx = originX + mx * scale
cy = originY - my * scale // 注意y轴方向反转
Transform bitmap images of high school physics problems into precise vector graphics code. This skill prepares diagrams for physics animation production through a 6-step workflow.
Recognize these elements from the image:
Cross-check Step 1 with the physics problem description:
This step is mandatory - must complete with user interaction.
Create Canvas code based on verified elements:
Default output: HTML Canvas (for easy animation)
Verify: Objects ✓, Positions ✓, Relationships ✓
Critical Notes:
Interact with user to check:
Export based on user needs:
SystemY-axisAngle DirectionCanvasDownwardClockwiseMath/PhysicsUpwardCounter-clockwise
text
Math (mx, my) → Canvas (cx, cy)
cx = originX + mx * scale
cy = originY - my * scale // Note: y-axis inverted