Solid Geometry Calculation (functions/solids.py)
functions/solids.py provides 3D analytic geometry calculations (points, lines, planes, spatial vectors, tetrahedra, and the oblique projection / restoration of the "斜二测" axonometric drawing) as well as constructors for 3D objects (used by the definition page). Note: this module does not contain surface-area / volume formulas for spheres, cylinders, cones, prisms, pyramids, etc. — those are handled elsewhere by other feature pages. The public entry is get_solids_result (string interface); it also exports low-level helper functions that take sympy 3D geometry objects (Point3D, Line3D, Plane, ...) directly.
Note
For string-based calls use get_solids_result; the helpers below are for composing 3D geometry programmatically. The UI "Solid Geometry" definition page and the "Solid Geometry Calculation" page use the constructors / calculation functions of this module respectively.
get_solids_result — unified dispatch (string interface)
Purpose: call the matching 3D geometry computation by op_index; parameters are strings, parsed internally.
def get_solids_result(op_index, params, fs):
...
| Param | Type | Meaning |
|---|---|---|
op_index |
int |
operation index, matching solids_operation_list (0–36) |
params |
list[str] |
parameter list: points as "x,y,z", multiple points ";" separated |
fs |
dict |
function dictionary |
Returns: result (sympy expression / coordinate tuple / string); "计算错误: ..." on invalid parameters.
Operation list solids_operation_list
solids_operation_list is a string list of length 37, indexed by op_index:
| idx | op | idx | op |
|---|---|---|---|
| 0 | distance of two points | 19 | line projection on plane |
| 1 | midpoint | 20 | plane contains point |
| 2 | point-to-plane distance | 21 | plane contains line |
| 3 | point-to-line distance | 22 | tetrahedron volume |
| 4 | point projection on plane | 23 | vector of two points (3D) |
| 5 | point projection on line | 24 | vector norm (3D) |
| 6 | coplanarity check | 25 | vector dot (3D) |
| 7 | line direction vector | 26 | vector cross (3D) |
| 8 | line-line intersection | 27 | vector angle (3D) |
| 9 | angle between lines | 28 | line-plane angle |
| 10 | parallel check (line) | 29 | oblique project (single point) |
| 11 | perpendicular check (line) | 30 | oblique project (multi points) |
| 12 | plane equation from 3 points | 31 | oblique inverse transform |
| 13 | plane normal vector | 32 | area scale ratio |
| 14 | angle between planes | 33 | projected area -> original area |
| 15 | parallel check (plane) | 34 | original area -> projected area |
| 16 | perpendicular check (plane) | 35 | y-direction length restore factor |
| 17 | plane-plane intersection line | 36 | y-direction projected length |
| 18 | plane-line intersection |
Note
The UI "Solid Geometry Calculation" page offers 22 common operations among them (points, lines, planes, vectors, tetrahedra, etc.), implemented internally by the low-level functions below.
Geometry constructors (used by the definition page)
create_point3d(x: str, y: str, z: str, fs: dict) -> Point3D
Purpose: build a 3D point from coordinate strings.
create_line3d(pt1: Point3D, pt2: Point3D) -> Line3D
Purpose: build a 3D line through two points.
create_plane_three_points(p1: Point3D, p2: Point3D, p3: Point3D) -> Plane
Purpose: build a plane through three points.
create_plane_point_normal(pt: Point3D, nx: str, ny: str, nz: str, fs: dict) -> Plane
Purpose: build a plane from a point and normal-vector component strings.
Low-level helper functions
Note
The functions below take sympy 3D geometry objects (Point3D/Line3D/Plane from sympy.geometry) and return radsimp-simplified expressions or coordinate tuples.
Point operations
point3d_distance(pt1: Point3D, pt2: Point3D) -> Expr
Purpose: 3D distance between two points.
point3d_midpoint(pt1: Point3D, pt2: Point3D) -> tuple[Expr, Expr, Expr]
Purpose: 3D midpoint (x, y, z).
point3d_to_plane_distance(pt: Point3D, plane: Plane) -> Expr
Purpose: distance from a point to a plane.
point3d_to_line_distance(pt: Point3D, line: Line3D) -> Expr
Purpose: distance from a point to a 3D line.
point3d_projection_on_plane(pt: Point3D, plane: Plane) -> tuple[Expr, Expr, Expr]
Purpose: projection of a point onto a plane.
point3d_projection_on_line(pt: Point3D, line: Line3D) -> tuple[Expr, Expr, Expr]
Purpose: projection of a point onto a line.
are_coplanar(points: list[Point3D]) -> bool
Purpose: whether a set of points is coplanar (meaningful with ≥4 points).
Line operations
line3d_direction(line: Line3D) -> tuple[Expr, Expr, Expr]
Purpose: direction vector (dx, dy, dz) of a line.
line3d_intersection(l1: Line3D, l2: Line3D) -> tuple | str
Purpose: intersection of two lines; "两直线不相交" if disjoint, "两直线重合" if coincident.
line3d_angle(l1: Line3D, l2: Line3D) -> Expr
Purpose: angle between two lines (acute, radians).
line3d_parallel_check(l1: Line3D, l2: Line3D) -> bool
Purpose: whether two lines are parallel.
line3d_perpendicular_check(l1: Line3D, l2: Line3D) -> bool
Purpose: whether two lines are perpendicular.
line3d_projection_on_plane(line: Line3D, plane: Plane) -> tuple | str
Purpose: projection of a line onto a plane (direction vector and a point, or a description when it projects to a point).
Plane operations
plane_equation_from_points(p1: Point3D, p2: Point3D, p3: Point3D) -> Expr
Purpose: plane equation through three points.
plane_normal_vector(plane: Plane) -> tuple[Expr, Expr, Expr]
Purpose: normal vector (nx, ny, nz) of a plane.
plane_angle_between(pl1: Plane, pl2: Plane) -> Expr
Purpose: angle between two planes (acute, radians).
plane_parallel_check(pl1: Plane, pl2: Plane) -> bool
Purpose: whether two planes are parallel.
plane_perpendicular_check(pl1: Plane, pl2: Plane) -> bool
Purpose: whether two planes are perpendicular.
plane_intersection(pl1: Plane, pl2: Plane) -> tuple | str
Purpose: intersection line of two planes (direction vector and a point); "两平面平行" if parallel, "两平面重合" if coincident.
plane_line_intersection(plane: Plane, line: Line3D) -> tuple | str
Purpose: intersection of a plane and a line; "直线与平面平行" if parallel, "直线在平面上" if contained.
plane_projection_of_line(plane: Plane, line: Line3D) -> tuple | str
Purpose: projection of a line onto a plane (same as line3d_projection_on_plane).
plane_contains_point(plane: Plane, pt: Point3D) -> bool
Purpose: whether a plane contains a point.
plane_contains_line(plane: Plane, line: Line3D) -> bool
Purpose: whether a plane contains a line.
Tetrahedron
tetrahedron_volume(p1: Point3D, p2: Point3D, p3: Point3D, p4: Point3D) -> Expr
Purpose: volume of a tetrahedron from four vertices (|scalar triple product|/6).
Spatial vectors
vector3d_from_points(pt1: Point3D, pt2: Point3D) -> tuple[Expr, Expr, Expr]
Purpose: 3D vector (dx, dy, dz) from pt1 to pt2.
vector3d_length(dx: str, dy: str, dz: str, fs: dict) -> Expr
Purpose: norm of a 3D vector; dx/dy/dz are component strings.
vector3d_dot(v1_dx: str, v1_dy: str, v1_dz: str, v2_dx: str, v2_dy: str, v2_dz: str, fs: dict) -> Expr
Purpose: dot product of two 3D vectors; the 6 component strings of both vectors.
vector3d_cross(v1_dx, v1_dy, v1_dz, v2_dx, v2_dy, v2_dz, fs) -> tuple[Expr, Expr, Expr]
Purpose: cross product of two 3D vectors, returns (x, y, z).
vector3d_angle(v1_dx, v1_dy, v1_dz, v2_dx, v2_dy, v2_dz, fs) -> Expr
Purpose: angle between two 3D vectors (radians).
Line–plane relations
line_plane_angle(line: Line3D, plane: Plane) -> Expr
Purpose: angle between a line and a plane (radians, = π/2 − angle of direction vector with normal).
Geometric constructions (new objects from existing ones)
plane_parallel_through_point(plane: Plane, pt: Point3D) -> Plane
Purpose: plane parallel to a given plane through a point.
plane_perpendicular_to_line_through_point(line: Line3D, pt: Point3D) -> Plane
Purpose: plane perpendicular to a given line through a point (the line direction is the plane normal).
line_parallel_through_point_3d(line: Line3D, pt: Point3D) -> Line3D
Purpose: line parallel to a given line through a point.
line_perpendicular_to_plane_through_point(plane: Plane, pt: Point3D) -> Line3D
Purpose: line perpendicular to a given plane through a point.
plane_through_line_and_point(line: Line3D, pt: Point3D) -> Plane
Purpose: plane through a line and an external point.
plane_through_two_lines(l1: Line3D, l2: Line3D) -> Plane | str
Purpose: plane through two lines (must intersect or be parallel); "两直线重合" if coincident, "两直线异面,无法确定唯一平面" if skew.
perpendicular_foot_to_plane(pt: Point3D, plane: Plane) -> Point3D
Purpose: perpendicular foot from a point to a plane.
perpendicular_foot_to_line_3d(pt: Point3D, line: Line3D) -> Point3D
Purpose: perpendicular foot from a point to a line.
segment3d_from_points(p1: Point3D, p2: Point3D) -> Segment3D
Purpose: 3D segment through two points.
Oblique projection (斜二测)
oblique_project(pt: Point3D) -> tuple[Expr, Expr]
Purpose: project a single 3D point onto the 2D drawing plane, returns (X, Y) (x, z unchanged; y at 45° with half length).
oblique_project_points(points: list[Point3D]) -> list[tuple[Expr, Expr]]
Purpose: project multiple 3D points in batch.
oblique_restore_point(X: str, Y: str, z: str, fs: dict) -> tuple[Expr, Expr]
Purpose: inverse transform: from projected (X, Y) and known z, recover original (x, y).
oblique_area_ratio() -> tuple[Expr, str]
Purpose: returns the area scale factor √2/4 for horizontal-plane figures and a description.
oblique_restore_area(projected_area: str, fs: dict) -> Expr
Purpose: from projected area, recover original horizontal area S·2√2.
oblique_project_area(original_area: str, fs: dict) -> Expr
Purpose: from original horizontal area, compute projected area S·√2/4.
oblique_isometric_factor() -> Expr
Purpose: y-direction length restore factor 2√2.
oblique_project_length_y(original_length: str, fs: dict) -> Expr
Purpose: contribution length of an original y-direction length in the projection.
Example
python
from functions.solids import get_solids_result
get_solids_result(0, ["0,0,0", "1,2,2"], {}) # distance -> 3
get_solids_result(22, ["0,0,0;1,0,0;0,1,0;0,0,1"], {}) # tetrahedron volume -> 1/6
Note
Point strings use the format "x,y,z"; multiple points are separated by ";". The oblique-related operations (29–36) project 3D coordinates onto the 2D drawing plane using the 斜二测 convention or restore them in reverse.