SymPy-1-13-中文文档-四十七-

46 阅读37分钟

SymPy 1.13 中文文档(四十七)

原文:docs.sympy.org/latest/index.html

曲线

原文链接:docs.sympy.org/latest/modules/geometry/curves.html

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)) 

椭圆

原文链接:docs.sympy.org/latest/modules/geometry/ellipses.html

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]

math.stackexchange.com/questions/108270/what-is-the-equation-of-an-ellipse-that-is-not-aligned-with-the-axis

[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 

参见

vradiusmajorminor

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]

zh.wikipedia.org/wiki/极矩

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]

zh.wikipedia.org/wiki/椭圆#半准径

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.Pointsympy.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

此椭圆属性是圆半径的别名。

尽管 hradiusmajorminor 可以使用椭圆的约定,但是 vradius 对于圆而言不存在。它始终是一个正值,以便像多边形一样,圆的面积可以根据 hradius 的符号为正或负。

示例

>>> from sympy import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.vradius
6 

多边形

原文:docs.sympy.org/latest/modules/geometry/polygons.html

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.Pointsympy.geometry.line.SegmentTriangle

属性

面积
角度
周长
顶点
重心
边数
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.Pointsympy.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]

skyciv.com/docs/tutorials/section-tutorials/calculating-the-statical-or-first-moment-of-area-of-beam-sections/?cc=BMD

[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.Pointsympy.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.PointPolygon

属性

顶点
高度
垂心
外心
外心半径
外接圆
内切圆半径
外接圆半径
外接圆半径
中位线
中心
九点圆
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.Pointsympy.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.Pointsympy.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_equilateralis_rightis_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_perpendicularis_equilateralis_isoscelesis_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_equilateralis_isoscelesis_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.midpointsympy.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.midpointsympy.geometry.polygon.Triangle.medialsympy.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