Plane Geometry Calculation (functions/planes.py)
functions/planes.py provides plane geometry calculations (points, lines, circles, triangles, polygons, vectors, and geometric transformations) as well as constructors for plane geometry objects (used by the definition page). The public entry is get_planes_result, which takes strings; it also exports low-level helper functions that take sympy geometry objects directly (Point, Line, Circle, Triangle, Polygon) and return radsimp-simplified expressions or coordinate tuples.
Note
For string-based calls use get_planes_result; the helpers below are for composing geometry programmatically. The UI "Plane Geometry" definition page and the "Plane Geometry Calculation" page use the constructors / calculation functions of this module respectively.
get_planes_result — unified dispatch (string interface)
Purpose: call the matching geometry computation by op_index; parameters are strings, parsed internally.
def get_planes_result(op_index, params, fs):
...
| Param | Type | Meaning |
|---|---|---|
op_index |
int |
operation index, matching planes_operation_list (0–29) |
params |
list[str] |
parameter list: points as "x,y", multiple points ";" separated |
fs |
dict |
function dictionary |
Returns: result (sympy expression / coordinate tuple / string); "计算错误: ..." on invalid parameters.
Operation list planes_operation_list
planes_operation_list is a string list of length 30, indexed by op_index:
| idx | op | idx | op |
|---|---|---|---|
| 0 | distance of two points | 15 | triangle perimeter |
| 1 | midpoint | 16 | triangle circumcenter |
| 2 | collinearity check | 17 | triangle incenter |
| 3 | line equation | 18 | triangle centroid |
| 4 | line slope | 19 | triangle orthocenter |
| 5 | line intersection | 20 | triangle analysis |
| 6 | point-to-line distance | 21 | polygon area |
| 7 | angle between lines | 22 | polygon perimeter |
| 8 | parallel check | 23 | translation |
| 9 | perpendicular check | 24 | rotation |
| 10 | circle area | 25 | reflection |
| 11 | circle circumference | 26 | vector of two points |
| 12 | circle-circle intersection | 27 | vector norm |
| 13 | circle tangent lines | 28 | vector dot product |
| 14 | triangle area | 29 | vector angle |
Note
The UI "Plane Geometry Calculation" page additionally offers 32 operations (including circumradius, inradius, and right / isosceles / equilateral triangle checks), implemented internally by the low-level functions below.
Geometry constructors (used by the definition page)
create_point(x: str, y: str, fs: dict) -> Point
Purpose: create a point from coordinate strings.
create_line(pt1: Point, pt2: Point) -> Line
Purpose: line through two points.
create_circle(center: Point, radius: str, fs: dict) -> Circle
Purpose: circle from a center and a radius string.
create_circle_three_points(p1: Point, p2: Point, p3: Point) -> Circle
Purpose: circle through three points (circumcircle).
create_triangle(p1: Point, p2: Point, p3: Point) -> Triangle
Purpose: triangle through three points.
create_polygon(points: list[Point]) -> Polygon
Purpose: polygon from a vertex list.
Low-level helper functions
Note
The functions below take sympy geometry objects (from sympy.geometry) and return radsimp-simplified expressions or coordinate tuples.
Points
point_distance(pt1: Point, pt2: Point) -> Expr
Purpose: distance between two points.
midpoint(pt1: Point, pt2: Point) -> tuple[Expr, Expr]
Purpose: midpoint coordinates, returns (x, y).
collinear_check(points: list[Point]) -> bool
Purpose: whether the points are collinear.
translate_point(pt: Point, dx: str, dy: str, fs: dict) -> tuple[Expr, Expr]
Purpose: translate pt by vector (dx, dy); dx/dy are string expressions, returns (x', y').
rotate_point(pt: Point, angle: str, center: Point, fs: dict) -> tuple[Expr, Expr]
Purpose: rotate pt about center by angle radians; angle is a string expression, returns (x', y').
reflect_point(pt: Point, line_pt1: Point, line_pt2: Point) -> tuple[Expr, Expr]
Purpose: symmetric point of pt about the line through line_pt1 and line_pt2, returns (x', y').
Lines
line_equation(pt1: Point, pt2: Point) -> Expr
Purpose: line equation through two points (variable x by default).
line_slope(pt1: Point, pt2: Point) -> Expr
Purpose: slope of the line through two points (oo for vertical).
line_intersection(p1: Point, p2: Point, q1: Point, q2: Point) -> tuple[Expr, Expr] | str
Purpose: intersection of two lines; "两直线平行" if parallel, "两直线重合" if coincident; else (x, y).
point_to_line_distance(pt: Point, line_pt1: Point, line_pt2: Point) -> Expr
Purpose: distance from a point to a line.
angle_between_lines(p1: Point, p2: Point, q1: Point, q2: Point) -> Expr
Purpose: angle between two lines (acute, radians).
parallel_check(p1: Point, p2: Point, q1: Point, q2: Point) -> bool
Purpose: whether two lines are parallel.
perpendicular_check(p1: Point, p2: Point, q1: Point, q2: Point) -> bool
Purpose: whether two lines are perpendicular.
Circles
circle_center(center: Point, radius: str, fs: dict) -> tuple[Expr, Expr]
Purpose: center coordinates (x, y) of the circle defined by center and radius.
circle_radius(center: Point, radius: str, fs: dict) -> Expr
Purpose: radius of the circle.
circle_area_func(center: Point, radius: str, fs: dict) -> Expr
Purpose: circle area π·r².
circle_circumference(center: Point, radius: str, fs: dict) -> Expr
Purpose: circle circumference 2π·r.
circle_intersection(center1: Point, radius1: str, center2: Point, radius2: str, fs: dict) -> list[tuple[Expr, Expr]] | str
Purpose: intersections of two circles; "两圆不相交" if none; else list of points.
circle_tangent_lines(center: Point, radius: str, point: Point, fs: dict) -> list[Expr] | str
Purpose: tangent line equations of the circle through an external point; "无切线" if none.
Triangles (each takes 3 Points)
triangle_area(p1, p2, p3) -> Expr # area
triangle_perimeter(p1, p2, p3) -> Expr # perimeter
triangle_circumcenter(p1, p2, p3) -> tuple[Expr, Expr] # circumcenter
triangle_circumradius(p1, p2, p3) -> Expr # circumradius
triangle_incenter(p1, p2, p3) -> tuple[Expr, Expr] # incenter
triangle_inradius(p1, p2, p3) -> Expr # inradius
triangle_centroid(p1, p2, p3) -> tuple[Expr, Expr] # centroid
triangle_orthocenter(p1, p2, p3) -> tuple[Expr, Expr] # orthocenter
triangle_is_right(p1, p2, p3) -> bool # right triangle check
triangle_is_isosceles(p1, p2, p3) -> bool # isosceles check
triangle_is_equilateral(p1, p2, p3) -> bool # equilateral check
triangle_analysis(p1, p2, p3) -> dict # full analysis (area/perimeter/centers/checks)
Polygons
polygon_area_func(points: list[Point]) -> Expr
Purpose: polygon area (points is the vertex list).
polygon_perimeter_func(points: list[Point]) -> Expr
Purpose: polygon perimeter.
Geometric constructions (new objects from existing ones)
circle_with_diameter(p1: Point, p2: Point) -> Circle
Purpose: circle with p1–p2 as diameter endpoints.
circle_by_center_and_point(center: Point, pt: Point) -> Circle
Purpose: circle from a center and a point on it.
perpendicular_bisector(p1: Point, p2: Point) -> Line
Purpose: perpendicular bisector of segment p1–p2.
line_parallel_through_point(line: Line, pt: Point) -> Line
Purpose: parallel line through a point.
line_perpendicular_through_point(line: Line, pt: Point) -> Line
Purpose: perpendicular line through a point.
angle_bisector_line(l1: Line, l2: Line) -> Line | str
Purpose: angle bisector of two intersecting lines; "两直线平行,无角平分线" if parallel, "两直线重合" if coincident.
angle_bisector(p1: Point, p2: Point, p3: Point) -> Line
Purpose: angle bisector of angle p1-p2-p3 (p2 is the vertex).
triangle_median(tri: Triangle, vertex_label: int) -> Segment
Purpose: median from a vertex to the midpoint of the opposite side; vertex_label is the vertex index (0/1/2).
triangle_altitude(tri: Triangle, vertex_label: int) -> Line
Purpose: altitude from a vertex to the opposite side.
triangle_midsegment(tri: Triangle) -> Segment
Purpose: midsegment connecting the midpoints of two sides.
triangle_incircle(tri: Triangle) -> Circle
Purpose: incircle of a triangle.
triangle_excircle(tri: Triangle, vertex_label: int) -> Circle
Purpose: excircle tangent to one side and the extensions of the other two.
segment_from_points(p1: Point, p2: Point) -> Segment
Purpose: segment through two points.
Vectors
vector_from_points(pt1: Point, pt2: Point) -> tuple[Expr, Expr]
Purpose: vector (dx, dy) from pt1 to pt2.
vector_length(dx: str, dy: str, fs: dict) -> Expr
Purpose: norm of a vector; dx/dy are component strings.
vector_dot(v1_dx: str, v1_dy: str, v2_dx: str, v2_dy: str, fs: dict) -> Expr
Purpose: dot product of two vectors.
vector_angle(v1_dx: str, v1_dy: str, v2_dx: str, v2_dy: str, fs: dict) -> Expr
Purpose: angle between two vectors (radians).
area_by_coordinates(x1, y1, x2, y2, x3, y3, fs) -> Expr
Purpose: triangle area from three coordinate strings (determinant method).
Example
python
from functions.planes import get_planes_result
get_planes_result(0, ["0,0", "3,4"], {}) # distance -> 5
get_planes_result(14, ["0,0", "1,0", "0,1"], {}) # triangle area -> 1/2