跳转至

平面几何计算(functions/planes.py)

functions/planes.py 提供平面几何计算(点、线、圆、三角形、多边形、向量及几何变换)与平面几何对象的构造(定义页面使用)。对外主接口为 get_planes_result,参数以字符串传入;除此之外还导出一批底层辅助函数,它们直接接收 sympy 几何对象(如 PointLineCircleTrianglePolygon),返回 radsimp 化简后的表达式或坐标元组。

Note

若只想按字符串调用,请用 get_planes_result;下列辅助函数适用于需要编程组合几何对象的场景。UI 的「平面几何」定义页与「平面几何计算」页分别使用本模块的构造 / 计算函数。

get_planes_result — 统一调度(字符串接口)

作用:根据 op_index 调用对应的底层几何计算,参数为字符串,内部自动解析。

def get_planes_result(op_index, params, fs):
    ...
参数 类型 含义
op_index int 操作编号,对应 planes_operation_list(0–29)
params list[str] 参数列表:点用 "x,y",多个点用 ";" 分隔;向量分量等按项填写
fs dict 函数字典

返回:计算结果(sympy 表达式 / 坐标元组 / 字符串);参数非法时返回 "计算错误: ..."

操作列表 planes_operation_list

planes_operation_list 是长度为 30 的字符串列表,索引与 op_index 一一对应:

索引 操作 索引 操作
0 两点距离 15 三角形周长
1 中点坐标 16 三角形外心
2 共线判断 17 三角形内心
3 直线方程 18 三角形重心
4 直线斜率 19 三角形垂心
5 直线交点 20 三角形分析
6 点到直线距离 21 多边形面积
7 两直线夹角 22 多边形周长
8 平行判断 23 平移变换
9 垂直判断 24 旋转变换
10 圆的面积 25 反射变换
11 圆的周长 26 两点向量
12 两圆交点 27 向量模
13 圆切线方程 28 向量点积
14 三角形面积 29 向量夹角

Note

UI「平面几何计算」页还额外提供外接圆半径、内切圆半径、直角 / 等腰 / 等边三角形判断等 32 种运算,其内部调用下方对应的底层函数。

几何对象构造(定义页使用)

create_point(x: str, y: str, fs: dict) -> Point

作用:由坐标字符串构造点,返回 Point

create_line(pt1: Point, pt2: Point) -> Line

作用:过两点构造直线。

create_circle(center: Point, radius: str, fs: dict) -> Circle

作用:由圆心与半径字符串构造圆。

create_circle_three_points(p1: Point, p2: Point, p3: Point) -> Circle

作用:过三点构造圆(外接圆)。

create_triangle(p1: Point, p2: Point, p3: Point) -> Triangle

作用:过三点构造三角形。

create_polygon(points: list[Point]) -> Polygon

作用:由顶点列表构造多边形。

底层辅助函数

Note

以下函数接收 sympy 几何对象(来自 sympy.geometry),radsimp 化简后返回表达式或坐标元组。

点运算

point_distance(pt1: Point, pt2: Point) -> Expr

作用:求两点间距离。

midpoint(pt1: Point, pt2: Point) -> tuple[Expr, Expr]

作用:求两点中点坐标,返回 (x, y)

collinear_check(points: list[Point]) -> bool

作用:判断多点是否共线。

translate_point(pt: Point, dx: str, dy: str, fs: dict) -> tuple[Expr, Expr]

作用:将点按向量 (dx, dy) 平移;dx/dy 为字符串表达式,返回 (x', y')

rotate_point(pt: Point, angle: str, center: Point, fs: dict) -> tuple[Expr, Expr]

作用:将点绕 center(旋转中心)旋转 angle 弧度;angle 为字符串表达式,返回 (x', y')

reflect_point(pt: Point, line_pt1: Point, line_pt2: Point) -> tuple[Expr, Expr]

作用:求 pt 关于过 line_pt1line_pt2 的直线的对称点,返回 (x', y')

直线运算

line_equation(pt1: Point, pt2: Point) -> Expr

作用:求过两点的直线方程(默认 x 为变量)。

line_slope(pt1: Point, pt2: Point) -> Expr

作用:求过两点的直线斜率(垂直线返回 oo)。

line_intersection(p1: Point, p2: Point, q1: Point, q2: Point) -> tuple[Expr, Expr] | str

作用:求两直线交点;平行返回 "两直线平行",重合返回 "两直线重合";否则返回 (x, y)

point_to_line_distance(pt: Point, line_pt1: Point, line_pt2: Point) -> Expr

作用:求点到直线的距离。

angle_between_lines(p1: Point, p2: Point, q1: Point, q2: Point) -> Expr

作用:求两直线的夹角(锐角,弧度)。

parallel_check(p1: Point, p2: Point, q1: Point, q2: Point) -> bool

作用:判断两直线是否平行。

perpendicular_check(p1: Point, p2: Point, q1: Point, q2: Point) -> bool

作用:判断两直线是否垂直。

