SymPy-1-13-中文文档-二十三-
SymPy 1.13 中文文档(二十三)
曲线
class sympy.geometry.curve.Curve(function, limits)
空间中的曲线。
曲线由坐标的参数化函数、参数及其参数值的下限和上限定义。
参数:
function:函数列表
limits:3-元组
函数参数和下限及上限。
引发:
ValueError
当指定的(functions)不正确时。当指定的(limits)不正确时。
示例
>>> from sympy import Curve, sin, cos, interpolate
>>> from sympy.abc import t, a
>>> C = Curve((sin(t), cos(t)), (t, 0, 2))
>>> C.functions
(sin(t), cos(t))
>>> C.limits
(t, 0, 2)
>>> C.parameter
t
>>> C = Curve((t, interpolate([1, 4, 9, 16], t)), (t, 0, 1)); C
Curve((t, t**2), (t, 0, 1))
>>> C.subs(t, 4)
Point2D(4, 16)
>>> C.arbitrary_point(a)
Point2D(a, a**2)
另请参阅
sympy.core.function.Function
, sympy.polys.polyfuncs.interpolate
属性
functions | |
---|---|
参数 | |
限制 |
property ambient_dimension
曲线的维度。
返回:
int:
曲线的维度。
示例
>>> from sympy.abc import t
>>> from sympy import Curve
>>> C = Curve((t, t**2), (t, 0, 2))
>>> C.ambient_dimension
2
arbitrary_point(parameter='t')
曲线上的参数化点。
参数:
parameter:str 或 Symbol,可选
默认值为‘t’。如果未指定 None 或 self.parameter,则选择 Curve 的参数,否则使用提供的符号。
返回:
点:
返回以参数形式的点。
引发:
ValueError
当函数中已经出现(parameter)时。
示例
>>> from sympy import Curve, Symbol
>>> from sympy.abc import s
>>> C = Curve([2*s, s**2], (s, 0, 2))
>>> C.arbitrary_point()
Point2D(2*t, t**2)
>>> C.arbitrary_point(C.parameter)
Point2D(2*s, s**2)
>>> C.arbitrary_point(None)
Point2D(2*s, s**2)
>>> C.arbitrary_point(Symbol('a'))
Point2D(2*a, a**2)
另请参阅
sympy.geometry.point.Point
property free_symbols
返回除用于参数化定义 Curve 的绑定符号之外的符号集合。
返回:
集:
所有非参数化符号的集合。
示例
>>> from sympy.abc import t, a
>>> from sympy import Curve
>>> Curve((t, t**2), (t, 0, 2)).free_symbols
set()
>>> Curve((t, t**2), (t, a, 2)).free_symbols
{a}
property functions
指定曲线的函数。
返回:
functions:
参数化坐标函数的列表。
示例
>>> from sympy.abc import t
>>> from sympy import Curve
>>> C = Curve((t, t**2), (t, 0, 2))
>>> C.functions
(t, t**2)
另请参阅
parameter
property length
曲线长度。
示例
>>> from sympy import Curve
>>> from sympy.abc import t
>>> Curve((t, t), (t, 0, 1)).length
sqrt(2)
property limits
曲线的限制。
返回:
limits:元组
包含参数和下限和上限。
示例
>>> from sympy.abc import t
>>> from sympy import Curve
>>> C = Curve([t, t**3], (t, -2, 2))
>>> C.limits
(t, -2, 2)
另请参阅
plot_interval
property parameter
曲线函数变量。
返回:
符号:
返回绑定符号。
示例
>>> from sympy.abc import t
>>> from sympy import Curve
>>> C = Curve([t, t**2], (t, 0, 2))
>>> C.parameter
t
另请参阅
functions
plot_interval(parameter='t')
曲线的默认几何绘图的绘图间隔。
参数:
parameter :str 或 Symbol,可选
默认值为‘t’;否则使用提供的符号。
返回:
列表:
如下所示的绘图间隔:
[参数,下限,上限]
示例
>>> from sympy import Curve, sin
>>> from sympy.abc import x, s
>>> Curve((x, sin(x)), (x, 1, 2)).plot_interval()
[t, 1, 2]
>>> Curve((x, sin(x)), (x, 1, 2)).plot_interval(s)
[s, 1, 2]
另请参阅
limits
返回参数间隔的限制
rotate(angle=0, pt=None)
此函数用于沿给定点pt
以给定角度(以弧度表示)旋转曲线。
参数:
角度:
曲线将以逆时针方向旋转的角度(以弧度表示)。角度的默认值为 0。
pt:点
曲线将绕其旋转的点。如果未指定点,则曲线将围绕原点旋转。
返回:
曲线:
返回以给定角度沿给定点旋转的曲线。
示例
>>> from sympy import Curve, pi
>>> from sympy.abc import x
>>> Curve((x, x), (x, 0, 1)).rotate(pi/2)
Curve((-x, x), (x, 0, 1))
scale(x=1, y=1, pt=None)
重写 GeometryEntity.scale 方法,因为 Curve 不由点构成。
返回:
曲线:
返回缩放后的曲线。
示例
>>> from sympy import Curve
>>> from sympy.abc import x
>>> Curve((x, x), (x, 0, 1)).scale(2)
Curve((2*x, x), (x, 0, 1))
translate(x=0, y=0)
将曲线按 (x, y) 平移。
返回:
曲线:
返回平移后的曲线。
示例
>>> from sympy import Curve
>>> from sympy.abc import x
>>> Curve((x, x), (x, 0, 1)).translate(1, 2)
Curve((x + 1, x + 2), (x, 0, 1))
椭圆
class sympy.geometry.ellipse.Ellipse(center=None, hradius=None, vradius=None, eccentricity=None, **kwargs)
一个椭圆形的几何实体。
Parameters:
center : Point, optional
默认值为 Point(0, 0)
hradius : number or SymPy expression, optional
vradius : number or SymPy expression, optional
eccentricity : number or SymPy expression, optional
必须提供(hradius)、(vradius)中的两个来创建一个椭圆。第三个将从提供的两个中派生。
Raises:
GeometryError
当(hradius)、(vradius)和(eccentricity)作为参数被错误提供时。
TypeError
当(center)不是一个 Point 时。
Notes
由中心和两个半径构成,第一个是水平半径(沿 x 轴),第二个是垂直半径(沿 y 轴)。
当使用 hradius 和 vradius 的符号值时,任何引用焦点或主轴或次轴的计算都将假定椭圆的主半径在 x 轴上。如果这不是真的,则需要手动旋转。
Examples
>>> from sympy import Ellipse, Point, Rational
>>> e1 = Ellipse(Point(0, 0), 5, 1)
>>> e1.hradius, e1.vradius
(5, 1)
>>> e2 = Ellipse(Point(3, 1), hradius=3, eccentricity=Rational(4, 5))
>>> e2
Ellipse(Point2D(3, 1), 3, 9/5)
See also
Circle
Attributes
center | |
---|---|
hradius | |
vradius | |
area | |
circumference | |
eccentricity | |
periapsis | |
apoapsis | |
focus_distance | |
foci |
property apoapsis
椭圆的远日点。
焦点与轮廓之间的最大距离。
Returns:
apoapsis : number
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.apoapsis
2*sqrt(2) + 3
See also
periapsis
返回焦点与轮廓之间的最短距离
arbitrary_point(parameter='t')
椭圆上的参数化点。
Parameters:
parameter : str, optional
默认值为‘t’。
Returns:
arbitrary_point : Point
Raises:
ValueError
当(parameter)已经出现在函数中。
Examples
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.arbitrary_point()
Point2D(3*cos(t), 2*sin(t))
See also
sympy.geometry.point.Point
property area
椭圆的面积。
Returns:
area : number
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.area
3*pi
auxiliary_circle()
返回一个直径为椭圆长轴的圆。
Examples
>>> from sympy import Ellipse, Point, symbols
>>> c = Point(1, 2)
>>> Ellipse(c, 8, 7).auxiliary_circle()
Circle(Point2D(1, 2), 8)
>>> a, b = symbols('a b')
>>> Ellipse(c, a, b).auxiliary_circle()
Circle(Point2D(1, 2), Max(a, b))
property bounds
返回表示几何图形的边界矩形的元组 (xmin, ymin, xmax, ymax)。
property center
椭圆的中心。
Returns:
center : number
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.center
Point2D(0, 0)
See also
sympy.geometry.point.Point
property circumference
椭圆的面积。
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.circumference
12*elliptic_e(8/9)
director_circle()
返回由椭圆上的两条垂直切线相交处的所有点构成的圆。
Returns:
圆
作为几何对象返回的导向圆。
Examples
>>> from sympy import Ellipse, Point, symbols
>>> c = Point(3,8)
>>> Ellipse(c, 7, 9).director_circle()
Circle(Point2D(3, 8), sqrt(130))
>>> a, b = symbols('a b')
>>> Ellipse(c, a, b).director_circle()
Circle(Point2D(3, 8), sqrt(a**2 + b**2))
References
[R545]
en.wikipedia.org/wiki/Director_circle
property eccentricity
椭圆的离心率。
Returns:
eccentricity : number
Examples
>>> from sympy import Point, Ellipse, sqrt
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, sqrt(2))
>>> e1.eccentricity
sqrt(7)/3
encloses_point(p)
如果 p 被包含在(被内部的)self 中,则返回 True。
Parameters:
p : Point
Returns:
encloses_point : True, False or None
Notes
被视为不自交的边界。
示例
>>> from sympy import Ellipse, S
>>> from sympy.abc import t
>>> e = Ellipse((0, 0), 3, 2)
>>> e.encloses_point((0, 0))
True
>>> e.encloses_point(e.arbitrary_point(t).subs(t, S.Half))
False
>>> e.encloses_point((4, 0))
False
参见
sympy.geometry.point.Point
equation(x='x', y='y', _slope=None)
返回与 x 和 y 轴对齐的椭圆的方程;当给定斜率时,返回的方程对应于具有该斜率的主轴的椭圆。
参数:
x:字符串,可选
x 轴的标签。默认值为“x”。
y:字符串,可选
y 轴的标签。默认值为“y”。
_slope:表达式,可选
主轴的斜率。当为“None”时忽略。
返回:
方程:SymPy 表达式
示例
>>> from sympy import Point, Ellipse, pi
>>> from sympy.abc import x, y
>>> e1 = Ellipse(Point(1, 0), 3, 2)
>>> eq1 = e1.equation(x, y); eq1
y**2/4 + (x/3 - 1/3)**2 - 1
>>> eq2 = e1.equation(x, y, _slope=1); eq2
(-x + y + 1)**2/8 + (x + y - 1)**2/18 - 1
e1 上的一个点满足 eq1. 让我们使用 x 轴上的一个点:
>>> p1 = e1.center + Point(e1.major, 0)
>>> assert eq1.subs(x, p1.x).subs(y, p1.y) == 0
当与旋转后的椭圆相同旋转时,围绕椭圆的中心点,它也将满足旋转椭圆的方程:
>>> r1 = p1.rotate(pi/4, e1.center)
>>> assert eq2.subs(x, r1.x).subs(y, r1.y) == 0
参见
arbitrary_point
返回椭圆上参数化的点
参考文献
[R546]
[R547]
en.wikipedia.org/wiki/Ellipse#Shifted_ellipse
evolute(x='x', y='y')
椭圆的渐似曲线方程。
参数:
x:字符串,可选
x 轴的标签。默认值为“x”。
y:字符串,可选
y 轴的标签。默认值为“y”。
返回:
方程:SymPy 表达式
示例
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(1, 0), 3, 2)
>>> e1.evolute()
2**(2/3)*y**(2/3) + (3*x - 3)**(2/3) - 5**(2/3)
property foci
椭圆的焦点。
异常:
数值错误
当无法确定主轴和副轴时。
注意事项
只有在已知主/副轴的情况下才能计算焦点。
示例
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.foci
(Point2D(-2*sqrt(2), 0), Point2D(2*sqrt(2), 0))
参见
sympy.geometry.point.Point
focus_distance
返回焦点与中心之间的距离
property focus_distance
椭圆的焦距。
中心与一个焦点之间的距离。
返回:
focus_distance:数字
示例
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.focus_distance
2*sqrt(2)
参见
foci
property hradius
椭圆的水平半径。
返回:
hradius:数字
示例
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.hradius
3
参见
vradius
,major
,minor
intersection(o)
该椭圆与另一几何实体(o)的交点。
参数:
o:几何实体
返回:
交点:几何实体对象的列表
注意事项
目前支持与点、直线、线段、射线、圆和椭圆类型的交点。
示例
>>> from sympy import Ellipse, Point, Line
>>> e = Ellipse(Point(0, 0), 5, 7)
>>> e.intersection(Point(0, 0))
[]
>>> e.intersection(Point(5, 0))
[Point2D(5, 0)]
>>> e.intersection(Line(Point(0,0), Point(0, 1)))
[Point2D(0, -7), Point2D(0, 7)]
>>> e.intersection(Line(Point(5,0), Point(5, 1)))
[Point2D(5, 0)]
>>> e.intersection(Line(Point(6,0), Point(6, 1)))
[]
>>> e = Ellipse(Point(-1, 0), 4, 3)
>>> e.intersection(Ellipse(Point(1, 0), 4, 3))
[Point2D(0, -3*sqrt(15)/4), Point2D(0, 3*sqrt(15)/4)]
>>> e.intersection(Ellipse(Point(5, 0), 4, 3))
[Point2D(2, -3*sqrt(7)/4), Point2D(2, 3*sqrt(7)/4)]
>>> e.intersection(Ellipse(Point(100500, 0), 4, 3))
[]
>>> e.intersection(Ellipse(Point(0, 0), 3, 4))
[Point2D(3, 0), Point2D(-363/175, -48*sqrt(111)/175), Point2D(-363/175, 48*sqrt(111)/175)]
>>> e.intersection(Ellipse(Point(-1, 0), 3, 4))
[Point2D(-17/5, -12/5), Point2D(-17/5, 12/5), Point2D(7/5, -12/5), Point2D(7/5, 12/5)]
参见
sympy.geometry.entity.GeometryEntity
is_tangent(o)
o 是否切线于椭圆?
Parameters:
o : 几何实体
一个椭圆、线性实体或多边形
Returns:
是否为切线:布尔值
如果 o 切线于椭圆,则为 True,否则为 False。
Raises:
NotImplementedError
当提供错误类型的参数时。
Examples
>>> from sympy import Point, Ellipse, Line
>>> p0, p1, p2 = Point(0, 0), Point(3, 0), Point(3, 3)
>>> e1 = Ellipse(p0, 3, 2)
>>> l1 = Line(p1, p2)
>>> e1.is_tangent(l1)
True
See also
切线
property major
椭圆的长轴(如果可以确定)否则水平半径。
Returns:
major : 数字或表达式
Examples
>>> from sympy import Point, Ellipse, Symbol
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.major
3
>>> a = Symbol('a')
>>> b = Symbol('b')
>>> Ellipse(p1, a, b).major
a
>>> Ellipse(p1, b, a).major
b
>>> m = Symbol('m')
>>> M = m + 1
>>> Ellipse(p1, m, M).major
m + 1
See also
hradius
, vradius
, minor
property minor
椭圆的短轴(如果可以确定)否则垂直半径。
Returns:
minor : 数字或表达式
Examples
>>> from sympy import Point, Ellipse, Symbol
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.minor
1
>>> a = Symbol('a')
>>> b = Symbol('b')
>>> Ellipse(p1, a, b).minor
b
>>> Ellipse(p1, b, a).minor
a
>>> m = Symbol('m')
>>> M = m + 1
>>> Ellipse(p1, m, M).minor
m
See also
hradius
, vradius
, major
normal_lines(p, prec=None)
p 和椭圆之间的法线线。
Parameters:
p : 点
Returns:
法线线 : 包含 1、2 或 4 条线的列表
Examples
>>> from sympy import Point, Ellipse
>>> e = Ellipse((0, 0), 2, 3)
>>> c = e.center
>>> e.normal_lines(c + Point(1, 0))
[Line2D(Point2D(0, 0), Point2D(1, 0))]
>>> e.normal_lines(c)
[Line2D(Point2D(0, 0), Point2D(0, 1)), Line2D(Point2D(0, 0), Point2D(1, 0))]
离轴点需要解四次方程的解。这通常会导致非常大的表达式,可能在实际使用中没有太多实际用途。可以通过传入所需值来获得精确到 prec 位数的近似解:
>>> e.normal_lines((3, 3), prec=2)
[Line2D(Point2D(-0.81, -2.7), Point2D(0.19, -1.2)),
Line2D(Point2D(1.5, -2.0), Point2D(2.5, -2.7))]
而上述解决方案的操作计数为 12,确切解决方案的操作计数为 2020。
property periapsis
椭圆的近地点。
焦点到轮廓之间的最短距离。
Returns:
近地点 : 数字
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.periapsis
3 - 2*sqrt(2)
See also
远地点
返回焦点与轮廓之间的最大距离
plot_interval(parameter='t')
椭圆默认几何图的绘图间隔。
Parameters:
参数 : 字符串,可选
默认值为‘t’。
Returns:
plot_interval : 列表
[参数, 下界, 上界]
Examples
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.plot_interval()
[t, -pi, pi]
polar_second_moment_of_area()
返回椭圆的极性二阶矩
它是通过垂直轴定理与平面截面的第二矩相关。虽然平面截面的第二矩描述了物体在平行于中心轴的平面上施加力时的抵抗(弯曲)情况,极性截面的第二矩描述了物体在施加在垂直于物体中心轴的平面上的力矩时的抵抗情况(即与横截面平行)。
Examples
>>> from sympy import symbols, Circle, Ellipse
>>> c = Circle((5, 5), 4)
>>> c.polar_second_moment_of_area()
128*pi
>>> a, b = symbols('a, b')
>>> e = Ellipse((0, 0), a, b)
>>> e.polar_second_moment_of_area()
pi*a**3*b/4 + pi*a*b**3/4
References
[R548]
random_point(seed=None)
椭圆上的一个随机点。
返回:
point:点
示例
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.random_point() # gives some random point
Point2D(...)
>>> p1 = e1.random_point(seed=0); p1.n(2)
Point2D(2.1, 1.4)
注意事项
当创建随机点时,可以简单地用随机数替换参数。但是,随机数应该是有理数,否则该点可能无法测试为在椭圆内:
>>> from sympy.abc import t
>>> from sympy import Rational
>>> arb = e1.arbitrary_point(t); arb
Point2D(3*cos(t), 2*sin(t))
>>> arb.subs(t, .1) in e1
False
>>> arb.subs(t, Rational(.1)) in e1
True
>>> arb.subs(t, Rational('.1')) in e1
True
另见
sympy.geometry.point.Point
arbitrary_point
返回椭圆上参数化的点
reflect(line)
覆盖 GeometryEntity.reflect,因为半径不是 GeometryEntity。
示例
>>> from sympy import Circle, Line
>>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1)))
Circle(Point2D(1, 0), -1)
>>> from sympy import Ellipse, Line, Point
>>> Ellipse(Point(3, 4), 1, 3).reflect(Line(Point(0, -4), Point(5, 0)))
Traceback (most recent call last):
...
NotImplementedError:
General Ellipse is not supported but the equation of the reflected
Ellipse is given by the zeros of: f(x, y) = (9*x/41 + 40*y/41 +
37/41)**2 + (40*x/123 - 3*y/41 - 364/123)**2 - 1
注意事项
在一般的椭圆(没有轴平行于 x 轴)得到支持之前,会引发 NotImplemented 错误,并给出定义旋转椭圆零点的方程。
rotate(angle=0, pt=None)
以 Point pt
为中心,逆时针旋转angle
弧度。
注意:由于不支持一般椭圆,因此只允许整数倍于 pi/2 的旋转。
示例
>>> from sympy import Ellipse, pi
>>> Ellipse((1, 0), 2, 1).rotate(pi/2)
Ellipse(Point2D(0, 1), 1, 2)
>>> Ellipse((1, 0), 2, 1).rotate(pi)
Ellipse(Point2D(-1, 0), 2, 1)
scale(x=1, y=1, pt=None)
覆盖 GeometryEntity.scale,因为需要缩放的是长轴和短轴,它们不是 GeometryEntities。
示例
>>> from sympy import Ellipse
>>> Ellipse((0, 0), 2, 1).scale(2, 4)
Circle(Point2D(0, 0), 4)
>>> Ellipse((0, 0), 2, 1).scale(2)
Ellipse(Point2D(0, 0), 4, 1)
second_moment_of_area(point=None)
返回椭圆的第二矩和乘积矩的面积。
参数:
point:点,两个可以符号化的对象的二元组,或者为 None(默认为 None)。
point 是要找到面积第二矩的点。如果“point=None”,则将围绕椭圆重心通过的轴计算。
返回:
I_xx,I_yy,I_xy:数字或 SymPy 表达式
I_xx,I_yy 是椭圆的二阶矩。I_xy 是椭圆的乘积矩。
示例
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.second_moment_of_area()
(3*pi/4, 27*pi/4, 0)
参考文献
[R549]
en.wikipedia.org/wiki/List_of_second_moments_of_area
section_modulus(point=None)
返回椭圆的截面模量的元组
截面模量是椭圆的一个几何属性,定义为面积的第二矩与椭圆极端端点到重心轴的距离的比率。
参数:
point:点,两个可以符号化的对象的二元组,或者为 None(默认为 None)。
point 是要找到截面模量的点。如果“point=None”,则将为离椭圆重心轴最远的点计算截面模量。
返回:
S_x,S_y:数字或 SymPy 表达式
S_x 是相对于 x 轴的截面模量,S_y 是相对于 y 轴的截面模量。负号表示截面模量是为重心轴以下的点确定的。
示例
>>> from sympy import Symbol, Ellipse, Circle, Point2D
>>> d = Symbol('d', positive=True)
>>> c = Circle((0, 0), d/2)
>>> c.section_modulus()
(pi*d**3/32, pi*d**3/32)
>>> e = Ellipse(Point2D(0, 0), 2, 4)
>>> e.section_modulus()
(8*pi, 4*pi)
>>> e.section_modulus((2, 2))
(16*pi, 4*pi)
参考文献
[R550]
en.wikipedia.org/wiki/Section_modulus
property semilatus_rectum
计算椭圆的半准线。
半准线被定义为通过焦点平行于圆锥截面直线的一半弦。
返回:
semilatus_rectum:数字
示例
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.semilatus_rectum
1/3
另见
apoapsis
返回焦点和轮廓之间的最大距离
近日点
焦点和轮廓之间的最短距离
参考文献
[R551]
mathworld.wolfram.com/SemilatusRectum.html
[R552]
tangent_lines(p)
点(p)与椭圆之间的切线。
若(p)在椭圆上,则返回通过点(p)的切线。否则,返回从(p)到椭圆的切线(或如果无法找到切线则返回 None,例如(p)在椭圆内部)。
参数:
p:点
返回:
切线:带有 1 或 2 条线的列表
异常:
未实现错误
仅能找到椭圆上一点(p)的切线。
示例
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.tangent_lines(Point(3, 0))
[Line2D(Point2D(3, 0), Point2D(3, -12))]
另请参见
sympy.geometry.point.Point
,sympy.geometry.line.Line
property vradius
椭圆的垂直半径。
返回:
垂直半径:数字
示例
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.vradius
1
另请参见
水平半径
,主要
,次要
class sympy.geometry.ellipse.Circle(*args, **kwargs)
空间中的一个圆。
可简单从一个中心和一个半径、三个不共线点或圆的方程式构造。
参数:
中心:点
半径:数字或 SymPy 表达式
点:三个点的序列
方程:圆的方程
异常:
几何错误
当给定方程不是圆的情况下。尝试从不正确的参数构造圆时。
示例
>>> from sympy import Point, Circle, Eq
>>> from sympy.abc import x, y, a, b
由中心和半径构造的圆:
>>> c1 = Circle(Point(0, 0), 5)
>>> c1.hradius, c1.vradius, c1.radius
(5, 5, 5)
由三个点构造的圆:
>>> c2 = Circle(Point(0, 0), Point(1, 1), Point(1, 0))
>>> c2.hradius, c2.vradius, c2.radius, c2.center
(sqrt(2)/2, sqrt(2)/2, sqrt(2)/2, Point2D(1/2, 1/2))
也可以从形式为(a*x2 + by2 + gx + hy + c = 0)的方程式构造一个圆:
>>> Circle(x**2 + y**2 - 25)
Circle(Point2D(0, 0), 5)
如果对应于 x 和 y 的变量命名为其他名称,则可以提供它们的名称或符号:
>>> Circle(Eq(a**2 + b**2, 25), x='a', y=b)
Circle(Point2D(0, 0), 5)
另请参见
椭圆
,sympy.geometry.point.Point
属性
半径(与水平半径、垂直半径、主轴和次轴同义) | |
---|---|
周长 | |
方程 |
property circumference
圆的周长。
返回:
周长:数字或 SymPy 表达式
示例
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.circumference
12*pi
equation(x='x', y='y')
圆的方程式。
参数:
x:str 或 Symbol,可选
默认值为‘x’。
y:str 或 Symbol,可选
默认值为‘y’。
返回:
方程式:SymPy 表达式
示例
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(0, 0), 5)
>>> c1.equation()
x**2 + y**2 - 25
intersection(o)
该圆与另一个几何实体的交点。
参数:
o:几何实体
返回:
交点:几何实体的列表
示例
>>> from sympy import Point, Circle, Line, Ray
>>> p1, p2, p3 = Point(0, 0), Point(5, 5), Point(6, 0)
>>> p4 = Point(5, 0)
>>> c1 = Circle(p1, 5)
>>> c1.intersection(p2)
[]
>>> c1.intersection(p4)
[Point2D(5, 0)]
>>> c1.intersection(Ray(p1, p2))
[Point2D(5*sqrt(2)/2, 5*sqrt(2)/2)]
>>> c1.intersection(Line(p2, p3))
[]
property radius
圆的半径。
返回:
半径:数字或 SymPy 表达式
示例
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.radius
6
参见
Ellipse.major
, Ellipse.minor
, Ellipse.hradius
, Ellipse.vradius
reflect(line)
覆盖 GeometryEntity.reflect
,因为半径不是 GeometryEntity
。
示例
>>> from sympy import Circle, Line
>>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1)))
Circle(Point2D(1, 0), -1)
scale(x=1, y=1, pt=None)
覆盖 GeometryEntity.scale
,因为半径不是 GeometryEntity
。
示例
>>> from sympy import Circle
>>> Circle((0, 0), 1).scale(2, 2)
Circle(Point2D(0, 0), 2)
>>> Circle((0, 0), 1).scale(2, 4)
Ellipse(Point2D(0, 0), 2, 4)
property vradius
此椭圆属性是圆半径的别名。
尽管 hradius
、major
和 minor
可以使用椭圆的约定,但是 vradius
对于圆而言不存在。它始终是一个正值,以便像多边形一样,圆的面积可以根据 hradius
的符号为正或负。
示例
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.vradius
6
多边形
class sympy.geometry.polygon.Polygon(*args, n=0, **kwargs)
二维多边形。
一个空间中的简单多边形。可以从一系列点或从中心、半径、边数和旋转角度构造。
参数:
顶点
一系列点。
n:整数,可选
如果 (> 0),则创建一个 n 边的正多边形。默认值为 (0)。
抛出:
几何错误
如果所有参数都不是点。
注意
多边形被视为封闭路径,而不是 2D 区域,因此一些计算可以基于点的方向是负数或正数(例如,面积)。
任何连续相同的点都会被减少为一个点,并且任何共线且位于两点之间的点都将被移除,除非它们需要定义显式交点(参见示例)。
当提供的点数为 3 个或更少时,将返回一个三角形、线段或点。
示例
>>> from sympy import Polygon, pi
>>> p1, p2, p3, p4, p5 = [(0, 0), (1, 0), (5, 1), (0, 1), (3, 0)]
>>> Polygon(p1, p2, p3, p4)
Polygon(Point2D(0, 0), Point2D(1, 0), Point2D(5, 1), Point2D(0, 1))
>>> Polygon(p1, p2)
Segment2D(Point2D(0, 0), Point2D(1, 0))
>>> Polygon(p1, p2, p5)
Segment2D(Point2D(0, 0), Point2D(3, 0))
多边形的面积在顶点沿逆时针方向遍历时被计算为正数。当多边形的边相交时,面积将具有正数和负数的贡献。以下定义了一个 Z 形状,其中右下角连接回左上角。
>>> Polygon((0, 2), (2, 2), (0, 0), (2, 0)).area
0
当关键词 (n) 用于定义多边形的边数时,将创建一个正多边形,并将其他参数解释为中心、半径和旋转。未旋转的正多边形始终在点( (r, 0) )处具有一个顶点,其中 (r) 是围绕正多边形的圆的半径。其方法 (spin) 可用于增加该角度。
>>> p = Polygon((0,0), 1, n=3)
>>> p
RegularPolygon(Point2D(0, 0), 1, 3, 0)
>>> p.vertices[0]
Point2D(1, 0)
>>> p.args[0]
Point2D(0, 0)
>>> p.spin(pi/2)
>>> p.vertices[0]
Point2D(0, 1)
另请参阅
sympy.geometry.point.Point
,sympy.geometry.line.Segment
,Triangle
属性
面积 | |
---|---|
角度 | |
周长 | |
顶点 | |
重心 | |
边数 |
property angles
每个顶点处的内角。
返回:
角度:字典
一个字典,其中每个键是一个顶点,每个值是该顶点处的内角。这些顶点表示为点。
示例
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.angles[p1]
pi/2
>>> poly.angles[p2]
acos(-4*sqrt(17)/17)
另请参阅
sympy.geometry.point.Point
,sympy.geometry.line.LinearEntity.angle_between
arbitrary_point(parameter='t')
多边形上的参数化点。
参数,从 0 到 1 变化,将点分配到周长上的位置,即总周长的分数部分。因此,在 (t=1/2) 处评估的点将返回围绕多边形一半的第一个顶点的点。
参数:
参数:字符串,可选
默认值为‘t’。
返回:
任意点:点
抛出:
数值错误
当多边形的定义中已经出现 (parameter) 时。
示例
>>> from sympy import Polygon, Symbol
>>> t = Symbol('t', real=True)
>>> tri = Polygon((0, 0), (1, 0), (1, 1))
>>> p = tri.arbitrary_point('t')
>>> perimeter = tri.perimeter
>>> s1, s2 = [s.length for s in tri.sides[:2]]
>>> p.subs(t, (s1 + s2/2)/perimeter)
Point2D(1, 1/2)
另请参阅
sympy.geometry.point.Point
property area
多边形的面积。
注意事项
根据点的定位,区域计算可能为正或负。如果多边形的任一边穿过其他边,则将存在具有相反符号的区域。
示例
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.area
3
在 Z 形多边形中(右下角连接回左上角),区域相互抵消:
>>> Z = Polygon((0, 1), (1, 1), (0, 0), (1, 0))
>>> Z.area
0
在 M 形多边形中,区域不会取消,因为没有一条边穿过其他边(尽管存在接触点)。
>>> M = Polygon((0, 0), (0, 1), (2, 0), (3, 1), (3, 0))
>>> M.area
-3/2
另请参阅
sympy.geometry.ellipse.Ellipse.area
bisectors(prec=None)
返回多边形的角平分线。如果给定 prec,则将点定义为该精度的近似点。
定义角分隔线段的点之间的距离为 1。
示例
>>> from sympy import Polygon, Point
>>> p = Polygon(Point(0, 0), Point(2, 0), Point(1, 1), Point(0, 3))
>>> p.bisectors(2)
{Point2D(0, 0): Ray2D(Point2D(0, 0), Point2D(0.71, 0.71)),
Point2D(0, 3): Ray2D(Point2D(0, 3), Point2D(0.23, 2.0)),
Point2D(1, 1): Ray2D(Point2D(1, 1), Point2D(0.19, 0.42)),
Point2D(2, 0): Ray2D(Point2D(2, 0), Point2D(1.1, 0.38))}
property bounds
返回一个元组 (xmin, ymin, xmax, ymax),表示几何图形的边界矩形。
property centroid
多边形的质心。
返回:
质心 : 点
示例
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.centroid
Point2D(31/18, 11/18)
另请参阅
sympy.geometry.point.Point
, sympy.geometry.util.centroid
cut_section(line)
返回一个包含与交叉线上方和下方的两个多边形段的元组。
参数:
line: 几何模块中的线对象
切割多边形的线。返回位于该线上方和下方的多边形的部分。
返回:
upper_polygon, lower_polygon:多边形对象或 None
上多边形是位于给定线上方的多边形。下多边形是位于给定线下方的多边形。当线上方或线下方不存在多边形时,上多边形和下多边形均为
None
。
抛出异常:
ValueError: 当线段不与多边形相交时
示例
>>> from sympy import Polygon, Line
>>> a, b = 20, 10
>>> p1, p2, p3, p4 = [(0, b), (0, 0), (a, 0), (a, b)]
>>> rectangle = Polygon(p1, p2, p3, p4)
>>> t = rectangle.cut_section(Line((0, 5), slope=0))
>>> t
(Polygon(Point2D(0, 10), Point2D(0, 5), Point2D(20, 5), Point2D(20, 10)),
Polygon(Point2D(0, 5), Point2D(0, 0), Point2D(20, 0), Point2D(20, 5)))
>>> upper_segment, lower_segment = t
>>> upper_segment.area
100
>>> upper_segment.centroid
Point2D(10, 15/2)
>>> lower_segment.centroid
Point2D(10, 5/2)
参考资料
[R553]
[ github.com/sympy/sympy/wiki/A-method-to-return-a-cut-section-of-any-polygon-geometry
distance(o)
返回自身与 o 之间的最短距离。
如果 o 是一个点,则 self 不需要是凸的。如果 o 是另一个多边形,则 self 和 o 必须是凸的。
示例
>>> from sympy import Point, Polygon, RegularPolygon
>>> p1, p2 = map(Point, [(0, 0), (7, 5)])
>>> poly = Polygon(*RegularPolygon(p1, 1, 3).vertices)
>>> poly.distance(p2)
sqrt(61)
encloses_point(p)
如果 p 被包含在 self 中(即在内部),则返回 True。
参数:
p : 点
返回:
encloses_point : True, False 或 None
注意事项
被视为位于自身边界上为 False。
示例
>>> from sympy import Polygon, Point
>>> p = Polygon((0, 0), (4, 0), (4, 4))
>>> p.encloses_point(Point(2, 1))
True
>>> p.encloses_point(Point(2, 2))
False
>>> p.encloses_point(Point(5, 5))
False
另请参阅
sympy.geometry.point.Point
, sympy.geometry.ellipse.Ellipse.encloses_point
参考资料
[R554]
paulbourke.net/geometry/polygonmesh/#insidepoly
first_moment_of_area(point=None)
返回关于特定兴趣点的二维多边形的第一矩。
面积的第一矩是多边形面积相对于轴的分布的度量。整个多边形关于其自身的质心的第一矩总是零。因此,这里计算了关于感兴趣点上方或下方构成多边形的一小部分的面积的第一矩。该区域由感兴趣点和多边形的极端端点(顶部或底部)界定。然后计算了该区域关于初始多边形的质心轴的第一矩。
参数:
point: Point, two-tuple of sympifyable objects, or None (default=None)
点是感兴趣区域上方或下方的点。如果
point=None
,则质心充当感兴趣点。
返回:
Q_x, Q_y: 数字或 SymPy 表达式
Q_x 是关于 x 轴的面积的第一矩 Q_y 是关于 y 轴的面积的第一矩 负号表示截面模量是为负的(或在质心轴的左侧)。
示例
>>> from sympy import Point, Polygon
>>> a, b = 50, 10
>>> p1, p2, p3, p4 = [(0, b), (0, 0), (a, 0), (a, b)]
>>> p = Polygon(p1, p2, p3, p4)
>>> p.first_moment_of_area()
(625, 3125)
>>> p.first_moment_of_area(point=Point(30, 7))
(525, 3000)
参考文献
[R555]
[R556]
mechanicalc.com/reference/cross-sections
intersection(o)
多边形与几何实体的交点。
交点可能为空,可以包含单独的点和完整的线段。
参数:
other: GeometryEntity
返回:
intersection : 列表
线段和点的列表
示例
>>> from sympy import Point, Polygon, Line
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly1 = Polygon(p1, p2, p3, p4)
>>> p5, p6, p7 = map(Point, [(3, 2), (1, -1), (0, 2)])
>>> poly2 = Polygon(p5, p6, p7)
>>> poly1.intersection(poly2)
[Point2D(1/3, 1), Point2D(2/3, 0), Point2D(9/5, 1/5), Point2D(7/3, 1)]
>>> poly1.intersection(Line(p1, p2))
[Segment2D(Point2D(0, 0), Point2D(1, 0))]
>>> poly1.intersection(p1)
[Point2D(0, 0)]
另见
sympy.geometry.point.Point
, sympy.geometry.line.Segment
is_convex()
多边形是否是凸的?
多边形凸多边形的内角小于 180 度且边之间没有交叉。
返回:
is_convex : 布尔值
如果多边形是凸的则为 True,否则为 False。
示例
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.is_convex()
True
另见
sympy.geometry.util.convex_hull
property perimeter
多边形的周长。
返回:
perimeter : 数字或 Basic 实例
示例
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.perimeter
sqrt(17) + 7
另见
sympy.geometry.line.Segment.length
plot_interval(parameter='t')
默认几何图形绘制多边形的绘图间隔。
参数:
parameter : 字符串,可选
默认值是‘t’。
返回:
plot_interval : 列表(绘图间隔)
[parameter, lower_bound, upper_bound]
示例
>>> from sympy import Polygon
>>> p = Polygon((0, 0), (1, 0), (1, 1))
>>> p.plot_interval()
[t, 0, 1]
polar_second_moment_of_area()
返回二维多边形的极坐标模量
它是截面惯性矩的组成部分,通过垂直轴定理相连。平面截面惯性矩描述了物体在受力作用于与中心轴平行的平面时的抗挠性(弯曲),而极点截面惯性矩描述了物体在受力作用于垂直于物体中心轴的平面(即与横截面平行)时的抗挠性。
示例
>>> from sympy import Polygon, symbols
>>> a, b = symbols('a, b')
>>> rectangle = Polygon((0, 0), (a, 0), (a, b), (0, b))
>>> rectangle.polar_second_moment_of_area()
a**3*b/12 + a*b**3/12
参考文献
[R557]
en.wikipedia.org/wiki/Polar_moment_of_inertia
second_moment_of_area(point=None)
返回二维多边形的第二矩和产品矩。
参数:
point:Point,两个可用 sympify 对象的元组,或 None(默认为 None)
point 是需要找到截面惯性矩的点。如果“point=None”,则会计算通过多边形质心的轴的截面惯性矩。
返回:
I_xx, I_yy, I_xy:数字或 SymPy 表达式
I_xx, I_yy 是二维多边形的截面惯性矩。I_xy 是二维多边形的产品惯性矩。
示例
>>> from sympy import Polygon, symbols
>>> a, b = symbols('a, b')
>>> p1, p2, p3, p4, p5 = [(0, 0), (a, 0), (a, b), (0, b), (a/3, b/3)]
>>> rectangle = Polygon(p1, p2, p3, p4)
>>> rectangle.second_moment_of_area()
(a*b**3/12, a**3*b/12, 0)
>>> rectangle.second_moment_of_area(p5)
(a*b**3/9, a**3*b/9, a**2*b**2/36)
参考文献
[R558]
en.wikipedia.org/wiki/Second_moment_of_area
section_modulus(point=None)
返回一个包含二维多边形截面模量的元组。
截面模量是多边形的几何特性,定义为截面惯性矩与多边形端点到质心轴距离的比值。
参数:
point:Point,两个可用 sympify 对象的元组,或 None(默认为 None)
point 是需要找到截面模量的点。如果“point=None”,则会计算距离多边形质心轴最远的点的截面模量。
返回:
S_x, S_y:数字或 SymPy 表达式
S_x 是相对于 x 轴的截面模量,S_y 是相对于 y 轴的截面模量。负号表示截面模量是针对质心轴下方一点确定的。
示例
>>> from sympy import symbols, Polygon, Point
>>> a, b = symbols('a, b', positive=True)
>>> rectangle = Polygon((0, 0), (a, 0), (a, b), (0, b))
>>> rectangle.section_modulus()
(a*b**2/6, a**2*b/6)
>>> rectangle.section_modulus(Point(a/4, b/4))
(-a*b**2/3, -a**2*b/3)
参考文献
[R559]
en.wikipedia.org/wiki/Section_modulus
property sides
形成多边形边的有向线段。
返回:
sides:边的列表
每条边都是一个有向线段。
示例
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.sides
[Segment2D(Point2D(0, 0), Point2D(1, 0)),
Segment2D(Point2D(1, 0), Point2D(5, 1)),
Segment2D(Point2D(5, 1), Point2D(0, 1)), Segment2D(Point2D(0, 1), Point2D(0, 0))]
参见
sympy.geometry.point.Point
,sympy.geometry.line.Segment
property vertices
多边形的顶点。
返回:
vertices:点的列表
注意
在迭代顶点时,比起请求顶点并对其进行索引,直接使用 self 更有效率。只有在想一次性处理所有顶点时才使用顶点。这在计算每个顶点的 RegularPolygons 时尤为重要。
示例
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.vertices
[Point2D(0, 0), Point2D(1, 0), Point2D(5, 1), Point2D(0, 1)]
>>> poly.vertices[0]
Point2D(0, 0)
参见
sympy.geometry.point.Point
class sympy.geometry.polygon.RegularPolygon(c, r, n, rot=0, **kwargs)
一个正多边形。
这样的多边形所有内角相等,所有边相同长度。
参数:
中心:点
半径:数字或基本实例
从中心到顶点的距离
n:整数
边数
异常
几何错误
如果(中心)不是一个点,或(半径)不是数字或基本实例,或者边数(n)小于三。
注释
用关键字参数 n 实例化多边形 Polygon。
常规多边形用中心、半径、边数和旋转角度实例化。与多边形的参数为顶点不同,常规多边形的顶点必须通过顶点方法获取。
示例
>>> from sympy import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r
RegularPolygon(Point2D(0, 0), 5, 3, 0)
>>> r.vertices[0]
Point2D(5, 0)
参见
sympy.geometry.point.Point
, 多边形
属性
顶点 | |
---|---|
中心 | |
半径 | |
旋转 | |
缩径 | |
内角 | |
外角 | |
外接圆 | |
内切圆 | |
角度 |
property angles
返回字典,键为多边形的顶点,值为每个顶点的内角。
示例
>>> from sympy import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r.angles
{Point2D(-5/2, -5*sqrt(3)/2): pi/3,
Point2D(-5/2, 5*sqrt(3)/2): pi/3,
Point2D(5, 0): pi/3}
property apothem
常规多边形的内接圆半径。
顶点距离/内接圆半径为内接圆的半径。
返回:
缩径:数字或基本实例
示例
>>> from sympy import Symbol
>>> from sympy import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.apothem
sqrt(2)*r/2
参见
sympy.geometry.line.Segment.length
, sympy.geometry.ellipse.Circle.radius
property area
返回面积。
示例
>>> from sympy import RegularPolygon
>>> square = RegularPolygon((0, 0), 1, 4)
>>> square.area
2
>>> _ == square.length**2
True
property args
返回中心点、半径、边数和方向角。
示例
>>> from sympy import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r.args
(Point2D(0, 0), 5, 3, 0)
property center
常规多边形的中心
这也是外接圆的中心。
返回:
中心:点
示例
>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.center
Point2D(0, 0)
参见
sympy.geometry.point.Point
, sympy.geometry.ellipse.Ellipse.center
property centroid
常规多边形的中心
这也是外接圆的中心。
返回:
中心:点
示例
>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.center
Point2D(0, 0)
参见
sympy.geometry.point.Point
, sympy.geometry.ellipse.Ellipse.center
property circumcenter
别名为中心。
示例
>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.circumcenter
Point2D(0, 0)
property circumcircle
常规多边形的外接圆。
返回:
外接圆:圆
示例
>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.circumcircle
Circle(Point2D(0, 0), 4)
参见
外接圆心
, sympy.geometry.ellipse.Circle
property circumradius
别名为半径。
示例
>>> from sympy import Symbol
>>> from sympy import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.circumradius
r
encloses_point(p)
如果 p 被包围(在内部)则返回 True。
参数:
p:点
返回:
包含点:是、否或无
注释
被认为不在自身边界上是 False。
如果点不在内切圆或外接圆内,只有在一般的 Polygon.encloses_point 方法被调用时才返回。
示例
>>> from sympy import RegularPolygon, S, Point, Symbol
>>> p = RegularPolygon((0, 0), 3, 4)
>>> p.encloses_point(Point(0, 0))
True
>>> r, R = p.inradius, p.circumradius
>>> p.encloses_point(Point((r + R)/2, 0))
True
>>> p.encloses_point(Point(R/2, R/2 + (R - r)/10))
False
>>> t = Symbol('t', real=True)
>>> p.encloses_point(p.arbitrary_point().subs(t, S.Half))
False
>>> p.encloses_point(Point(5, 5))
False
另请参阅
sympy.geometry.ellipse.Ellipse.encloses_point
property exterior_angle
外角的测量。
返回:
外角:数字
示例
>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.exterior_angle
pi/4
另请参阅
sympy.geometry.line.LinearEntity.angle_between
property incircle
RegularPolygon 的内切圆。
返回:
内切圆:Circle
示例
>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 7)
>>> rp.incircle
Circle(Point2D(0, 0), 4*cos(pi/7))
另请参阅
inradius
, sympy.geometry.ellipse.Circle
property inradius
apothem 的别名。
示例
>>> from sympy import Symbol
>>> from sympy import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.inradius
sqrt(2)*r/2
property interior_angle
内角的测量。
返回:
内角:数字
示例
>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.interior_angle
3*pi/4
另请参阅
sympy.geometry.line.LinearEntity.angle_between
property length
返回边长。
边长的一半和辅角形成一个直角三角形,其斜边是正多边形的半径。
示例
>>> from sympy import RegularPolygon
>>> from sympy import sqrt
>>> s = square_in_unit_circle = RegularPolygon((0, 0), 1, 4)
>>> s.length
sqrt(2)
>>> sqrt((_/2)**2 + s.apothem**2) == s.radius
True
property radius
RegularPolygon 的半径
这也是外接圆的半径。
返回:
半径:数字或 Basic 的实例
示例
>>> from sympy import Symbol
>>> from sympy import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.radius
r
另请参阅
sympy.geometry.line.Segment.length
, sympy.geometry.ellipse.Circle.radius
reflect(line)
由于这不仅仅是点的集合,所以覆盖 GeometryEntity.reflect 方法。
示例
>>> from sympy import RegularPolygon, Line
>>> RegularPolygon((0, 0), 1, 4).reflect(Line((0, 1), slope=-2))
RegularPolygon(Point2D(4/5, 2/5), -1, 4, atan(4/3))
rotate(angle, pt=None)
覆盖 GeometryEntity.rotate 方法,首先围绕其中心旋转 RegularPolygon。
>>> from sympy import Point, RegularPolygon, pi
>>> t = RegularPolygon(Point(1, 0), 1, 3)
>>> t.vertices[0] # vertex on x-axis
Point2D(2, 0)
>>> t.rotate(pi/2).vertices[0] # vertex on y axis now
Point2D(0, 2)
另请参阅
rotation
spin
原地旋转 RegularPolygon
property rotation
RegularPolygon 的逆时针角度。
返回:
旋转:数字或 Basic 的实例
示例
>>> from sympy import pi
>>> from sympy.abc import a
>>> from sympy import RegularPolygon, Point
>>> RegularPolygon(Point(0, 0), 3, 4, pi/4).rotation
pi/4
数值旋转角度变为规范角度:
>>> RegularPolygon(Point(0, 0), 3, 4, a).rotation
a
>>> RegularPolygon(Point(0, 0), 3, 4, pi).rotation
0
scale(x=1, y=1, pt=None)
由于必须缩放半径(如果 x == y),否则必须返回一个新的 Polygon,所以覆盖 GeometryEntity.scale 方法。
>>> from sympy import RegularPolygon
对称缩放返回一个 RegularPolygon:
>>> RegularPolygon((0, 0), 1, 4).scale(2, 2)
RegularPolygon(Point2D(0, 0), 2, 4, 0)
不对称缩放将返回一个菱形作为 Polygon:
>>> RegularPolygon((0, 0), 1, 4).scale(2, 1)
Polygon(Point2D(2, 0), Point2D(0, 1), Point2D(-2, 0), Point2D(0, -1))
spin(angle)
原地增量地逆时针旋转虚拟 Polygon 的旋转。
另请参阅:rotate 方法,移动中心。
>>> from sympy import Polygon, Point, pi
>>> r = Polygon(Point(0,0), 1, n=3)
>>> r.vertices[0]
Point2D(1, 0)
>>> r.spin(pi/6)
>>> r.vertices[0]
Point2D(sqrt(3)/2, 1/2)
另请参阅
rotation
rotate
创建绕点旋转的 RegularPolygon 的副本
property vertices
RegularPolygon 的顶点。
返回:
顶点:列表
每个顶点是一个点。
示例
>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.vertices
[Point2D(5, 0), Point2D(0, 5), Point2D(-5, 0), Point2D(0, -5)]
另请参阅
sympy.geometry.point.Point
class sympy.geometry.polygon.Triangle(*args, **kwargs)
三个顶点和三条边的多边形。
参数:
点:点的序列
关键字:asa、sas 或 sss 用于指定三角形的边/角
异常:
几何错误
如果顶点数量不等于三,或其中一个顶点不是点,或未给出有效的关键字。
示例
>>> from sympy import Triangle, Point
>>> Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
Triangle(Point2D(0, 0), Point2D(4, 0), Point2D(4, 3))
可使用关键字 sss、sas 或 asa 指定所需的边长(按顺序)和内角(以度数)来定义三角形:
>>> Triangle(sss=(3, 4, 5))
Triangle(Point2D(0, 0), Point2D(3, 0), Point2D(3, 4))
>>> Triangle(asa=(30, 1, 30))
Triangle(Point2D(0, 0), Point2D(1, 0), Point2D(1/2, sqrt(3)/6))
>>> Triangle(sas=(1, 45, 2))
Triangle(Point2D(0, 0), Point2D(2, 0), Point2D(sqrt(2)/2, sqrt(2)/2))
另请参阅
sympy.geometry.point.Point
,Polygon
属性
顶点 | |
---|---|
高度 | |
垂心 | |
外心 | |
外心半径 | |
外接圆 | |
内切圆半径 | |
外接圆半径 | |
外接圆半径 | |
中位线 | |
中心 | |
九点圆 |
property altitudes
三角形的高度。
三角形的一个高度是通过顶点的一条段,垂直于对边,长度是从包含边的直线到顶点的高度。
返回:
高度:字典
字典包含键为顶点,值为线段的键。
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.altitudes[p1]
Segment2D(Point2D(0, 0), Point2D(1/2, 1/2))
另请参阅
sympy.geometry.point.Point
,sympy.geometry.line.Segment.length
bisectors()
三角形的角平分线。
三角形的角平分线是通过顶点的一条直线,将相应的角分为两等分。
返回:
角平分线:字典
每个键是一个顶点(点),每个值是相应的角平分线(线段)。
示例
>>> from sympy import Point, Triangle, Segment
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> from sympy import sqrt
>>> t.bisectors()[p2] == Segment(Point(1, 0), Point(0, sqrt(2) - 1))
True
另请参阅
sympy.geometry.point.Point
,sympy.geometry.line.Segment
property circumcenter
三角形的外心
外心是外接圆的中心。
返回:
外心:点
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.circumcenter
Point2D(1/2, 1/2)
另请参阅
sympy.geometry.point.Point
property circumcircle
通过三角形的三个顶点的圆。
返回:
外接圆:圆
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.circumcircle
Circle(Point2D(1/2, 1/2), sqrt(2)/2)
另请参阅
sympy.geometry.ellipse.Circle
property circumradius
三角形的外接圆的半径。
返回:
外接圆半径:基本实例的数量
示例
>>> from sympy import Symbol
>>> from sympy import Point, Triangle
>>> a = Symbol('a')
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, a)
>>> t = Triangle(p1, p2, p3)
>>> t.circumradius
sqrt(a**2/4 + 1/4)
另请参阅
sympy.geometry.ellipse.Circle.radius
property eulerline
三角形的欧拉线。
通过外心、重心和垂心的直线。
返回:
欧拉线:线(或者对于等边三角形,是一个点)
中心重合)
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.eulerline
Line2D(Point2D(0, 0), Point2D(1/2, 1/2))
property excenters
三角形的外心。
外心是一个圆的中心,它与三角形的一条边以及另外两条边的延长线相切。
返回:
外心:字典
示例
外心与三角形边的对应外切圆相切:中心是键入的,例如接触第 0 边的圆的外心是:
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(6, 0), Point(0, 2)
>>> t = Triangle(p1, p2, p3)
>>> t.excenters[t.sides[0]]
Point2D(12*sqrt(10), 2/3 + sqrt(10)/3)
另见
sympy.geometry.polygon.Triangle.exradii
参考文献
[R560]
mathworld.wolfram.com/Excircles.html
property exradii
三角形的外切圆的半径。
三角形的外接圆是位于三角形外部的圆,它与其一条边相切并与另外两条边的延长线相切。
返回:
外切圆半径:字典
示例
外切圆接触到其键入的三角形边的边,例如接触到第 2 边的外切圆是:
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(6, 0), Point(0, 2)
>>> t = Triangle(p1, p2, p3)
>>> t.exradii[t.sides[2]]
-2 + sqrt(10)
另见
sympy.geometry.polygon.Triangle.inradius
参考文献
[R561]
mathworld.wolfram.com/Exradius.html
[R562]
mathworld.wolfram.com/Excircles.html
property incenter
内切圆的中心。
内切圆是位于三角形内部并接触所有三条边的圆。
返回:
内心:点
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.incenter
Point2D(1 - sqrt(2)/2, 1 - sqrt(2)/2)
另见
内切圆
, sympy.geometry.point.Point
property incircle
三角形的内切圆。
内切圆是位于三角形内部并接触所有三条边的圆。
返回:
外切圆:圆
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(2, 0), Point(0, 2)
>>> t = Triangle(p1, p2, p3)
>>> t.incircle
Circle(Point2D(2 - sqrt(2), 2 - sqrt(2)), 2 - sqrt(2))
另见
sympy.geometry.ellipse.Circle
property inradius
内切圆的半径。
返回:
内切圆半径:基础实例的数量
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(4, 0), Point(0, 3)
>>> t = Triangle(p1, p2, p3)
>>> t.inradius
1
另见
内切圆
, sympy.geometry.ellipse.Circle.radius
is_equilateral()
所有边的长度都相等吗?
返回:
是否等边:布尔值
示例
>>> from sympy import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t1.is_equilateral()
False
>>> from sympy import sqrt
>>> t2 = Triangle(Point(0, 0), Point(10, 0), Point(5, 5*sqrt(3)))
>>> t2.is_equilateral()
True
另见
sympy.geometry.entity.GeometryEntity.is_similar
, RegularPolygon
, is_isosceles
, is_right
, is_scalene
is_isosceles()
两个或更多边是否相等?
返回:
is_isosceles:布尔值
示例
>>> from sympy import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(2, 4))
>>> t1.is_isosceles()
True
另请参阅
is_equilateral
,is_right
,is_scalene
is_right()
三角形是否直角?
返回:
is_right:布尔值
示例
>>> from sympy import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t1.is_right()
True
另请参阅
sympy.geometry.line.LinearEntity.is_perpendicular
,is_equilateral
,is_isosceles
,is_scalene
is_scalene()
三角形的各边长度是否都不同?
返回:
is_scalene:布尔值
示例
>>> from sympy import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(1, 4))
>>> t1.is_scalene()
True
另请参阅
is_equilateral
,is_isosceles
,is_right
is_similar(t2)
另一个三角形是否与此相似。
如果一个三角形可以均匀缩放到另一个三角形,则它们相似。
参数:
其他:三角形
返回:
is_similar:布尔值
示例
>>> from sympy import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t2 = Triangle(Point(0, 0), Point(-4, 0), Point(-4, -3))
>>> t1.is_similar(t2)
True
>>> t2 = Triangle(Point(0, 0), Point(-4, 0), Point(-4, -4))
>>> t1.is_similar(t2)
False
另请参阅
sympy.geometry.entity.GeometryEntity.is_similar
property medial
三角形的中位三角形。
由三边的中点形成的三角形。
返回:
medial:三角形
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.medial
Triangle(Point2D(1/2, 0), Point2D(1/2, 1/2), Point2D(0, 1/2))
另请参阅
sympy.geometry.line.Segment.midpoint
property medians
三角形的中位线。
三角形的中位线是通过一个顶点和对边中点的直线,将三角形分成两个相等的面积。
返回:
medians:字典
每个键是一个顶点(点),每个值是通过该点的中位线(线段)。
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.medians[p1]
Segment2D(Point2D(0, 0), Point2D(1/2, 1/2))
另请参阅
sympy.geometry.point.Point.midpoint
,sympy.geometry.line.Segment.midpoint
property nine_point_circle
三角形的九点圆。
九点圆是三角形中位三角形的外接圆,它经过高度的脚和连接顶点与正交中心的线段的中点。
返回:
nine_point_circle:圆
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.nine_point_circle
Circle(Point2D(1/4, 1/4), sqrt(2)/4)
另请参阅
sympy.geometry.line.Segment.midpoint
,sympy.geometry.polygon.Triangle.medial
,sympy.geometry.polygon.Triangle.orthocenter
property orthocenter
三角形的正交中心。
正交中心是三角形的高线的交点。它可能位于三角形的内部、外部或边上。
返回:
正交中心:Point
示例
>>> from sympy import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.orthocenter
Point2D(0, 0)
另请参见
sympy.geometry.point.Point
property vertices
三角形的顶点
返回:
顶点:元组
元组中的每个元素都是一个 Point
示例
>>> from sympy import Triangle, Point
>>> t = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t.vertices
(Point2D(0, 0), Point2D(4, 0), Point2D(4, 3))
另请参见
sympy.geometry.point.Point
平面
class sympy.geometry.plane.Plane(p1, a=None, b=None, **kwargs)
平面是一个平坦的二维表面。平面是点(零维)、线(一维)和立体(三维)的二维模拟。平面通常可以通过两种类型的输入构造。它们是:- 三个非共线点 - 一个点和平面的法向量
示例
>>> from sympy import Plane, Point3D
>>> Plane(Point3D(1, 1, 1), Point3D(2, 3, 4), Point3D(2, 2, 2))
Plane(Point3D(1, 1, 1), (-1, 2, -1))
>>> Plane((1, 1, 1), (2, 3, 4), (2, 2, 2))
Plane(Point3D(1, 1, 1), (-1, 2, -1))
>>> Plane(Point3D(1, 1, 1), normal_vector=(1,4,7))
Plane(Point3D(1, 1, 1), (1, 4, 7))
属性
p1 | |
---|---|
normal_vector |
angle_between(o)
平面与其他几何实体之间的夹角。
参数:
LinearEntity3D, Plane.
返回:
角度:弧度角
注意事项
该方法只接受 3D 实体作为其参数,但如果要计算二维实体与平面之间的角度,应首先将其投影到所需的平面上转换为 3D 实体,然后再计算角度。
示例
>>> from sympy import Point3D, Line3D, Plane
>>> a = Plane(Point3D(1, 2, 2), normal_vector=(1, 2, 3))
>>> b = Line3D(Point3D(1, 3, 4), Point3D(2, 2, 2))
>>> a.angle_between(b)
-asin(sqrt(21)/6)
arbitrary_point(u=None, v=None)
返回平面上的任意点。如果给定两个参数,则该点在整个平面上变化。如果给定 1 个或没有参数,则返回一个点,其中一个参数在从 0 到 2*pi 变化时在平面的 p1 处以半径 1 的圆上移动。
返回:
Point3D
示例
>>> from sympy import Plane, Ray
>>> from sympy.abc import u, v, t, r
>>> p = Plane((1, 1, 1), normal_vector=(1, 0, 0))
>>> p.arbitrary_point(u, v)
Point3D(1, u + 1, v + 1)
>>> p.arbitrary_point(t)
Point3D(1, cos(t) + 1, sin(t) + 1)
尽管参数 u 和 v 的任意值可以将点移动到平面上的任何位置,但单参数点可以用来构造射线,其任意点可以位于以角度 t 和半径 r 从 p.p1 开始的圆上:
>>> Ray(p.p1, _).arbitrary_point(r)
Point3D(1, r*cos(t) + 1, r*sin(t) + 1)
static are_concurrent(*planes)
一系列平面是否共线?
如果它们的交点是一条公共线,则两个或更多个平面是共线的。
参数:
planes: list
返回:
布尔值
示例
>>> from sympy import Plane, Point3D
>>> a = Plane(Point3D(5, 0, 0), normal_vector=(1, -1, 1))
>>> b = Plane(Point3D(0, -2, 0), normal_vector=(3, 1, 1))
>>> c = Plane(Point3D(0, -1, 0), normal_vector=(5, -1, 9))
>>> Plane.are_concurrent(a, b)
True
>>> Plane.are_concurrent(a, b, c)
False
distance(o)
平面与另一个几何实体之间的距离。
参数:
Point3D, LinearEntity3D, Plane.
返回:
距离
注意事项
该方法只接受 3D 实体作为其参数,但如果要计算二维实体与平面之间的距离,应首先将其投影到所需的平面上转换为 3D 实体,然后再计算距离。
示例
>>> from sympy import Point3D, Line3D, Plane
>>> a = Plane(Point3D(1, 1, 1), normal_vector=(1, 1, 1))
>>> b = Point3D(1, 2, 3)
>>> a.distance(b)
sqrt(3)
>>> c = Line3D(Point3D(2, 3, 1), Point3D(1, 2, 2))
>>> a.distance(c)
0
equals(o)
如果 self 和 o 是相同的数学实体,则返回 True。
示例
>>> from sympy import Plane, Point3D
>>> a = Plane(Point3D(1, 2, 3), normal_vector=(1, 1, 1))
>>> b = Plane(Point3D(1, 2, 3), normal_vector=(2, 2, 2))
>>> c = Plane(Point3D(1, 2, 3), normal_vector=(-1, 4, 6))
>>> a.equals(a)
True
>>> a.equals(b)
True
>>> a.equals(c)
False
equation(x=None, y=None, z=None)
平面的方程式。
示例
>>> from sympy import Point3D, Plane
>>> a = Plane(Point3D(1, 1, 2), Point3D(2, 4, 7), Point3D(3, 5, 1))
>>> a.equation()
-23*x + 11*y - 2*z + 16
>>> a = Plane(Point3D(1, 4, 2), normal_vector=(6, 6, 6))
>>> a.equation()
6*x + 6*y + 6*z - 42
intersection(o)
与其他几何实体的交点。
参数:
Point, Point3D, LinearEntity, LinearEntity3D, Plane
返回:
列表
示例
>>> from sympy import Point3D, Line3D, Plane
>>> a = Plane(Point3D(1, 2, 3), normal_vector=(1, 1, 1))
>>> b = Point3D(1, 2, 3)
>>> a.intersection(b)
[Point3D(1, 2, 3)]
>>> c = Line3D(Point3D(1, 4, 7), Point3D(2, 2, 2))
>>> a.intersection(c)
[Point3D(2, 2, 2)]
>>> d = Plane(Point3D(6, 0, 0), normal_vector=(2, -5, 3))
>>> e = Plane(Point3D(2, 0, 0), normal_vector=(3, 4, -3))
>>> d.intersection(e)
[Line3D(Point3D(78/23, -24/23, 0), Point3D(147/23, 321/23, 23))]
is_coplanar(o)
如果 (o) 与自身共面,则返回 True,否则返回 False。
示例
>>> from sympy import Plane
>>> o = (0, 0, 0)
>>> p = Plane(o, (1, 1, 1))
>>> p2 = Plane(o, (2, 2, 2))
>>> p == p2
False
>>> p.is_coplanar(p2)
True
is_parallel(l)
给定的几何实体是否与该平面平行?
参数:
LinearEntity3D 或 Plane
返回:
布尔值
示例
>>> from sympy import Plane, Point3D
>>> a = Plane(Point3D(1,4,6), normal_vector=(2, 4, 6))
>>> b = Plane(Point3D(3,1,3), normal_vector=(4, 8, 12))
>>> a.is_parallel(b)
True
is_perpendicular(l)
给定的几何实体是否与给定的平面垂直?
参数:
LinearEntity3D 或 Plane
返回:
布尔值
示例
>>> from sympy import Plane, Point3D
>>> a = Plane(Point3D(1,4,6), normal_vector=(2, 4, 6))
>>> b = Plane(Point3D(2, 2, 2), normal_vector=(-1, 2, -1))
>>> a.is_perpendicular(b)
True
property normal_vector
给定平面的法向量。
示例
>>> from sympy import Point3D, Plane
>>> a = Plane(Point3D(1, 1, 1), Point3D(2, 3, 4), Point3D(2, 2, 2))
>>> a.normal_vector
(-1, 2, -1)
>>> a = Plane(Point3D(1, 1, 1), normal_vector=(1, 4, 7))
>>> a.normal_vector
(1, 4, 7)
property p1
平面的唯一定义点。其他点可以从 arbitrary_point 方法获取。
示例
>>> from sympy import Point3D, Plane
>>> a = Plane(Point3D(1, 1, 1), Point3D(2, 3, 4), Point3D(2, 2, 2))
>>> a.p1
Point3D(1, 1, 1)
另请参阅
sympy.geometry.point.Point3D
parallel_plane(pt)
平行于给定平面并通过点 pt 的平面。
参数:
pt: Point3D
返回:
平面
示例
>>> from sympy import Plane, Point3D
>>> a = Plane(Point3D(1, 4, 6), normal_vector=(2, 4, 6))
>>> a.parallel_plane(Point3D(2, 3, 5))
Plane(Point3D(2, 3, 5), (2, 4, 6))
parameter_value(other, u, v=None)
返回与给定点对应的参数(s)。
示例
>>> from sympy import pi, Plane
>>> from sympy.abc import t, u, v
>>> p = Plane((2, 0, 0), (0, 0, 1), (0, 1, 0))
默认情况下,返回的参数值定义了一个距离平面 p1 值 1 的点,并且与给定点在一条直线上:
>>> on_circle = p.arbitrary_point(t).subs(t, pi/4)
>>> on_circle.distance(p.p1)
1
>>> p.parameter_value(on_circle, t)
{t: pi/4}
将点从 p1 移动两倍,不会改变参数值:
>>> off_circle = p.p1 + (on_circle - p.p1)*2
>>> off_circle.distance(p.p1)
2
>>> p.parameter_value(off_circle, t)
{t: pi/4}
如果需要 2 个值的参数,请提供两个参数符号,并返回替换字典:
>>> p.parameter_value(on_circle, u, v)
{u: sqrt(10)/10, v: sqrt(10)/30}
>>> p.parameter_value(off_circle, u, v)
{u: sqrt(10)/5, v: sqrt(10)/15}
perpendicular_line(pt)
垂直于给定平面的直线。
参数:
pt:Point3D
返回:
Line3D
示例
>>> from sympy import Plane, Point3D
>>> a = Plane(Point3D(1,4,6), normal_vector=(2, 4, 6))
>>> a.perpendicular_line(Point3D(9, 8, 7))
Line3D(Point3D(9, 8, 7), Point3D(11, 12, 13))
perpendicular_plane(*pts)
返回通过给定点的垂直线。如果点之间的方向比平面的法线向量相同,则为了从无数可能的平面中选择,将在 z 轴上选择第三个点(如果法线不已经平行于 z 轴,则在平行于 y 轴的线上)。如果给出少于两个点,则将如下提供:如果没有给出点,则 pt1 将是 self.p1;如果没有给出第二个点,则它将是一条通过 pt1 的线,平行于 z 轴(如果法线不已经是 z 轴,则平行于 y 轴的线)。
参数:
pts:0、1 或 2 个 Point3D
返回:
平面
示例
>>> from sympy import Plane, Point3D
>>> a, b = Point3D(0, 0, 0), Point3D(0, 1, 0)
>>> Z = (0, 0, 1)
>>> p = Plane(a, normal_vector=Z)
>>> p.perpendicular_plane(a, b)
Plane(Point3D(0, 0, 0), (1, 0, 0))
projection(pt)
将给定点沿平面法线投影到平面上。
参数:
点或 Point3D
返回:
Point3D
示例
>>> from sympy import Plane, Point3D
>>> A = Plane(Point3D(1, 1, 2), normal_vector=(1, 1, 1))
投影沿法线向量方向进行,而不是沿 z 轴,因此(1, 1)在平面 A 上不投影到(1, 1, 2):
>>> b = Point3D(1, 1)
>>> A.projection(b)
Point3D(5/3, 5/3, 2/3)
>>> _ in A
True
但是点(1, 1, 2)在 XY 平面上投影到(1, 1):
>>> XY = Plane((0, 0, 0), (0, 0, 1))
>>> XY.projection((1, 1, 2))
Point3D(1, 1, 0)
projection_line(line)
将给定的直线投影到包含该直线的法线平面上。
参数:
LinearEntity 或 LinearEntity3D
返回:
Point3D、Line3D、Ray3D 或 Segment3D
注意事项
对于 2D 和 3D 线段(射线、线段)之间的交互,应通过使用此方法将线段转换为 3D。例如,要找到 2D 和 3D 线之间的交点,请通过将 2D 线段投影到所需平面上将其转换为 3D 线段,然后继续查找这些线之间的交点。
示例
>>> from sympy import Plane, Line, Line3D, Point3D
>>> a = Plane(Point3D(1, 1, 1), normal_vector=(1, 1, 1))
>>> b = Line(Point3D(1, 1), Point3D(2, 2))
>>> a.projection_line(b)
Line3D(Point3D(4/3, 4/3, 1/3), Point3D(5/3, 5/3, -1/3))
>>> c = Line3D(Point3D(1, 1, 1), Point3D(2, 2, 2))
>>> a.projection_line(c)
Point3D(1, 1, 1)
random_point(seed=None)
返回平面上的随机点。
返回:
Point3D
示例
>>> from sympy import Plane
>>> p = Plane((1, 0, 0), normal_vector=(0, 1, 0))
>>> r = p.random_point(seed=42) # seed value is optional
>>> r.n(3)
Point3D(2.29, 0, -1.35)
可以将随机点移动到以 p1 为中心、半径为 1 的圆上:
>>> c = p.p1 + (r - p.p1).unit
>>> c.distance(p.p1).equals(1)
True
全息函数
holonomic
模块旨在处理全息函数及其诸如加法、乘法、组合、积分和微分等各种操作。该模块还实现了各种类型的转换,例如将全息函数转换为不同形式及其逆操作。
内容
-
关于全息函数
-
SymPy 中的全息函数表示
-
全息函数的操作
-
将其他表示形式转换为全息函数
-
用途和当前限制
-
内部 API
关于全纯函数
本文旨在解释全纯函数。我们假设您对微分方程和抽象代数有基本的了解。
定义
全纯函数是特殊函数的一种非常普遍的类型,包括许多简单的已知函数作为其特殊情况。事实上,更为知名的超几何函数和 Meijer G 函数也是它的特殊情况之一。
如果一个函数是多项式系数的常微分方程的解,则称其为全纯函数。由于常微分方程的一般解由一组函数而不是单个函数组成,全纯函数通常由初始条件和微分方程定义。
设 (K) 是一个特征为 0
的域。例如,(K) 可以是 QQ
或 RR
。如果存在多项式 (p_0, p_1, p_2, ... p_r \in K[x]),使得
[p_0 \cdot f(x) + p_1 \cdot f^{(1)}(x) + p_2 \cdot f^{(2)}(x) + ... + p_r \cdot f^{(r)}(x) = 0]
这个微分方程也可以写成 (L \cdot f(x) = 0) 其中
[L = p_0 + p_1 \cdot D + p_2 \cdot D² + ... p_r \cdot D^r]
这里 (D) 是微分算子,(L) 被称为函数的湮灭算子。
从湮灭算子和一组初始条件可以定义出一个唯一的全纯函数。例如:
[ \begin{align}\begin{aligned}f(x) = \exp(x): L = D - 1,: f(0) = 1\f(x) = \sin(x): L = D² + 1,: f(0) = 0, f'(0) = 1\end{aligned}\end{align} ]
其他基础函数如 (\cos(x)), (\log(x)), 贝塞尔函数等也是全纯函数。
全纯函数的族在加法、乘法、积分、组合下封闭。这意味着如果两个函数是全纯函数,那么对它们进行这些运算得到的函数也将是全纯函数。
参考文献
SymPy 中全纯函数的表示
类DifferentialOperator
用于表示湮灭子,但我们可以使用函数DifferentialOperators()
轻松创建微分算子。类HolonomicFunction
表示一个全纯函数。
让我们通过一个例子来解释这一点:
以 (\sin(x)) 为例,它满足的微分方程是 (y^{(2)}(x) + y(x) = 0)。根据定义,我们得出它是一个全纯函数。该常微分方程的一般解为 (C_{1} \cdot \sin(x) + C_{2} \cdot \cos(x)),但要得到 (\sin(x)),我们需要提供初始条件,即 (y(0) = 0, y^{(1)}(0) = 1)。
要在该模块中表示相同的内容,需要将微分方程以湮灭子的形式提供。基本上,微分算子是作用于函数的操作符,对其进行微分。因此,(D^{n} \cdot y(x) = y^{(n)}(x)),其中 (y^{(n)}(x)) 表示 (y(x)) 关于 (x) 的第 (n) 次导数。
因此,微分方程也可以写作 (D^{2} \cdot y(x) + y(x) = 0) 或者 ((D^{2} + 1) \cdot y(x) = 0)。方程左侧的部分是湮灭子,即 (D^{2}+1)。
这就是如何将 (\sin(x)) 表示为全纯函数的方式:
>>> from sympy.holonomic import DifferentialOperators, HolonomicFunction
>>> from sympy.abc import x
>>> from sympy import ZZ
>>> R, D = DifferentialOperators(ZZ.old_poly_ring(x), 'D')
>>> HolonomicFunction(D**2 + 1, x, 0, [0, 1])
HolonomicFunction((1) + (1)*D**2, x, 0, [0, 1])
在示例中,多项式系数将成为环 ZZ[x]
的成员。通过函数DifferentialOperators()
返回的 D
算子可以像 SymPy 表达式一样用于创建湮灭子。我们目前使用 SymPy 中较旧的环实现优先机制。
class sympy.holonomic.holonomic.HolonomicFunction(annihilator, x, x0=0, y0=None)
全纯函数是线性齐次常微分方程 (L.f = 0) 的解,其系数为多项式。此微分方程也可以用湮灭子表示,即微分算子 L
。为了确保这些函数的唯一性,可以提供初始条件和湮灭子。
解释
全纯函数具有封闭性质,因此形成一个环。给定两个全纯函数 (f) 和 (g),它们的和、积、积分和导数也是全纯函数。
对于普通点,初始条件应为导数值的向量,即 ([y(x_0), y'(x_0), y''(x_0) ... ])。
对于常规奇异点,还可以按照此格式提供初值条件:({s0: [C_0, C_1, ...], s1: [C¹_0, C¹_1, ...], ...}),其中 s0, s1, …是指标方程的根,向量([C_0, C_1, ...], [C⁰_0, C⁰_1, ...], ...)是相关幂级数的初始项。请参见下面的示例。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import QQ
>>> from sympy import symbols, S
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
>>> p = HolonomicFunction(Dx - 1, x, 0, [1]) # e^x
>>> q = HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]) # sin(x)
>>> p + q # annihilator of e^x + sin(x)
HolonomicFunction((-1) + (1)*Dx + (-1)*Dx**2 + (1)*Dx**3, x, 0, [1, 2, 1])
>>> p * q # annihilator of e^x * sin(x)
HolonomicFunction((2) + (-2)*Dx + (1)*Dx**2, x, 0, [0, 1])
对于常规奇异点的初值条件示例,指标方程只有一个根(1/2)。
>>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]})
HolonomicFunction((-1/2) + (x)*Dx, x, 0, {1/2: [1]})
>>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]}).to_expr()
sqrt(x)
要绘制 Holonomic 函数,可以使用.evalf()
进行数值计算。以下是使用 numpy 和 matplotlib 绘制(sin(x)**2/x)的示例。
>>> import sympy.holonomic
>>> from sympy import var, sin
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> var("x")
>>> r = np.linspace(1, 5, 100)
>>> y = sympy.holonomic.expr_to_holonomic(sin(x)**2/x, x0=1).evalf(r)
>>> plt.plot(r, y, label="holonomic function")
>>> plt.show()
class sympy.holonomic.holonomic.DifferentialOperator(list_of_poly, parent)
微分算子是 Weyl 代数的元素。这些运算符由基础环中的多项式列表和运算符所属的父环定义,即它所属的代数。
解释
接受每个Dx
幂级别的多项式列表和必须是 DifferentialOperatorAlgebra 实例的父环的列表。
使用运算符Dx
可以轻松创建微分算子。请参见下面的示例。
示例
>>> from sympy.holonomic.holonomic import DifferentialOperator, DifferentialOperators
>>> from sympy import ZZ
>>> from sympy import symbols
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx')
>>> DifferentialOperator([0, 1, x**2], R)
(1)*Dx + (x**2)*Dx**2
>>> (x*Dx*x + 1 - Dx**2)**2
(2*x**2 + 2*x + 1) + (4*x**3 + 2*x**2 - 4)*Dx + (x**4 - 6*x - 2)*Dx**2 + (-2*x**2)*Dx**3 + (1)*Dx**4
另请参阅
DifferentialOperatorAlgebra
is_singular(x0)
检查微分方程在 x0 处是否奇异。
sympy.holonomic.holonomic.DifferentialOperators(base, generator)
此函数用于使用Dx
创建湮灭算子。
参数:
基础:
代数的基础多项式环。基础多项式环是在运算符中出现的 x 的多项式环,这些运算符将作为运算符的系数。
生成器:
代数的生成器可以是非交换的
Symbol
或字符串。例如,“Dx”或“D”。
解释
返回微分算子的代数,也称为 Weyl 代数,以及区分运算的操作符,即Dx
运算符。
示例
>>> from sympy import ZZ
>>> from sympy.abc import x
>>> from sympy.holonomic.holonomic import DifferentialOperators
>>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x), 'Dx')
>>> R
Univariate Differential Operator Algebra in intermediate Dx over the base ring ZZ[x]
>>> Dx*x
(1) + (x)*Dx
class sympy.holonomic.holonomic.DifferentialOperatorAlgebra(base, generator)
Ore 代数是中间Dx
中的非交换多项式集合和基础多项式环(A)中的系数。它遵循交换规则:
[Dxa = \sigma(a)Dx + \delta(a)]
对于(a \subset A)。
其中(\sigma: A \Rightarrow A)是一个自同态,而(\delta: A \rightarrow A)是一个斜导数,即(\delta(ab) = \delta(a) b + \sigma(a) \delta(b))。
如果将 sigma 视为恒等映射,将 delta 视为标准导数,那么它变成了微分算子的代数,也称为 Weyl 代数,即其元素为微分算子的代数。
该类代表一个 Weyl 代数,并作为微分算子的父环。
示例
>>> from sympy import ZZ
>>> from sympy import symbols
>>> from sympy.holonomic.holonomic import DifferentialOperators
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x), 'Dx')
>>> R
Univariate Differential Operator Algebra in intermediate Dx over the base ring
ZZ[x]
另请参阅
DifferentialOperator
全息函数的运算
原文链接:
docs.sympy.org/latest/modules/holonomic/operations.html
加法和乘法
两个全息函数可以相加或相乘,结果也是全息函数。
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy.polys.domains import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
这里的
p
和q
是 (e^x) 和 (\sin(x)) 的全息表示。>>> p = HolonomicFunction(Dx - 1, x, 0, [1]) >>> q = HolonomicFunction(Dx**2 + 1, x, 0, [0, 1])
(e^x+\sin(x)) 的完全表示
>>> p + q HolonomicFunction((-1) + (1)*Dx + (-1)*Dx**2 + (1)*Dx**3, x, 0, [1, 2, 1])
(e^x \cdot \sin(x)) 的完全表示
>>> p * q HolonomicFunction((2) + (-2)*Dx + (1)*Dx**2, x, 0, [0, 1])
积分和微分
HolonomicFunction.integrate(limits, initcond=False)
对给定的全息函数进行积分。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import QQ
>>> from sympy import symbols
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
>>> HolonomicFunction(Dx - 1, x, 0, [1]).integrate((x, 0, x)) # e^x - 1
HolonomicFunction((-1)*Dx + (1)*Dx**2, x, 0, [0, 1])
>>> HolonomicFunction(Dx**2 + 1, x, 0, [1, 0]).integrate((x, 0, x))
HolonomicFunction((1)*Dx + (1)*Dx**3, x, 0, [0, 1, 0])
HolonomicFunction.diff(*args, **kwargs)
对给定的全息函数进行微分。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import ZZ
>>> from sympy import symbols
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx')
>>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).diff().to_expr()
cos(x)
>>> HolonomicFunction(Dx - 2, x, 0, [1]).diff().to_expr()
2*exp(2*x)
另见
integrate
与多项式的组合
HolonomicFunction.composition(expr, *args, **kwargs)
返回全息函数与代数函数的组合后的函数。该方法不能单独计算结果的初始条件,因此也可以提供它们。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import QQ
>>> from sympy import symbols
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
>>> HolonomicFunction(Dx - 1, x).composition(x**2, 0, [1]) # e^(x**2)
HolonomicFunction((-2*x) + (1)*Dx, x, 0, [1])
>>> HolonomicFunction(Dx**2 + 1, x).composition(x**2 - 1, 1, [1, 0])
HolonomicFunction((4*x**3) + (-1)*Dx + (x)*Dx**2, x, 1, [1, 0])
另见
from_hyper
转换为完全序列
HolonomicFunction.to_sequence(lb=True)
在关于 (x_0) 的函数的级数展开中找到系数的递归关系,其中 (x_0) 是存储初始条件的点。
解释
如果点 (x_0) 是普通的,将返回形式为 ([(R, n_0)]) 的解。其中 (R) 是递归关系,(n_0) 是满足递归的最小 n
。
如果点 (x_0) 是正则奇异的,将返回格式为 ((R, p, n_0)) 的解列表。即 ([(R, p, n_0), ... ])。在这种情况下,还可以提供不同格式的条件,请参阅 HolonomicFunction 类的文档字符串。
如果无法数值计算初始条件,则将其作为符号 (C_j) 返回,表示关于 (x_0) 的幂级数中 ((x - x_0)^j) 的系数。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import QQ
>>> from sympy import symbols, S
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
>>> HolonomicFunction(Dx - 1, x, 0, [1]).to_sequence()
[(HolonomicSequence((-1) + (n + 1)Sn, n), u(0) = 1, 0)]
>>> HolonomicFunction((1 + x)*Dx**2 + Dx, x, 0, [0, 1]).to_sequence()
[(HolonomicSequence((n**2) + (n**2 + n)Sn, n), u(0) = 0, u(1) = 1, u(2) = -1/2, 2)]
>>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]}).to_sequence()
[(HolonomicSequence((n), n), u(0) = 1, 1/2, 1)]
另见
HolonomicFunction.series
参考文献
[R565]
hal.inria.fr/inria-00070025/document
[R566]
www3.risc.jku.at/publications/download/risc_2244/DIPLFORM.pdf
级数展开
HolonomicFunction.series(n=6, coefficient=False, order=True, _recur=None)
找到给定的全息函数关于 (x_0) 的幂级数展开。
解释
如果 (x_0) 是指标方程具有多个根的正则点,则可能返回系列列表。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import QQ
>>> from sympy import symbols
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
>>> HolonomicFunction(Dx - 1, x, 0, [1]).series() # e^x
1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)
>>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).series(n=8) # sin(x)
x - x**3/6 + x**5/120 - x**7/5040 + O(x**8)
另见
HolonomicFunction.to_sequence
数值评估
HolonomicFunction.evalf(points, method='RK4', h=0.05, derivatives=False)
使用数值方法找到霍洛莫尼克函数的数值。(默认使用 RK4)。必须提供一组点(实数或复数),这将是数值积分的路径。
解释
路径应以列表形式给出 ([x_1, x_2, \dots x_n])。将按此顺序计算每个点的数值 (x_1 \rightarrow x_2 \rightarrow x_3 \dots \rightarrow x_n)。
返回在列表中 (x_1, x_2, \dots x_n) 处函数的值。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import QQ
>>> from sympy import symbols
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
实轴上从 (0 到 1) 的直线
>>> r = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
从 0.1 到 1 上的 (e^x) 的四阶龙格-库塔法。在 1 处的精确解为 2.71828182845905
>>> HolonomicFunction(Dx - 1, x, 0, [1]).evalf(r)
[1.10517083333333, 1.22140257085069, 1.34985849706254, 1.49182424008069,
1.64872063859684, 1.82211796209193, 2.01375162659678, 2.22553956329232,
2.45960141378007, 2.71827974413517]
欧拉法的相同
>>> HolonomicFunction(Dx - 1, x, 0, [1]).evalf(r, method='Euler')
[1.1, 1.21, 1.331, 1.4641, 1.61051, 1.771561, 1.9487171, 2.14358881,
2.357947691, 2.5937424601]
人们还可以观察到,使用四阶龙格-库塔法获得的值比欧拉法更精确。
转换为超几何函数的线性组合
HolonomicFunction.to_hyper(as_list=False, _recur=None)
返回表示给定霍洛莫尼克函数的超几何函数(或其线性组合)。
解释
返回形式为:(a_1 \cdot x^{b_1} \cdot{hyper()} + a_2 \cdot x^{b_2} \cdot{hyper()} \dots) 的答案。
这非常有用,因为现在可以使用 hyperexpand
找到符号表达式/函数。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import ZZ
>>> from sympy import symbols
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx')
>>> # sin(x)
>>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).to_hyper()
x*hyper((), (3/2,), -x**2/4)
>>> # exp(x)
>>> HolonomicFunction(Dx - 1, x, 0, [1]).to_hyper()
hyper((), (), x)
请参见
from_hyper
, from_meijerg
转换为 Meijer G 函数的线性组合
HolonomicFunction.to_meijerg()
返回 Meijer G 函数的线性组合。
示例
>>> from sympy.holonomic import expr_to_holonomic
>>> from sympy import sin, cos, hyperexpand, log, symbols
>>> x = symbols('x')
>>> hyperexpand(expr_to_holonomic(cos(x) + sin(x)).to_meijerg())
sin(x) + cos(x)
>>> hyperexpand(expr_to_holonomic(log(x)).to_meijerg()).simplify()
log(x)
请参见
to_hyper
转换为表达式
HolonomicFunction.to_expr()
将霍洛莫尼克函数转换回初等函数。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
>>> from sympy import ZZ
>>> from sympy import symbols, S
>>> x = symbols('x')
>>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx')
>>> HolonomicFunction(x**2*Dx**2 + x*Dx + (x**2 - 1), x, 0, [0, S(1)/2]).to_expr()
besselj(1, x)
>>> HolonomicFunction((1 + x)*Dx**3 + Dx**2, x, 0, [1, 1, 1]).to_expr()
x*log(x + 1) + log(x + 1) + 1
将其他表示转换为全局函数
转换超几何函数
sympy.holonomic.holonomic.from_hyper(func, x0=0, evalf=False)
将超几何函数转换为全局函数。func
是超几何函数,x0
是需要初始条件的点。
示例
>>> from sympy.holonomic.holonomic import from_hyper
>>> from sympy import symbols, hyper, S
>>> x = symbols('x')
>>> from_hyper(hyper([], [S(3)/2], x**2/4))
HolonomicFunction((-x) + (2)*Dx + (x)*Dx**2, x, 1, [sinh(1), -sinh(1) + cosh(1)])
转换 Meijer G-函数
sympy.holonomic.holonomic.from_meijerg(func, x0=0, evalf=False, initcond=True, domain=QQ)
将 Meijer G-函数转换为全局函数。func
是 G-函数,x0
是需要初始条件的点。
示例
>>> from sympy.holonomic.holonomic import from_meijerg
>>> from sympy import symbols, meijerg, S
>>> x = symbols('x')
>>> from_meijerg(meijerg(([], []), ([S(1)/2], [0]), x**2/4))
HolonomicFunction((1) + (1)*Dx**2, x, 0, [0, 1/sqrt(pi)])
转换符号表达式
sympy.holonomic.holonomic.expr_to_holonomic(func, x=None, x0=0, y0=None, lenics=None, domain=None, initcond=True)
将函数或表达式转换为全局函数。
参数:
func:
待转换的表达式。
x:
函数的变量。
x0:
必须计算初始条件的点。
y0:
如果方法无法自动执行,可以选择提供初始条件。
lenics:
初始条件中的项数。默认情况下等于湮灭子的阶数。
domain:
在湮灭子中作为系数出现的多项式
x
的基本域。
initcond:
如果不想计算初始条件,请将其设置为 false。
示例
>>> from sympy.holonomic.holonomic import expr_to_holonomic
>>> from sympy import sin, exp, symbols
>>> x = symbols('x')
>>> expr_to_holonomic(sin(x))
HolonomicFunction((1) + (1)*Dx**2, x, 0, [0, 1])
>>> expr_to_holonomic(exp(x))
HolonomicFunction((-1) + (1)*Dx, x, 0, [1])
另请参阅
sympy.integrals.meijerint._rewrite1
, _convert_poly_rat_alg
, _create_table
用途和当前的限制
积分
可以按照以下步骤使用全局函数执行积分:
-
将被积函数转换为全局函数。
-
现在整合函数的全局表达式。
-
将积分再转换为表达式。
示例
>>> from sympy.abc import x, a
>>> from sympy import sin
>>> from sympy.holonomic import expr_to_holonomic
>>> expr_to_holonomic(1/(x**2+a), x).integrate(x).to_expr()
atan(x/sqrt(a))/sqrt(a)
>>> expr_to_holonomic(sin(x)/x).integrate(x).to_expr()
Si(x)
正如您在第一个示例中看到的,我们将函数转换为全局函数,对结果进行积分,然后再转换回符号表达式。
局限性
1. 并非总是可以转换为表达式。全局函数应该在 x0
处具有超几何级数。
2. 当解需要具有 (\log) 项时,当前转换为全局序列的实现不支持 Frobenius method
。当指标方程的至少一个根对之间差一个整数时,以及 Frobenius 方法产生线性相关的级数解时,这种情况就会发生。由于我们在转换为表达式时使用这个方法,有时 to_expr()
会失败。
3. 似乎没有计算不定积分的方法,所以 integrate()
基本上计算的是 (\int_{x_0}^{x} f(x)dx),如果没有给出限制条件,则 (x_0) 是存储被积函数初始条件的点。有时结果会多出一个常数。例如:
>>> expr_to_holonomic(sin(x)).integrate(x).to_expr()
1 - cos(x)
>>> sin(x).integrate(x)
-cos(x)
(\sin(x)) 的不定积分是 (-\cos(x))。但输出为 (-\cos(x) + 1),即 (\int_{0}^{x} sin(x)dx)。虽然两者都被认为是正确的,但 (-\cos(x)) 更简单。
内部 API
sympy.holonomic.holonomic._create_table(table, domain=QQ)
创建查找表。有关类似实现,请参见 meijerint._create_lookup_table。
sympy.holonomic.holonomic._convert_poly_rat_alg(func, x, x0=0, y0=None, lenics=None, domain=QQ, initcond=True)
将多项式、有理数和代数函数转换为全局性函数。
李代数
class sympy.liealgebras.root_system.RootSystem(cartantype)
表示简单李代数的根系
每个简单李代数都有一个唯一的根系。要找到根系,我们首先考虑 g 的 Cartan 子代数,即最大的阿贝尔子代数,并考虑 g 对该子代数的伴随作用。与此作用相关联的是一个根系。现在,一个向量空间 V 上的根系是一组有限向量 Phi(称为根),满足:
-
根跨越 V
-
Phi 中 x 的唯一标量倍数是 x 和-x
-
对于 Phi 中的每个 x,Phi 集合在通过 x 的垂直超平面的反射下是封闭的。
-
如果 x 和 y 是 Phi 中的根,则 y 在通过 x 的线上的投影是 x 的半整数倍。
现在,有 Phi 的一个子集 Delta,我们称之为 Delta,满足:1. Delta 是 V 的一个基础 2. Phi 中的每个根 x 可以写成 x = sum k_y y,其中 y 在 Delta 中
Delta 的元素被称为简单根。因此,我们可以看到简单根跨越了给定简单李代数的根空间。
参考文献
[R598]
en.wikipedia.org/wiki/Root_system
[R599]
李代数与表示论 - Humphreys
add_as_roots(root1, root2)
只有它们的和也是一个根时才将两个根相加
它以两个应该是根的向量作为输入。然后计算它们的和,并检查它是否在所有可能根的列表中。如果是,则返回总和。否则,返回一个字符串,说明总和不是一个根。
例子
>>> from sympy.liealgebras.root_system import RootSystem
>>> c = RootSystem("A3")
>>> c.add_as_roots([1, 0, -1, 0], [0, 0, 1, -1])
[1, 0, 0, -1]
>>> c.add_as_roots([1, -1, 0, 0], [0, 0, -1, 1])
'The sum of these two roots is not a root'
add_simple_roots(root1, root2)
将两个简单根相加
此函数将两个整数 root1 和 root2 作为输入。然后,它将这些整数用作简单根字典中的键,并获取相应的简单根,然后将它们相加。
例子
>>> from sympy.liealgebras.root_system import RootSystem
>>> c = RootSystem("A3")
>>> newroot = c.add_simple_roots(1, 2)
>>> newroot
[1, 0, -1, 0]
all_roots()
生成给定根系的所有根。
结果是一个字典,其键是整数。它通过从基类获取所有正根的字典,然后取每个根,乘以-1 并加入字典来生成根。通过这种方式生成所有负根。
cartan_matrix()
与此根系相关联的李代数的 Cartan 矩阵
例子
>>> from sympy.liealgebras.root_system import RootSystem
>>> c = RootSystem("A3")
>>> c.cartan_matrix()
Matrix([
[ 2, -1, 0],
[-1, 2, -1],
[ 0, -1, 2]])
dynkin_diagram()
与此根系相关联的李代数的 Dynkin 图
例子
>>> from sympy.liealgebras.root_system import RootSystem
>>> c = RootSystem("A3")
>>> print(c.dynkin_diagram())
0---0---0
1 2 3
root_space()
返回简单根的跨度
根空间是由简单根张成的向量空间,即具有显著基础的向量空间,即简单根。该方法返回一个表示根空间的字符串,作为简单根 alpha[1],...,alpha[n]的张量。
例子
>>> from sympy.liealgebras.root_system import RootSystem
>>> c = RootSystem("A3")
>>> c.root_space()
'alpha[1] + alpha[2] + alpha[3]'
simple_roots()
生成李代数的简单根
李代数的秩决定了它具有的简单根数量。该方法获取李代数的秩,然后使用李代数类中的 simple_root 方法生成所有简单根。
例子
>>> from sympy.liealgebras.root_system import RootSystem
>>> c = RootSystem("A3")
>>> roots = c.simple_roots()
>>> roots
{1: [1, -1, 0, 0], 2: [0, 1, -1, 0], 3: [0, 0, 1, -1]}
class sympy.liealgebras.type_a.TypeA(n)
此类包含有关简单 Lie 代数 A 系列的信息。 ====
basic_root(i, j)
这是一种仅生成具有第 i 个位置为 1 和第 j 个位置为-1 的根的方法。
basis()
返回 A_n 的独立生成器数目
cartan_matrix()
返回 A_n 的 Cartan 矩阵。Lie 代数的 Cartan 矩阵是通过对简单根(alpha[1], …., alpha[l])进行排序生成的。然后 Cartan 矩阵的 ij 项是(<alpha[i],alpha[j]>).
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType('A4')
>>> c.cartan_matrix()
Matrix([
[ 2, -1, 0, 0],
[-1, 2, -1, 0],
[ 0, -1, 2, -1],
[ 0, 0, -1, 2]])
dimension()
Lie 代数 V 空间的向量维数
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A4")
>>> c.dimension()
5
highest_root()
返回 A_n 的最高权根
lie_algebra()
返回与 A_n 相关联的 Lie 代数
positive_roots()
这种方法生成 A_n 的所有正根。这是 A_n 所有根的一半;通过将所有正根乘以-1,我们得到负根。
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A3")
>>> c.positive_roots()
{1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
roots()
返回 A_n 的总根数
simple_root(i)
每个李代数都有一个唯一的根系。给定一个根系 Q,存在一个子集合根使得 Q 的元素称为简单根,如果它不能被写成 Q 中两个元素的和。如果我们让 D 表示简单根的集合,那么很明显,Q 的每个元素都可以写成 D 的元素的线性组合,所有系数都是非负的。
在 A_n 中,第 i 个简单根是具有第 i 个位置为 1,在(i+1)位置为-1,其他位置为零的根。
此方法返回 A 系列的第 i 个简单根。
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A4")
>>> c.simple_root(1)
[1, -1, 0, 0, 0]
class sympy.liealgebras.type_b.TypeB(n)
basic_root(i, j)
这是一种仅生成具有第 i 个位置为 1 和第 j 个位置为-1 的根的方法。
basis()
返回 B_n 的独立生成器数目
cartan_matrix()
返回 B_n 的 Cartan 矩阵。Lie 代数的 Cartan 矩阵是通过对简单根(alpha[1], …., alpha[l])进行排序生成的。然后 Cartan 矩阵的 ij 项是(<alpha[i],alpha[j]>).
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType('B4')
>>> c.cartan_matrix()
Matrix([
[ 2, -1, 0, 0],
[-1, 2, -1, 0],
[ 0, -1, 2, -2],
[ 0, 0, -1, 2]])
dimension()
Lie 代数 V 空间的向量维数
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("B3")
>>> c.dimension()
3
lie_algebra()
返回与 B_n 相关联的 Lie 代数
positive_roots()
此方法生成 A_n 的所有正根。这是 B_n 所有根的一半;通过将所有正根乘以-1,我们得到负根。
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A3")
>>> c.positive_roots()
{1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
roots()
返回 B_n 的总根数”
simple_root(i)
每个李代数都有一个唯一的根系。给定一个根系 Q,存在一个子集合根使得 Q 的元素称为简单根,如果它不能被写成 Q 中两个元素的和。如果我们让 D 表示简单根的集合,那么很明显,Q 的每个元素都可以写成 D 的元素的线性组合,所有系数都是非负的。
在 B_n 中,前 n-1 个简单根与 A_(n-1)中的根相同(第 i 个位置为 1,(i+1)位置为-1,其他位置为零)。第 n 个简单根是在第 n 个位置为 1,其他位置为零的根。
此方法返回 B 系列的第 i 个简单根。
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("B3")
>>> c.simple_root(2)
[0, 1, -1]
class sympy.liealgebras.type_c.TypeC(n)
basic_root(i, j)
生成具有第 i 个位置为 1 和第 j 个位置为-1 的根
basis()
返回 C_n 的独立生成器数目
cartan_matrix()
C_n 的 Cartan 矩阵
李代数的 Cartan 矩阵由简单根(alpha[1], …, alpha[l])的顺序分配生成。然后 Cartan 矩阵的 ij 项是(<alpha[i],alpha[j]>).
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType('C4')
>>> c.cartan_matrix()
Matrix([
[ 2, -1, 0, 0],
[-1, 2, -1, 0],
[ 0, -1, 2, -1],
[ 0, 0, -2, 2]])
dimension()
李代数 V 的基础空间 V 的维数
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("C3")
>>> c.dimension()
3
lie_algebra()
返回与 C_n 相关联的李代数”
positive_roots()
生成 A_n 的所有正根
这是 C_n 所有根的一半;通过将所有正根乘以-1 我们得到负根。
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A3")
>>> c.positive_roots()
{1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
roots()
返回 C_n 的总根数”
simple_root(i)
C 系列的第 i 个简单根
每个李代数都有一个独特的根系。给定一个根系 Q,存在根的子集,称为简单根,如果它不能被写成 Q 中两个元素的和。如果我们让 D 表示简单根集合,则显然 Q 中的每个元素都可以被 D 的元素的非负系数线性组合表示。
在 C_n 中,前 n-1 个简单根与 A_(n-1)中的根相同(第 i 个位置为 1,第(i+1)个位置为-1,其他位置为零)。第 n 个简单根是第 n 位置为 2,其他位置为零的根。
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("C3")
>>> c.simple_root(2)
[0, 1, -1]
class sympy.liealgebras.type_d.TypeD(n)
basic_root(i, j)
这是一种只生成第 i 个位置为 1,第 j 个位置为-1 的根的方法。
basis()
返回 D_n 的独立生成元的数量。
cartan_matrix()
返回 D_n 的 Cartan 矩阵。李代数的 Cartan 矩阵由简单根(alpha[1], …, alpha[l])的顺序分配生成。然后 Cartan 矩阵的 ij 项是(<alpha[i],alpha[j]>).
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType('D4')
>>> c.cartan_matrix()
Matrix([
[ 2, -1, 0, 0],
[-1, 2, -1, -1],
[ 0, -1, 2, 0],
[ 0, -1, 0, 2]])
dimension()
李代数 V 的基础空间 V 的维数
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("D4")
>>> c.dimension()
4
lie_algebra()
返回与 D_n 相关联的李代数”
positive_roots()
这种方法生成 A_n 的所有正根。这是 D_n 所有根的一半,通过将所有正根乘以-1 我们得到负根。
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A3")
>>> c.positive_roots()
{1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
roots()
返回 D_n 的总根数”
simple_root(i)
每个李代数都有一个独特的根系。给定一个根系 Q,存在根的子集,称为简单根,如果它不能被写成 Q 中两个元素的和。如果我们让 D 表示简单根集合,则显然 Q 中的每个元素都可以被 D 的元素的非负系数线性组合表示。
在 D_n 中,前 n-1 个简单根与 A_(n-1)中的根相同(第 i 个位置为 1,第(i+1)个位置为-1,其他位置为零)。第 n 个简单根是第 n 和(n-1)位置为 1,其他位置为零的根。
这种方法返回 D 系列的第 i 个简单根。
示例
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("D4")
>>> c.simple_root(2)
[0, 1, -1, 0]
class sympy.liealgebras.type_e.TypeE(n)
basic_root(i, j)
这是一种只生成第 i 个位置为-1,第 j 个位置为 1 的根的方法。
basis()
返回 E_n 的独立生成元的数量。
cartan_matrix()
返回 G_2 的 Cartan 矩阵。李代数的 Cartan 矩阵由简单根(alpha[1], …, alpha[l])的顺序分配生成。然后 Cartan 矩阵的 ij 项是(<alpha[i],alpha[j]>).
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType('A4')
>>> c.cartan_matrix()
Matrix([
[ 2, -1, 0, 0],
[-1, 2, -1, 0],
[ 0, -1, 2, -1],
[ 0, 0, -1, 2]])
dimension()
向量空间 V 的维数作为李代数的基础
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("E6")
>>> c.dimension()
8
positive_roots()
此方法生成 A_n 的所有正根。这是 E_n 所有根的一半;通过将所有正根乘以 -1,我们得到负根。
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A3")
>>> c.positive_roots()
{1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
roots()
返回 E_n 的根的总数
simple_root(i)
每个李代数都有一个唯一的根系。给定一个根系 Q,存在一个子集合使得 Q 中的一个元素被称为简单根,如果它不能被 Q 中的两个元素之和表示。如果我们让 D 表示简单根的集合,则很明显 Q 中的每个元素都可以用 D 中元素的线性组合表示,而且所有系数都是非负的。
此方法返回 E_n 的第 i 个简单根。
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("E6")
>>> c.simple_root(2)
[1, 1, 0, 0, 0, 0, 0, 0]
class sympy.liealgebras.type_f.TypeF(n)
basic_root(i, j)
在第 i 个位置为 1 和第 j 个位置为 -1 的根
basis()
返回 F_4 的独立生成器数目
cartan_matrix()
F_4 的 Cartan 矩阵
对于一个李代数的 Cartan 矩阵是通过为简单根分配一个顺序生成的,(alpha[1], …., alpha[l])。然后 Cartan 矩阵的 ij 元素是 (<alpha[i],alpha[j]>).
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType('A4')
>>> c.cartan_matrix()
Matrix([
[ 2, -1, 0, 0],
[-1, 2, -1, 0],
[ 0, -1, 2, -1],
[ 0, 0, -1, 2]])
dimension()
向量空间 V 的维数作为李代数的基础
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("F4")
>>> c.dimension()
4
positive_roots()
生成 A_n 的所有正根
这是 F_4 所有根的一半;通过将所有正根乘以 -1,我们得到负根。
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A3")
>>> c.positive_roots()
{1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
roots()
返回 F_4 的根的总数
simple_root(i)
F_4 的第 i 个简单根
每个李代数都有一个唯一的根系。给定一个根系 Q,存在一个子集合使得 Q 中的一个元素被称为简单根,如果它不能被 Q 中的两个元素之和表示。如果我们让 D 表示简单根的集合,则很明显 Q 中的每个元素都可以用 D 中元素的线性组合表示,而且所有系数都是非负的。
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("F4")
>>> c.simple_root(3)
[0, 0, 0, 1]
class sympy.liealgebras.type_g.TypeG(n)
basis()
返回 G_2 的独立生成器数目
cartan_matrix()
G_2 的 Cartan 矩阵
对于一个李代数的 Cartan 矩阵是通过为简单根分配一个顺序生成的,(alpha[1], …., alpha[l])。然后 Cartan 矩阵的 ij 元素是 (<alpha[i],alpha[j]>).
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("G2")
>>> c.cartan_matrix()
Matrix([
[ 2, -1],
[-3, 2]])
dimension()
向量空间 V 的维数作为李代数的基础
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("G2")
>>> c.dimension()
3
positive_roots()
生成 A_n 的所有正根
这是 A_n 所有根的一半;通过将所有正根乘以 -1,我们得到负根。
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("A3")
>>> c.positive_roots()
{1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
roots()
返回 G_2 的根的总数”
simple_root(i)
G_2 的第 i 个简单根
每个李代数都有一个唯一的根系。给定一个根系 Q,存在一个子集合使得 Q 中的一个元素被称为简单根,如果它不能被 Q 中的两个元素之和表示。如果我们让 D 表示简单根的集合,则很明显 Q 中的每个元素都可以用 D 中元素的线性组合表示,而且所有系数都是非负的。
例子
>>> from sympy.liealgebras.cartan_type import CartanType
>>> c = CartanType("G2")
>>> c.simple_root(1)
[0, 1, -1]
class sympy.liealgebras.weyl_group.WeylGroup(cartantype)
对于每个半单 Lie 群,我们有一个 Weyl 群。它是根系的等距群的子群。具体而言,它是通过与根正交的超平面的反射生成的子群。因此,Weyl 群是反射群,因此 Weyl 群是有限 Coxeter 群的一种。
coxeter_diagram()
此方法返回与 Weyl 群对应的 Coxeter 图。通过从李代数的 Dynkin 图中删除所有箭头可以获得 Coxeter 图;Coxeter 图是无向图。Coxeter 图的顶点表示 Weyl 群的生成反射,(s_i)。如果(s_i)和(s_j)的顺序(m(i, j))大于 2,则两者之间会有一条边。如果有一条边,则顺序(m(i, j))为 3。如果有两条边,则顺序(m(i, j))为 4,如果有三条边,则顺序(m(i, j))为 6。
例子
>>> from sympy.liealgebras.weyl_group import WeylGroup
>>> c = WeylGroup("B3")
>>> print(c.coxeter_diagram())
0---0===0
1 2 3
delete_doubles(reflections)
这是确定 G2 的 Weyl 群中元素顺序的辅助方法。它接受一个 Weyl 元素,并删除其中的重复简单反射。
element_order(weylelt)
此方法返回给定 Weyl 群元素的顺序,用户应以生成反射的形式指定,即形如 r1*r2 等。
对于类型 A-F,此方法当前通过获取指定元素的矩阵形式,并找到该矩阵的幂等于单位矩阵。然后返回这个幂。
例子
>>> from sympy.liealgebras.weyl_group import WeylGroup
>>> b = WeylGroup("B4")
>>> b.element_order('r1*r4*r2')
4
generators()
此方法为给定李代数创建 Weyl 群的生成反射。对于秩为 n 的李代数,有 n 个不同的生成反射。此函数将它们作为列表返回。
例子
>>> from sympy.liealgebras.weyl_group import WeylGroup
>>> c = WeylGroup("F4")
>>> c.generators()
['r1', 'r2', 'r3', 'r4']
group_name()
此方法返回给定李代数的 Weyl 群的一些一般信息。它返回群的名称及其作用的元素(如果相关)。
group_order()
此方法返回 Weyl 群的顺序。对于类型 A、B、C、D 和 E,顺序取决于李代数的秩。对于类型 F 和 G,顺序是固定的。
例子
>>> from sympy.liealgebras.weyl_group import WeylGroup
>>> c = WeylGroup("D4")
>>> c.group_order()
192.0
matrix_form(weylelt)
此方法接受用户以生成反射的形式的输入,并返回对应于 Weyl 群元素的矩阵。由于 Weyl 群的每个元素都是某种类型的反射,因此有对应的矩阵表示。此方法使用所有生成反射的标准表示。
例子
>>> from sympy.liealgebras.weyl_group import WeylGroup
>>> f = WeylGroup("F4")
>>> f.matrix_form('r2*r3')
Matrix([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, -1],
[0, 0, 1, 0]])
class sympy.liealgebras.cartan_type.CartanType_generator
实际创建事物的构造函数
class sympy.liealgebras.cartan_type.Standard_Cartan(series, n)
Cartan 类型的具体基类,如 A4 等
rank()
返回李代数的秩
series()
返回李代数的类型
sympy.liealgebras.dynkin_diagram.DynkinDiagram(t)
显示给定李代数的 Dynkin 图
通过生成输入 t 的 CartanType 来工作,然后从各个类中返回 Dynkin 图方法。
例子
>>> from sympy.liealgebras.dynkin_diagram import DynkinDiagram
>>> print(DynkinDiagram("A3"))
0---0---0
1 2 3
>>> print(DynkinDiagram("B4"))
0---0---0=>=0
1 2 3 4
sympy.liealgebras.cartan_matrix.CartanMatrix(ct)
访问特定李代数的 Cartan 矩阵
例子
>>> from sympy.liealgebras.cartan_matrix import CartanMatrix
>>> CartanMatrix("A2")
Matrix([
[ 2, -1],
[-1, 2]])
>>> CartanMatrix(['C', 3])
Matrix([
[ 2, -1, 0],
[-1, 2, -1],
[ 0, -2, 2]])
此方法通过返回对应于 Cartan 类型 t 的 Cartan 矩阵来工作。