[ SKILL_DOCUMENTATION ]
# SymPy 高级主题
本文档涵盖了 SymPy 的高级数学功能,包括几何、数论、组合数学、逻辑与集合、统计学、多项式和特殊函数。
## 几何
### 二维几何
python
from sympy.geometry import Point, Line, Circle, Triangle, Polygon
# 点
p1 = Point(0, 0)
p2 = Point(1, 1)
p3 = Point(1, 0)
# 点间距离
dist = p1.distance(p2)
# 直线
line = Line(p1, p2)
line_from_eq = Line(Point(0, 0), slope=2)
# 直线属性
line.slope # 斜率
line.equation() # 直线方程
line.length # oo (直线长度无限)
# 线段
from sympy.geometry import Segment
seg = Segment(p1, p2)
seg.length # 有限长度
seg.midpoint # 中点
# 交点
line2 = Line(Point(0, 1), Point(1, 0))
intersection = line.intersection(line2) # [Point(1/2, 1/2)]
# 圆
circle = Circle(Point(0, 0), 5) # 圆心,半径
circle.area # 25*pi
circle.circumference # 10*pi
# 三角形
tri = Triangle(p1, p2, p3)
tri.area # 面积
tri.perimeter # 周长
tri.angles # 角度字典
tri.vertices # 顶点元组
# 多边形
poly = Polygon(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1))
poly.area
poly.perimeter
poly.vertices
### 几何查询
python
# 检查点是否在直线/曲线上
point = Point(0.5, 0.5)
line.contains(point)
# 检查是否平行/垂直
line1 = Line(Point(0, 0), Point(1, 1))
line2 = Line(Point(0, 1), Point(1, 2))
line1.is_parallel(line2) # True
line1.is_perpendicular(line2) # False
# 切线
from sympy.geometry import Circle, Point
circle = Circle(Point(0, 0), 5)
point = Point(5, 0)
tangents = circle.tangent_lines(point)
### 三维几何
python
from sympy.geometry import Point3D, Line3D, Plane
# 3D 点
p1 = Point3D(0, 0, 0)
p2 = Point3D(1, 1, 1)
p3 = Point3D(1, 0, 0)
# 3D 直线
line = Line3D(p1, p2)
# 平面
plane = Plane(p1, p2, p3) # 通过 3 点定义
plane = Plane(Point3D(0, 0, 0), normal_vector=(1, 0, 0)) # 通过点和法向量定义
# 平面方程
plane.equation()
# 点到平面的距离
point = Point3D(2, 3, 4)
dist = plane.distance(point)
# 平面与直线的交点
intersection = plane.intersection(line)
### 曲线与椭圆
python
from sympy.geometry import Ellipse, Curve
from sympy import sin, cos, pi
# 椭圆
ellipse = Ellipse(Point(0, 0), hradius=3, vradius=2)
ellipse.area # 6*pi
ellipse.eccentricity # 离心率
# 参数化 c