圆运算

circle_center(center: Point, radius: str, fs: dict) -> tuple[Expr, Expr]

作用:求圆(由圆心与半径确定)的圆心坐标 (x, y)

circle_radius(center: Point, radius: str, fs: dict) -> Expr

作用:求圆半径。

circle_area_func(center: Point, radius: str, fs: dict) -> Expr

作用:求圆面积 π·r²

circle_circumference(center: Point, radius: str, fs: dict) -> Expr

作用:求圆周长 2π·r

circle_intersection(center1: Point, radius1: str, center2: Point, radius2: str, fs: dict) -> list[tuple[Expr, Expr]] | str

作用:求两圆交点;无交点返回 "两圆不相交";否则返回交点坐标列表。

circle_tangent_lines(center: Point, radius: str, point: Point, fs: dict) -> list[Expr] | str

作用:求圆外一点到圆的切线方程;无切线返回 "无切线"

三角形运算(均接收 3 个 Point

triangle_area(p1, p2, p3) -> Expr              # 面积
triangle_perimeter(p1, p2, p3) -> Expr         # 周长
triangle_circumcenter(p1, p2, p3) -> tuple[Expr, Expr]   # 外心
triangle_circumradius(p1, p2, p3) -> Expr      # 外接圆半径
triangle_incenter(p1, p2, p3) -> tuple[Expr, Expr]       # 内心
triangle_inradius(p1, p2, p3) -> Expr          # 内切圆半径
triangle_centroid(p1, p2, p3) -> tuple[Expr, Expr]       # 重心
triangle_orthocenter(p1, p2, p3) -> tuple[Expr, Expr]    # 垂心
triangle_is_right(p1, p2, p3) -> bool          # 直角三角形判断
triangle_is_isosceles(p1, p2, p3) -> bool      # 等腰三角形判断
triangle_is_equilateral(p1, p2, p3) -> bool    # 等边三角形判断
triangle_analysis(p1, p2, p3) -> dict          # 综合分析(面积/周长/四心/三类判断等)

多边形运算

polygon_area_func(points: list[Point]) -> Expr

作用:求多边形面积(points 为顶点列表)。

polygon_perimeter_func(points: list[Point]) -> Expr

作用:求多边形周长。

几何构造(由已有对象生成新对象)

circle_with_diameter(p1: Point, p2: Point) -> Circle

作用:以两点为直径端点构造圆。

circle_by_center_and_point(center: Point, pt: Point) -> Circle

作用:以圆心和圆上一点构造圆。

perpendicular_bisector(p1: Point, p2: Point) -> Line

作用:求线段(p1p2)的中垂线。

line_parallel_through_point(line: Line, pt: Point) -> Line

作用:过一点作已知直线的平行线。

line_perpendicular_through_point(line: Line, pt: Point) -> Line

作用:过一点作已知直线的垂线。

angle_bisector_line(l1: Line, l2: Line) -> Line | str

作用:求两相交直线的角平分线;平行返回 "两直线平行,无角平分线",重合返回 "两直线重合"

angle_bisector(p1: Point, p2: Point, p3: Point) -> Line

作用:求角 p1-p2-p3 的角平分线(p2 为顶点)。

triangle_median(tri: Triangle, vertex_label: int) -> Segment

作用:求三角形中线(顶点到对边中点);vertex_label 为顶点索引(0/1/2)。

triangle_altitude(tri: Triangle, vertex_label: int) -> Line

作用:求三角形高线(过顶点作对边垂线)。

triangle_midsegment(tri: Triangle) -> Segment

作用:求三角形中位线(连接两边中点的线段)。

triangle_incircle(tri: Triangle) -> Circle

作用:求三角形内切圆。

triangle_excircle(tri: Triangle, vertex_label: int) -> Circle

作用:求三角形旁切圆(与某边及另外两边延长线相切)。

segment_from_points(p1: Point, p2: Point) -> Segment

作用:过两点构造线段。

向量运算

vector_from_points(pt1: Point, pt2: Point) -> tuple[Expr, Expr]

作用:求由 pt1 指向 pt2 的向量 (dx, dy)

vector_length(dx: str, dy: str, fs: dict) -> Expr

作用:求向量模长;dx/dy 为分量字符串。

vector_dot(v1_dx: str, v1_dy: str, v2_dx: str, v2_dy: str, fs: dict) -> Expr

作用:求两向量点积。

vector_angle(v1_dx: str, v1_dy: str, v2_dx: str, v2_dy: str, fs: dict) -> Expr

作用:求两向量夹角(弧度)。

area_by_coordinates(x1, y1, x2, y2, x3, y3, fs) -> Expr

作用:由三个顶点的坐标字符串(行列式法)求三角形面积。

Example

python from functions.planes import get_planes_result get_planes_result(0, ["0,0", "3,4"], {}) # 两点距离 -> 5 get_planes_result(14, ["0,0", "1,0", "0,1"], {}) # 三角形面积 -> 1/2