当前位置:   article > 正文

SymPy 1.13 中文文档(四十六)_python sympy库官方文档

python sympy库官方文档

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

主题

原文链接:docs.sympy.org/latest/reference/public/topics/index.html

目录

  • 几何学

    • 实体

    • 实用工具

    • 线

    • 曲线

    • 椭圆

    • 多边形

    • 平面

  • 全息函数

    • 关于全息函数

    • SymPy 中全息函数的表示

    • 全息函数操作

    • 将其他表示形式转换为全息函数

    • 用途与当前限制

    • 内部 API

  • 李代数

  • 多项式操作

    • 模块的基本功能

    • Wester 文章中的例子

    • 多项式操作模块参考

    • AGCA - 代数几何与交换代数模块

    • 多项式模块的域介绍

    • Poly Domains 的参考文档

    • 多项式操作模块的内部

    • 使用多项式进行级数操作

    • 文献资料

    • 多项式求解器

    • 多项式模块的域矩阵介绍

    • 数域

  • 范畴论

  • 密码学

  • 微分几何

  • 绘图

  • 统计

几何

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

简介

SymPy 的几何模块允许创建二维几何实体,如直线和圆,并查询有关这些实体的信息。这可能包括询问椭圆的面积,检查一组点的共线性,或找到两条线的交点。该模块的主要用例涉及具有数值值的实体,但也可以使用符号表示。

可用实体

当前在几何模块中可用的实体包括:

  • 线, 线段, 射线

  • 椭圆,

  • 多边形, 正多边形, 三角形

大部分工作都将通过这些实体的属性和方法完成,但也存在一些全局方法:

  • intersection(entity1, entity2)

  • are_similar(entity1, entity2)

  • convex_hull(points)

有关完整的 API 列表及其方法和返回值的解释,请参阅本文档末尾的类列表。

示例用法

以下 Python 会话给出了如何使用几何模块的一些想法。

>>> from sympy import *
>>> from sympy.geometry import *
>>> x = Point(0, 0)
>>> y = Point(1, 1)
>>> z = Point(2, 2)
>>> zp = Point(1, 0)
>>> Point.is_collinear(x, y, z)
True
>>> Point.is_collinear(x, y, zp)
False
>>> t = Triangle(zp, y, x)
>>> t.area
1/2
>>> t.medians[x]
Segment2D(Point2D(0, 0), Point2D(1, 1/2))
>>> m = t.medians
>>> intersection(m[x], m[y], m[zp])
[Point2D(2/3, 1/3)]
>>> c = Circle(x, 5)
>>> l = Line(Point(5, -5), Point(5, 5))
>>> c.is_tangent(l) # is l tangent to c?
True
>>> l = Line(x, y)
>>> c.is_tangent(l) # is l tangent to c?
False
>>> intersection(c, l)
[Point2D(-5*sqrt(2)/2, -5*sqrt(2)/2), Point2D(5*sqrt(2)/2, 5*sqrt(2)/2)] 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

中位线的交点

>>> from sympy import symbols
>>> from sympy.geometry import Point, Triangle, intersection

>>> a, b = symbols("a,b", positive=True)

>>> x = Point(0, 0)
>>> y = Point(a, 0)
>>> z = Point(2*a, b)
>>> t = Triangle(x, y, z)

>>> t.area
a*b/2

>>> t.medians[x]
Segment2D(Point2D(0, 0), Point2D(3*a/2, b/2))

>>> intersection(t.medians[x], t.medians[y], t.medians[z])
[Point2D(a, b/3)] 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

一个深入例子:帕普斯的六边形定理

来自维基百科(维基帕普斯):

给定一组共线点 (A), (B), (C), 和另一组共线点 (a), (b), (c), 则线对 (Ab) 和 (aB), (Ac) 和 (aC), (Bc) 和 (bC) 的交点 (X), (Y), (Z) 是共线的。

>>> from sympy import *
>>> from sympy.geometry import *
>>>
>>> l1 = Line(Point(0, 0), Point(5, 6))
>>> l2 = Line(Point(0, 0), Point(2, -2))
>>>
>>> def subs_point(l, val):
...  """Take an arbitrary point and make it a fixed point."""
...    t = Symbol('t', real=True)
...    ap = l.arbitrary_point()
...    return Point(ap.x.subs(t, val), ap.y.subs(t, val))
...
>>> p11 = subs_point(l1, 5)
>>> p12 = subs_point(l1, 6)
>>> p13 = subs_point(l1, 11)
>>>
>>> p21 = subs_point(l2, -1)
>>> p22 = subs_point(l2, 2)
>>> p23 = subs_point(l2, 13)
>>>
>>> ll1 = Line(p11, p22)
>>> ll2 = Line(p11, p23)
>>> ll3 = Line(p12, p21)
>>> ll4 = Line(p12, p23)
>>> ll5 = Line(p13, p21)
>>> ll6 = Line(p13, p22)
>>>
>>> pp1 = intersection(ll1, ll3)[0]
>>> pp2 = intersection(ll2, ll5)[0]
>>> pp3 = intersection(ll4, ll6)[0]
>>>
>>> Point.is_collinear(pp1, pp2, pp3)
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

参考文献

[维基帕普斯]

“帕普斯的六边形定理” 维基百科,自由百科全书。网络。2013 年 4 月 26 日。 <zh.wikipedia.org/wiki/%E6%B3%A2%E5%B8%95%E6%96%AF>

杂注

  • PolygonTriangle 的面积属性可能返回正值或负值,这取决于点的顺时针或逆时针方向。如果您总是希望得到正值,请确保使用 abs 函数。

  • 虽然多边形可以指任何类型的多边形,但代码是为简单多边形编写的。因此,如果处理复杂多边形(重叠边),请预期可能出现问题。

  • 因为 SymPy 还处于初期阶段,某些情况可能无法正确简化,因此一些应返回True的情况(例如Point.is_collinear)实际上可能不会返回。类似地,试图找到相交的实体的交点可能会导致空结果。

未来的工作

真值设置表达式

当处理符号实体时,经常会出现无法保证断言的情况。例如,考虑以下代码:

>>> from sympy import *
>>> from sympy.geometry import *
>>> x,y,z = map(Symbol, 'xyz')
>>> p1,p2,p3 = Point(x, y), Point(y, z), Point(2*x*y, y)
>>> Point.is_collinear(p1, p2, p3)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

即使结果目前是False,这并不总是真的。如果数量 (z - y - 2yz + 2*y**2 == 0),那么这些点将共线。告知用户这一点将非常有用,因为这样的数量可能对用户进行进一步的计算有用,至少知道这一点也是很好的。可以通过返回一个对象(例如,GeometryResult)来实现这一点,用户可以使用这个对象。实际上,这不需要大量的工作。

三维及以上

目前几何模块的有限子集已扩展到三维,但显然扩展更多将是一个很好的补充。这可能涉及相当多的工作,因为许多使用的算法是特定于二维的。

几何可视化

绘图模块能够绘制几何实体。在绘图模块条目中查看绘制几何实体。

子模块

  • 实体

  • 实用工具

  • 直线

  • 曲线

  • 椭圆

  • 多边形

  • 平面

实体

原始文档:docs.sympy.org/latest/modules/geometry/entities.html

class sympy.geometry.entity.GeometryEntity(*args, **kwargs)
  • 1

所有几何实体的基类。

此类不代表任何特定几何实体,仅提供所有子类常见方法的实现。

property ambient_dimension
  • 1

对象所包含的空间的维数是多少?

property bounds
  • 1

返回表示几何图形边界的矩形 (xmin, ymin, xmax, ymax) 元组。

encloses(o)
  • 1

如果o位于self的边界内部(而不是在边界上或外部),则返回True

将对象分解为点和单独的实体,只需为其类定义一个encloses_point方法。

示例

>>> from sympy import RegularPolygon, Point, Polygon
>>> t  = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
>>> t2 = Polygon(*RegularPolygon(Point(0, 0), 2, 3).vertices)
>>> t2.encloses(t)
True
>>> t.encloses(t2)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

另请参阅

sympy.geometry.ellipse.Ellipse.encloses_point, sympy.geometry.polygon.Polygon.encloses_point

intersection(o)
  • 1

返回与自身相交的所有交点列表。

注意

实体不需要实现此方法。

如果两种不同类型的实体可以相交,则在ordering_of_classes中索引较高的项目应实现与索引较低的任何项目的相交。

另请参阅

sympy.geometry.util.intersection

is_similar(other)
  • 1

此几何实体是否与另一几何实体相似?

如果可以通过统一缩放(放大或缩小)其中一个实体来获得另一个实体,则两个实体是相似的。

注意

此方法不打算直接使用,而是通过util.py中的are_similar函数。实体不需要实现此方法。如果两种不同类型的实体可以相似,则只需要其中一种能够确定这一点。

另请参阅

scale

parameter_value(other, t)
  • 1

返回与给定点对应的参数。在此参数值处评估实体的任意点将返回给定点。

示例

>>> from sympy import Line, Point
>>> from sympy.abc import t
>>> a = Point(0, 0)
>>> b = Point(2, 2)
>>> Line(a, b).parameter_value((1, 1), t)
{t: 1/2}
>>> Line(a, b).arbitrary_point(t).subs(_)
Point2D(1, 1) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
reflect(line)
  • 1

将对象沿线进行反射。

参数:

线:线

示例

>>> from sympy import pi, sqrt, Line, RegularPolygon
>>> l = Line((0, pi), slope=sqrt(2))
>>> pent = RegularPolygon((1, 2), 1, 5)
>>> rpent = pent.reflect(l)
>>> rpent
RegularPolygon(Point2D(-2*sqrt(2)*pi/3 - 1/3 + 4*sqrt(2)/3, 2/3 + 2*sqrt(2)/3 + 2*pi/3), -1, 5, -atan(2*sqrt(2)) + 3*pi/5) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
>>> from sympy import pi, Line, Circle, Point
>>> l = Line((0, pi), slope=1)
>>> circ = Circle(Point(0, 0), 5)
>>> rcirc = circ.reflect(l)
>>> rcirc
Circle(Point2D(-pi, pi), -5) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
rotate(angle, pt=None)
  • 1

以逆时针绕点pt旋转angle弧度。

默认pt为原点,Point(0, 0)

示例

>>> from sympy import Point, RegularPolygon, Polygon, pi
>>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
>>> t # vertex on x axis
Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2))
>>> t.rotate(pi/2) # vertex on y axis now
Triangle(Point2D(0, 1), Point2D(-sqrt(3)/2, -1/2), Point2D(sqrt(3)/2, -1/2)) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

另请参阅

scale, translate

scale(x=1, y=1, pt=None)
  • 1

通过将 x 和 y 坐标乘以 x 和 y 来缩放对象。

如果给定了pt,则按照该点进行缩放;对象被移动到-pt,进行缩放,然后再移动到pt

示例

>>> from sympy import RegularPolygon, Point, Polygon
>>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
>>> t
Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2))
>>> t.scale(2)
Triangle(Point2D(2, 0), Point2D(-1, sqrt(3)/2), Point2D(-1, -sqrt(3)/2))
>>> t.scale(2, 2)
Triangle(Point2D(2, 0), Point2D(-1, sqrt(3)), Point2D(-1, -sqrt(3))) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

另请参阅

rotate, translate

translate(x=0, y=0)
  • 1

将对象移动,通过增加 x 和 y 坐标的值。

示例

>>> from sympy import RegularPolygon, Point, Polygon
>>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
>>> t
Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2))
>>> t.translate(2)
Triangle(Point2D(3, 0), Point2D(3/2, sqrt(3)/2), Point2D(3/2, -sqrt(3)/2))
>>> t.translate(2, 2)
Triangle(Point2D(3, 2), Point2D(3/2, sqrt(3)/2 + 2), Point2D(3/2, 2 - sqrt(3)/2)) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

另见

rotate, scale

工具

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

sympy.geometry.util.intersection(*entities, pairwise=False, **kwargs)
  • 1

几何实体集合的交集。

参数:

entities:几何实体序列

pairwise (关键字参数):可以是 True 或 False

返回:

intersection:几何实体列表

引发:

未实现错误

当无法计算交集时。

注意

任何几何实体与自身的交集应返回包含该实体的列表中的一个项目。交集需要两个或更多实体。如果只给定一个单独实体,则该函数将返回一个空列表。可能由于未完全内部简化所需量而导致(intersection)错过已知存在的交点。实数应转换为有理数,例如 Rational(str(real_num)),否则可能由于浮点数问题而失败。

情况 1:当关键字参数‘pairwise’为 False(默认值)时:在这种情况下,函数返回所有实体共有的交集列表。

情况 2:当关键字参数‘pairwise’为 True 时:在这种情况下,函数返回发生在任意一对实体之间的交集列表。

示例

>>> from sympy import Ray, Circle, intersection
>>> c = Circle((0, 1), 1)
>>> intersection(c, c.center)
[]
>>> right = Ray((0, 0), (1, 0))
>>> up = Ray((0, 0), (0, 1))
>>> intersection(c, right, up)
[Point2D(0, 0)]
>>> intersection(c, right, up, pairwise=True)
[Point2D(0, 0), Point2D(0, 2)]
>>> left = Ray((1, 0), (0, 0))
>>> intersection(right, left)
[Segment2D(Point2D(0, 0), Point2D(1, 0))] 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

另请参阅

sympy.geometry.entity.GeometryEntity.intersection

sympy.geometry.util.convex_hull(*args, polygon=True)
  • 1

包含在实体列表中的点所围成的凸多边形。

参数:

args:一组点、线段和/或多边形

返回:

凸包:如果polygon为 True,则为多边形,否则为一个元组((U, L)),其中

LU 分别是下凸壳和上凸壳。

可选参数

polygonBoolean。如果为 True,则返回多边形;如果为 false,则返回一个元组,如下所示。

默认值为 True。

注意

这只能在其坐标可以在数轴上排序的一组点上执行。

示例

>>> from sympy import convex_hull
>>> points = [(1, 1), (1, 2), (3, 1), (-5, 2), (15, 4)]
>>> convex_hull(*points)
Polygon(Point2D(-5, 2), Point2D(1, 1), Point2D(3, 1), Point2D(15, 4))
>>> convex_hull(*points, **dict(polygon=False))
([Point2D(-5, 2), Point2D(15, 4)],
 [Point2D(-5, 2), Point2D(1, 1), Point2D(3, 1), Point2D(15, 4)]) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

另请参阅

sympy.geometry.point.Pointsympy.geometry.polygon.Polygon

参考文献

[R563]

zh.wikipedia.org/wiki/格雷厄姆扫描

[R564]

安德鲁单调链算法(A.M. Andrew,“另一种有效的二维凸包算法”,1979)web.archive.org/web/20210511015444/http://geomalgorithms.com/a10-_hull-1.html

sympy.geometry.util.are_similar(e1, e2)
  • 1

两个几何实体是否相似。

一个几何实体能否均匀缩放到另一个几何实体?

参数:

e1:几何实体

e2:几何实体

返回:

are_similar:布尔值

引发:

几何错误

当(e1)和(e2)无法比较时。

注意

如果两个对象相等,则它们是相似的。

示例

>>> from sympy import Point, Circle, Triangle, are_similar
>>> c1, c2 = Circle(Point(0, 0), 4), Circle(Point(1, 4), 3)
>>> t1 = Triangle(Point(0, 0), Point(1, 0), Point(0, 1))
>>> t2 = Triangle(Point(0, 0), Point(2, 0), Point(0, 2))
>>> t3 = Triangle(Point(0, 0), Point(3, 0), Point(0, 1))
>>> are_similar(t1, t2)
True
>>> are_similar(t1, t3)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

另请参阅

sympy.geometry.entity.GeometryEntity.is_similar

sympy.geometry.util.centroid(*args)
  • 1

寻找仅包含点、线段或多边形的集合的质心(重心)。 质心是各个质心的加权平均值,其中权重是长度(线段)或面积(多边形)。 重叠区域将增加该区域的权重。

如果没有对象(或混合对象),则返回None

示例

>>> from sympy import Point, Segment, Polygon
>>> from sympy.geometry.util import centroid
>>> p = Polygon((0, 0), (10, 0), (10, 10))
>>> q = p.translate(0, 20)
>>> p.centroid, q.centroid
(Point2D(20/3, 10/3), Point2D(20/3, 70/3))
>>> centroid(p, q)
Point2D(20/3, 40/3)
>>> p, q = Segment((0, 0), (2, 0)), Segment((0, 0), (2, 2))
>>> centroid(p, q)
Point2D(1, 2 - sqrt(2))
>>> centroid(Point(0, 0), Point(2, 0))
Point2D(1, 0) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

将 3 个多边形堆叠在一起有效地使该多边形的重量增加三倍:

>>> p = Polygon((0, 0), (1, 0), (1, 1), (0, 1))
>>> q = Polygon((1, 0), (3, 0), (3, 1), (1, 1))
>>> centroid(p, q)
Point2D(3/2, 1/2)
>>> centroid(p, p, p, q) # centroid x-coord shifts left
Point2D(11/10, 1/2) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

将正方形垂直堆叠在p的上方和下方具有相同的效果:

>>> centroid(p, p.translate(0, 1), p.translate(0, -1), q)
Point2D(11/10, 1/2) 
  • 1
  • 2

另请参阅

sympy.geometry.point.Point, sympy.geometry.line.Segment, sympy.geometry.polygon.Polygon

sympy.geometry.util.idiff(eq, y, x, n=1)
  • 1

假设eq == 0,返回dy/dx

参数:

y:因变量或因变量列表(以y开头)

x:进行导数计算的变量

n:导数的阶数(默认为 1)

示例

>>> from sympy.abc import x, y, a
>>> from sympy.geometry.util import idiff 
  • 1
  • 2
>>> circ = x**2 + y**2 - 4
>>> idiff(circ, y, x)
-x/y
>>> idiff(circ, y, x, 2).simplify()
(-x**2 - y**2)/y**3 
  • 1
  • 2
  • 3
  • 4
  • 5

在这里,假设ax无关:

>>> idiff(x + a + y, y, x)
-1 
  • 1
  • 2

现在通过在列表中将a列在y之后,使得a的 x 依赖性变得明确。

>>> idiff(x + a + y, [y, a], x)
-Derivative(a, x) - 1 
  • 1
  • 2

另请参阅

sympy.core.function.Derivative

表示未求值的导数

sympy.core.function.diff

显式地针对符号进行微分

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

class sympy.geometry.point.Point(*args, **kwargs)
  • 1

n 维欧几里得空间中的一个点。

参数:

coords:n 个坐标值的序列。在特定

情况下,n=2 或 3,将相应创建 Point2D 或 Point3D。

evaluate:如果为 (True)(默认值),所有浮点数都会转换为

精确的类型。

dim:点应具有的坐标数。如果坐标

未指定时,它们将填充为零。

on_morph:指示当数量变化时应该发生什么

通过添加或删除零来更改点的坐标。可能的值为 (‘warn’), (‘error’), 或 (ignore)(默认)。当 (*args) 为空且给定 (dim) 时不发出警告或错误。尝试移除非零坐标时总是引发错误。

引发:

TypeError:当使用不是 Point 或序列的东西进行实例化时

ValueError:当使用长度小于 2 或

尝试减少维度时,如果设置了关键字 (on_morph=‘error’),则会引发错误。

示例

>>> from sympy import Point
>>> from sympy.abc import x
>>> Point(1, 2, 3)
Point3D(1, 2, 3)
>>> Point([1, 2])
Point2D(1, 2)
>>> Point(0, x)
Point2D(0, x)
>>> Point(dim=4)
Point(0, 0, 0, 0) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

浮点数会自动转换为 Rational,除非 evaluate 标志为 False:

>>> Point(0.5, 0.25)
Point2D(1/2, 1/4)
>>> Point(0.5, 0.25, evaluate=False)
Point2D(0.5, 0.25) 
  • 1
  • 2
  • 3
  • 4

参见

sympy.geometry.line.Segment

连接两个点

属性

长度
原点:表示适当维度空间的原点。
static affine_rank(*args)
  • 1

一组点的仿射秩是包含所有点的最小仿射空间的维数。例如,如果点位于一条直线上(并且不全相同),它们的仿射秩为 1。如果点位于平面上但不是一条直线,则它们的仿射秩为 2。按照惯例,空集的仿射秩为 -1。

property ambient_dimension
  • 1

此点具有的组件数量。

classmethod are_coplanar(*points)
  • 1

如果存在一个平面,所有点都位于其中,则返回 True。如果 (len(points) < 3) 或所有点都是二维的,则返回一个平凡的 True 值。

参数:

一组点

返回:

布尔值

引发:

ValueError:如果给出的唯一点少于 3 个

示例

>>> from sympy import Point3D
>>> p1 = Point3D(1, 2, 2)
>>> p2 = Point3D(2, 7, 2)
>>> p3 = Point3D(0, 0, 2)
>>> p4 = Point3D(1, 1, 2)
>>> Point3D.are_coplanar(p1, p2, p3, p4)
True
>>> p5 = Point3D(0, 1, 3)
>>> Point3D.are_coplanar(p1, p2, p3, p5)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
canberra_distance(p)
  • 1

从 self 到点 p 的 Canberra 距离。

返回到点 p 的水平和垂直距离的加权和。

参数:

p:点

返回:

canberra_distance:水平和垂直的加权和

到点 p 的距离。使用的权重是绝对值之和

坐标的

引发:

ValueError 当两个向量都为零时。

示例

>>> from sympy import Point
>>> p1, p2 = Point(1, 1), Point(3, 3)
>>> p1.canberra_distance(p2)
1
>>> p1, p2 = Point(0, 0), Point(3, 3)
>>> p1.canberra_distance(p2)
2 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

参见

sympy.geometry.point.Point.distance

distance(other)
  • 1

self 和另一个 GeometricEntity 之间的欧几里得距离。

返回:

distance:数字或符号表达式。

引发:

TypeError:如果其他对象不能识别为 GeometricEntity 或是

未定义距离的 GeometricEntity。

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 1), Point(4, 5)
>>> l = Line((3, 1), (2, 2))
>>> p1.distance(p2)
5
>>> p1.distance(l)
sqrt(2) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

计算得到的距离也可能是符号的:

>>> from sympy.abc import x, y
>>> p3 = Point(x, y)
>>> p3.distance((0, 0))
sqrt(x**2 + y**2) 
  • 1
  • 2
  • 3
  • 4

参见

sympy.geometry.line.Segment.length, sympy.geometry.point.Point.taxicab_distance

dot(p)
  • 1

返回 self 与另一个点的点积。

equals(other)
  • 1

返回 self 和 other 的坐标是否一致。

intersection(other)
  • 1

该点与另一个几何实体的交点。

参数:

其他 : 几何实体或坐标序列

返回:

交点 : 点列表

注释

如果没有交点则返回空列表,否则将包含该点。

示例

>>> from sympy import Point
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 0)
>>> p1.intersection(p2)
[]
>>> p1.intersection(p3)
[Point2D(0, 0)] 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
is_collinear(*args)
  • 1

如果存在一条包含 self 和 points 的直线,则返回 True。否则返回 False。如果未给出任何点,则返回一个显然为 True 的值。

参数:

args : 点序列

返回:

共线 : 布尔值

示例

>>> from sympy import Point
>>> from sympy.abc import x
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> p3, p4, p5 = Point(2, 2), Point(x, x), Point(1, 2)
>>> Point.is_collinear(p1, p2, p3, p4)
True
>>> Point.is_collinear(p1, p2, p3, p5)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

另见

sympy.geometry.line.Line

is_concyclic(*args)
  • 1

self 和给定的点序列是否在同一个圆内?

如果点集是共圆的则返回 True,否则返回 False。如果点数少于 2 个,则返回一个显然为 True 的值。

参数:

args : 点序列

返回:

共圆 : 布尔值

示例

>>> from sympy import Point 
  • 1

定义 4 个位于单位圆上的点:

>>> p1, p2, p3, p4 = Point(1, 0), (0, 1), (-1, 0), (0, -1) 
  • 1
>>> p1.is_concyclic() == p1.is_concyclic(p2, p3, p4) == True
True 
  • 1
  • 2

定义一个不在该圆上的点:

>>> p = Point(1, 1) 
  • 1
>>> p.is_concyclic(p1, p2, p3)
False 
  • 1
  • 2
property is_nonzero
  • 1

如果任何坐标非零,则为 True,如果每个坐标都为零,则为 False,如果无法确定,则为 None。

is_scalar_multiple(p)
  • 1

返回 self 的每个坐标是否是点 p 对应坐标的标量倍。

property is_zero
  • 1

如果每个坐标都为零,则为 True,如果任何坐标不为零,则为 False,如果无法确定,则为 None。

property length
  • 1

将点视为线,返回点的长度为 0。

示例

>>> from sympy import Point
>>> p = Point(0, 1)
>>> p.length
0 
  • 1
  • 2
  • 3
  • 4
midpoint(p)
  • 1

自身和点 p 之间的中点。

参数:

p : 点

返回:

中点 : 点

示例

>>> from sympy import Point
>>> p1, p2 = Point(1, 1), Point(13, 5)
>>> p1.midpoint(p2)
Point2D(7, 3) 
  • 1
  • 2
  • 3
  • 4

另见

sympy.geometry.line.Segment.midpoint

property origin
  • 1

与当前点环境维度相同的所有零点

property orthogonal_direction
  • 1

返回一个与包含 self 和原点的线垂直的非零点。

示例

>>> from sympy import Line, Point
>>> a = Point(1, 2, 3)
>>> a.orthogonal_direction
Point3D(-2, 1, 0)
>>> b = _
>>> Line(b, b.origin).is_perpendicular(Line(a, a.origin))
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
static project(a, b)
  • 1

将点 a 投影到原点和点 b 之间的线上,沿法线方向。

参数:

a : 点

b : 点

返回:

p : 点

示例

>>> from sympy import Line, Point
>>> a = Point(1, 2)
>>> b = Point(2, 5)
>>> z = a.origin
>>> p = Point.project(a, b)
>>> Line(p, a).is_perpendicular(Line(p, b))
True
>>> Point.is_collinear(z, p, b)
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

另见

sympy.geometry.line.LinearEntity.projection

taxicab_distance(p)
  • 1

self 到点 p 的曼哈顿距离。

返回到点 p 的水平和垂直距离的总和。

参数:

p : 点

返回:

曼哈顿距离 : 水平方向的总和

和到点 p 的垂直距离。

示例

>>> from sympy import Point
>>> p1, p2 = Point(1, 1), Point(4, 5)
>>> p1.taxicab_distance(p2)
7 
  • 1
  • 2
  • 3
  • 4

另见

sympy.geometry.point.Point.distance

property unit
  • 1

返回与 (self) 方向相同且距原点距离为 1 的点。

class sympy.geometry.point.Point2D(*args, _nocheck=False, **kwargs)
  • 1

二维欧几里得空间中的一个点。

Parameters:

坐标

两个坐标值的序列。

抛出:

类型错误

尝试添加或减去不同维度的点时。尝试创建超过两个维度的点时。调用 (intersection) 时使用的对象不是点。

示例

>>> from sympy import Point2D
>>> from sympy.abc import x
>>> Point2D(1, 2)
Point2D(1, 2)
>>> Point2D([1, 2])
Point2D(1, 2)
>>> Point2D(0, x)
Point2D(0, x) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

浮点数会自动转换为有理数,除非 evaluate 标志为 False:

>>> Point2D(0.5, 0.25)
Point2D(1/2, 1/4)
>>> Point2D(0.5, 0.25, evaluate=False)
Point2D(0.5, 0.25) 
  • 1
  • 2
  • 3
  • 4

参见

sympy.geometry.line.Segment

连接两个点。

属性

x
y
长度
property bounds
  • 1

返回表示几何图形的边界矩形的元组 (xmin, ymin, xmax, ymax)。

property coordinates
  • 1

返回点的两个坐标。

示例

>>> from sympy import Point2D
>>> p = Point2D(0, 1)
>>> p.coordinates
(0, 1) 
  • 1
  • 2
  • 3
  • 4
rotate(angle, pt=None)
  • 1

绕点 pt 逆时针旋转 angle 弧度。

示例

>>> from sympy import Point2D, pi
>>> t = Point2D(1, 0)
>>> t.rotate(pi/2)
Point2D(0, 1)
>>> t.rotate(pi/2, (2, 0))
Point2D(2, -1) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

参见

translate, scale

scale(x=1, y=1, pt=None)
  • 1

通过在减去 pt(默认为 (0, 0))之后乘以 xy,然后再将 pt 加回来来缩放点的坐标(即 pt 是缩放的参考点)。

示例

>>> from sympy import Point2D
>>> t = Point2D(1, 1)
>>> t.scale(2)
Point2D(2, 1)
>>> t.scale(2, 2)
Point2D(2, 2) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

参见

rotate, translate

transform(matrix)
  • 1

应用由 3x3 矩阵 matrix 描述的变换后的点。

参见

sympy.geometry.point.Point2D.rotate, sympy.geometry.point.Point2D.scale, sympy.geometry.point.Point2D.translate

translate(x=0, y=0)
  • 1

将点移动,通过将 x 和 y 添加到点的坐标中。

示例

>>> from sympy import Point2D
>>> t = Point2D(0, 1)
>>> t.translate(2)
Point2D(2, 1)
>>> t.translate(2, 2)
Point2D(2, 3)
>>> t + Point2D(2, 2)
Point2D(2, 3) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

参见

sympy.geometry.point.Point2D.rotate, scale

property x
  • 1

返回点的 X 坐标。

示例

>>> from sympy import Point2D
>>> p = Point2D(0, 1)
>>> p.x
0 
  • 1
  • 2
  • 3
  • 4
property y
  • 1

返回点的 Y 坐标。

示例

>>> from sympy import Point2D
>>> p = Point2D(0, 1)
>>> p.y
1 
  • 1
  • 2
  • 3
  • 4
class sympy.geometry.point.Point3D(*args, _nocheck=False, **kwargs)
  • 1

三维欧几里得空间中的一个点。

参数:

坐标

三个坐标值的序列。

抛出:

类型错误

尝试添加或减去不同维度的点时。调用 (intersection) 时使用的对象不是点。

示例

>>> from sympy import Point3D
>>> from sympy.abc import x
>>> Point3D(1, 2, 3)
Point3D(1, 2, 3)
>>> Point3D([1, 2, 3])
Point3D(1, 2, 3)
>>> Point3D(0, x, 3)
Point3D(0, x, 3) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

浮点数会自动转换为有理数,除非 evaluate 标志为 False:

>>> Point3D(0.5, 0.25, 2)
Point3D(1/2, 1/4, 2)
>>> Point3D(0.5, 0.25, 3, evaluate=False)
Point3D(0.5, 0.25, 3) 
  • 1
  • 2
  • 3
  • 4

属性

x
y
z
长度
static are_collinear(*points)
  • 1

一系列点是否共线?

测试一组点是否共线。如果一组点共线,则返回 True,否则返回 False。

参数:

points : 点的序列

返回:

are_collinear : 布尔值

示例

>>> from sympy import Point3D
>>> from sympy.abc import x
>>> p1, p2 = Point3D(0, 0, 0), Point3D(1, 1, 1)
>>> p3, p4, p5 = Point3D(2, 2, 2), Point3D(x, x, x), Point3D(1, 2, 6)
>>> Point3D.are_collinear(p1, p2, p3, p4)
True
>>> Point3D.are_collinear(p1, p2, p3, p5)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

参见

sympy.geometry.line.Line3D

property coordinates
  • 1

返回点的三个坐标。

示例

>>> from sympy import Point3D
>>> p = Point3D(0, 1, 2)
>>> p.coordinates
(0, 1, 2) 
  • 1
  • 2
  • 3
  • 4
direction_cosine(point)
  • 1

给出两点之间的方向余弦

参数:

p:Point3D

返回:

列表

示例

>>> from sympy import Point3D
>>> p1 = Point3D(1, 2, 3)
>>> p1.direction_cosine(Point3D(2, 3, 5))
[sqrt(6)/6, sqrt(6)/6, sqrt(6)/3] 
  • 1
  • 2
  • 3
  • 4
direction_ratio(point)
  • 1

给出两点之间的方向比率

参数:

p:Point3D

返回:

列表

示例

>>> from sympy import Point3D
>>> p1 = Point3D(1, 2, 3)
>>> p1.direction_ratio(Point3D(2, 3, 5))
[1, 1, 2] 
  • 1
  • 2
  • 3
  • 4
intersection(other)
  • 1

这一点与另一个几何实体的交点。

参数:

other:几何实体或坐标序列

返回:

intersection:点的列表

注意

如果没有交点,则返回空列表;否则返回此点。

示例

>>> from sympy import Point3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, 0, 0)
>>> p1.intersection(p2)
[]
>>> p1.intersection(p3)
[Point3D(0, 0, 0)] 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
scale(x=1, y=1, z=1, pt=None)
  • 1

通过将点减去pt(默认为(0, 0)),然后乘以xy,再加回pt(即pt是缩放的参考点),来缩放点的坐标。

示例

>>> from sympy import Point3D
>>> t = Point3D(1, 1, 1)
>>> t.scale(2)
Point3D(2, 1, 1)
>>> t.scale(2, 2)
Point3D(2, 2, 1) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

参见

translate

transform(matrix)
  • 1

应用描述为 4x4 矩阵matrix的变换后返回点。

参见

sympy.geometry.point.Point3D.scale, sympy.geometry.point.Point3D.translate

translate(x=0, y=0, z=0)
  • 1

将点位移,通过将 x 和 y 添加到点的坐标中。

示例

>>> from sympy import Point3D
>>> t = Point3D(0, 1, 1)
>>> t.translate(2)
Point3D(2, 1, 1)
>>> t.translate(2, 2)
Point3D(2, 3, 1)
>>> t + Point3D(2, 2, 2)
Point3D(2, 3, 3) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

参见

scale

property x
  • 1

返回点的 X 坐标。

示例

>>> from sympy import Point3D
>>> p = Point3D(0, 1, 3)
>>> p.x
0 
  • 1
  • 2
  • 3
  • 4
property y
  • 1

返回点的 Y 坐标。

示例

>>> from sympy import Point3D
>>> p = Point3D(0, 1, 2)
>>> p.y
1 
  • 1
  • 2
  • 3
  • 4
property z
  • 1

返回点的 Z 坐标。

示例

>>> from sympy import Point3D
>>> p = Point3D(0, 1, 1)
>>> p.z
1 
  • 1
  • 2
  • 3
  • 4

线

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

class sympy.geometry.line.LinearEntity(p1, p2=None, **kwargs)
  • 1

n-维欧几里得空间中所有线性实体(线、射线和线段)的基类。

注意

这是一个抽象类,不应被实例化。

另请参阅

sympy.geometry.entity.GeometryEntity

属性

环境维度
方向
长度
p1
p2
property ambient_dimension
  • 1

返回线性实体对象的维度的属性方法。

参数:

p1:线性实体

返回:

维度:整数

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> l1 = Line(p1, p2)
>>> l1.ambient_dimension
2 
  • 1
  • 2
  • 3
  • 4
  • 5
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0, 0), Point(1, 1, 1)
>>> l1 = Line(p1, p2)
>>> l1.ambient_dimension
3 
  • 1
  • 2
  • 3
  • 4
  • 5
angle_between(l2)
  • 1

返回由从原点发出方向与线性实体的方向向量相同的射线形成的非反射角。

参数:

l1:线性实体

l2:线性实体

返回:

角度:弧度制的角度

注意

根据向量 v1 和 v2 的点积,已知:

dot(v1, v2) = |v1|*|v2|*cos(A)

其中 A 是两个向量之间形成的角度。我们可以获取两条线的方向向量,并利用上述公式轻松找到两者之间的角度。

示例

>>> from sympy import Line
>>> e = Line((0, 0), (1, 0))
>>> ne = Line((0, 0), (1, 1))
>>> sw = Line((1, 1), (0, 0))
>>> ne.angle_between(e)
pi/4
>>> sw.angle_between(e)
3*pi/4 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

要获取线交点处的非钝角,请使用smallest_angle_between方法:

>>> sw.smallest_angle_between(e)
pi/4 
  • 1
  • 2
>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(-1, 2, 0)
>>> l1, l2 = Line3D(p1, p2), Line3D(p2, p3)
>>> l1.angle_between(l2)
acos(-sqrt(2)/3)
>>> l1.smallest_angle_between(l2)
acos(sqrt(2)/3) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

另请参阅

is_perpendicular, Ray2D.closing_angle

arbitrary_point(parameter='t')
  • 1

线上的参数化点。

参数:

参数:字符串,可选

将用于参数点的参数的名称。默认值为‘t’。当此参数为 0 时,将返回用于定义线的第一个点,当它为 1 时,将返回第二个点。

返回:

:点

引发:

ValueError

当参数在线的定义中已经出现时。

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.arbitrary_point()
Point2D(4*t + 1, 3*t)
>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(1, 0, 0), Point3D(5, 3, 1)
>>> l1 = Line3D(p1, p2)
>>> l1.arbitrary_point()
Point3D(4*t + 1, 3*t, t) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

另请参阅

sympy.geometry.point.Point

static are_concurrent(*lines)
  • 1

一系列线性实体是否共线?

如果两个或更多线性实体在一个点相交,则它们是共线的。

参数:

线

一系列线性实体。

返回:

True:如果线性实体集合在一个点相交

False:否则。

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> p3, p4 = Point(-2, -2), Point(0, 2)
>>> l1, l2, l3 = Line(p1, p2), Line(p1, p3), Line(p1, p4)
>>> Line.are_concurrent(l1, l2, l3)
True
>>> l4 = Line(p2, p3)
>>> Line.are_concurrent(l2, l3, l4)
False
>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(3, 5, 2)
>>> p3, p4 = Point3D(-2, -2, -2), Point3D(0, 2, 1)
>>> l1, l2, l3 = Line3D(p1, p2), Line3D(p1, p3), Line3D(p1, p4)
>>> Line3D.are_concurrent(l1, l2, l3)
True
>>> l4 = Line3D(p2, p3)
>>> Line3D.are_concurrent(l2, l3, l4)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

另请参阅

sympy.geometry.util.intersection

bisectors(other)
  • 1

返回通过自身和其他相交点的垂直线,这些相交点在同一平面上。

参数:

线:三维线

返回:

列表:两个线实例

示例

>>> from sympy import Point3D, Line3D
>>> r1 = Line3D(Point3D(0, 0, 0), Point3D(1, 0, 0))
>>> r2 = Line3D(Point3D(0, 0, 0), Point3D(0, 1, 0))
>>> r1.bisectors(r2)
[Line3D(Point3D(0, 0, 0), Point3D(1, 1, 0)), Line3D(Point3D(0, 0, 0), Point3D(1, -1, 0))] 
  • 1
  • 2
  • 3
  • 4
  • 5
contains(other)
  • 1

子类应实现此方法,如果其他在自身的边界上则返回 True;如果不在自身的边界上则返回 False;如果无法确定则返回 None。

property direction
  • 1

线性实体的方向向量。

返回:

p:一个点;从原点到该点的射线是

(self)的方向

示例

>>> from sympy import Line
>>> a, b = (1, 1), (1, 3)
>>> Line(a, b).direction
Point2D(0, 2)
>>> Line(b, a).direction
Point2D(0, -2) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

这可以报告从原点到的距离是 1:

>>> Line(b, a).direction.unit
Point2D(0, -1) 
  • 1
  • 2

参见

sympy.geometry.point.Point.unit

intersection(other)
  • 1

与另一个几何实体的交点。

参数:

o:点或线性实体

返回:

intersection:几何实体的列表

示例

>>> from sympy import Point, Line, Segment
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(7, 7)
>>> l1 = Line(p1, p2)
>>> l1.intersection(p3)
[Point2D(7, 7)]
>>> p4, p5 = Point(5, 0), Point(0, 3)
>>> l2 = Line(p4, p5)
>>> l1.intersection(l2)
[Point2D(15/8, 15/8)]
>>> p6, p7 = Point(0, 5), Point(2, 6)
>>> s1 = Segment(p6, p7)
>>> l1.intersection(s1)
[]
>>> from sympy import Point3D, Line3D, Segment3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(7, 7, 7)
>>> l1 = Line3D(p1, p2)
>>> l1.intersection(p3)
[Point3D(7, 7, 7)]
>>> l1 = Line3D(Point3D(4,19,12), Point3D(5,25,17))
>>> l2 = Line3D(Point3D(-3, -15, -19), direction_ratio=[2,8,8])
>>> l1.intersection(l2)
[Point3D(1, 1, -3)]
>>> p6, p7 = Point3D(0, 5, 2), Point3D(2, 6, 3)
>>> s1 = Segment3D(p6, p7)
>>> l1.intersection(s1)
[] 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

参见

sympy.geometry.point.Point

is_parallel(l2)
  • 1

两个线性实体是否平行?

参数:

l1:线性实体

l2:线性实体

返回:

True:如果( l1 )和( l2 )平行,

False:否则。

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> p3, p4 = Point(3, 4), Point(6, 7)
>>> l1, l2 = Line(p1, p2), Line(p3, p4)
>>> Line.is_parallel(l1, l2)
True
>>> p5 = Point(6, 6)
>>> l3 = Line(p3, p5)
>>> Line.is_parallel(l1, l3)
False
>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(3, 4, 5)
>>> p3, p4 = Point3D(2, 1, 1), Point3D(8, 9, 11)
>>> l1, l2 = Line3D(p1, p2), Line3D(p3, p4)
>>> Line3D.is_parallel(l1, l2)
True
>>> p5 = Point3D(6, 6, 6)
>>> l3 = Line3D(p3, p5)
>>> Line3D.is_parallel(l1, l3)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

参见

coefficients

is_perpendicular(l2)
  • 1

两个线性实体是否垂直?

参数:

l1:线性实体

l2:线性实体

返回:

True:如果( l1 )和( l2 )垂直,

False:否则。

示例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(-1, 1)
>>> l1, l2 = Line(p1, p2), Line(p1, p3)
>>> l1.is_perpendicular(l2)
True
>>> p4 = Point(5, 3)
>>> l3 = Line(p1, p4)
>>> l1.is_perpendicular(l3)
False
>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(-1, 2, 0)
>>> l1, l2 = Line3D(p1, p2), Line3D(p2, p3)
>>> l1.is_perpendicular(l2)
False
>>> p4 = Point3D(5, 3, 7)
>>> l3 = Line3D(p1, p4)
>>> l1.is_perpendicular(l3)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

参见

coefficients

is_similar(other)
  • 1

如果 self 和其他位于同一条线上,则返回 True。

示例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 1), Point(3, 4), Point(2, 3)
>>> l1 = Line(p1, p2)
>>> l2 = Line(p1, p3)
>>> l1.is_similar(l2)
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
property length
  • 1

线的长度。

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> l1 = Line(p1, p2)
>>> l1.length
oo 
  • 1
  • 2
  • 3
  • 4
  • 5
property p1
  • 1

线性实体的第一个定义点。

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.p1
Point2D(0, 0) 
  • 1
  • 2
  • 3
  • 4
  • 5

参见

sympy.geometry.point.Point

property p2
  • 1

线性实体的第二个定义点。

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.p2
Point2D(5, 3) 
  • 1
  • 2
  • 3
  • 4
  • 5

参见

sympy.geometry.point.Point

parallel_line(p)
  • 1

创建一条新的线,与通过点( p )的这个线性实体平行。

参数:

p:点

返回:

line:线

示例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2)
>>> l1 = Line(p1, p2)
>>> l2 = l1.parallel_line(p3)
>>> p3 in l2
True
>>> l1.is_parallel(l2)
True
>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(2, 3, 4), Point3D(-2, 2, 0)
>>> l1 = Line3D(p1, p2)
>>> l2 = l1.parallel_line(p3)
>>> p3 in l2
True
>>> l1.is_parallel(l2)
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

参见

is_parallel

perpendicular_line(p)
  • 1

创建一条新的线,垂直于该线性实体,通过点( p )。

参数:

p:点

返回:

line:线

示例

>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(2, 3, 4), Point3D(-2, 2, 0)
>>> L = Line3D(p1, p2)
>>> P = L.perpendicular_line(p3); P
Line3D(Point3D(-2, 2, 0), Point3D(4/29, 6/29, 8/29))
>>> L.is_perpendicular(P)
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在三维空间中,定义线条的第一个点是需要通过的垂直线通过的点;第二个点(任意地)包含在给定的线条中:

>>> P.p2 in L
True 
  • 1
  • 2

参见

sympy.geometry.line.LinearEntity.is_perpendicular, perpendicular_segment

perpendicular_segment(p)
  • 1

创建从( p )到这条线的垂直线段。

线段的端点是p和包含 self 的线中的最近点。(如果 self 不是一条线,则该点可能不在 self 中。)

参数:

p:点

返回:

segment:线段

注意

如果( p )在这个线性实体上,则返回( p )本身。

示例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 2)
>>> l1 = Line(p1, p2)
>>> s1 = l1.perpendicular_segment(p3)
>>> l1.is_perpendicular(s1)
True
>>> p3 in s1
True
>>> l1.perpendicular_segment(Point(4, 0))
Segment2D(Point2D(4, 0), Point2D(2, 2))
>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, 2, 0)
>>> l1 = Line3D(p1, p2)
>>> s1 = l1.perpendicular_segment(p3)
>>> l1.is_perpendicular(s1)
True
>>> p3 in s1
True
>>> l1.perpendicular_segment(Point3D(4, 0, 0))
Segment3D(Point3D(4, 0, 0), Point3D(4/3, 4/3, 4/3)) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

参见

perpendicular_line

property points
  • 1

用于定义这个线性实体的两个点。

返回:

points:点的元组

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 11)
>>> l1 = Line(p1, p2)
>>> l1.points
(Point2D(0, 0), Point2D(5, 11)) 
  • 1
  • 2
  • 3
  • 4
  • 5

参见

sympy.geometry.point.Point

projection(other)
  • 1

将点、线、射线或线段投影到此线性实体上。

参数:

other:点或线性实体(线、射线、线段)

返回:

投影:点或线性实体(线、射线、线段)

返回类型与参数other的类型匹配。

引发:

几何错误

当方法无法执行投影时。

注意

投影涉及取两个定义线性实体的点,并将这些点投影到一条线上,然后使用这些投影重新形成线性实体。 点 P 通过找到距离 P 最近的 L 上的点来投影到线 L 上。 此点是与通过 P 的垂直于 L 的线的 L 的交点。

示例

>>> from sympy import Point, Line, Segment, Rational
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(Rational(1, 2), 0)
>>> l1 = Line(p1, p2)
>>> l1.projection(p3)
Point2D(1/4, 1/4)
>>> p4, p5 = Point(10, 0), Point(12, 1)
>>> s1 = Segment(p4, p5)
>>> l1.projection(s1)
Segment2D(Point2D(5, 5), Point2D(13/2, 13/2))
>>> p1, p2, p3 = Point(0, 0, 1), Point(1, 1, 2), Point(2, 0, 1)
>>> l1 = Line(p1, p2)
>>> l1.projection(p3)
Point3D(2/3, 2/3, 5/3)
>>> p4, p5 = Point(10, 0, 1), Point(12, 1, 3)
>>> s1 = Segment(p4, p5)
>>> l1.projection(s1)
Segment3D(Point3D(10/3, 10/3, 13/3), Point3D(5, 5, 6)) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

另请参见

sympy.geometry.point.Point, perpendicular_line

random_point(seed=None)
  • 1

线性实体上的随机点。

返回:

point:点

示例

>>> from sympy import Point, Line, Ray, Segment
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> line = Line(p1, p2)
>>> r = line.random_point(seed=42)  # seed value is optional
>>> r.n(3)
Point2D(-0.72, -0.432)
>>> r in line
True
>>> Ray(p1, p2).random_point(seed=42).n(3)
Point2D(0.72, 0.432)
>>> Segment(p1, p2).random_point(seed=42).n(3)
Point2D(3.2, 1.92) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

另请参见

sympy.geometry.point.Point

smallest_angle_between(l2)
  • 1

返回形成线性实体包含的线的交点处的最小角度。

参数:

l1:线性实体

l2:线性实体

返回:

角度:弧度角

示例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(0, 4), Point(2, -2)
>>> l1, l2 = Line(p1, p2), Line(p1, p3)
>>> l1.smallest_angle_between(l2)
pi/4 
  • 1
  • 2
  • 3
  • 4
  • 5

另请参见

angle_between, is_perpendicular, Ray2D.closing_angle

class sympy.geometry.line.Line(*args, **kwargs)
  • 1

空间中的无限直线。

使用两个不同的点、点和斜率或方程式声明 2D 线。可以用点和方向比例定义 3D 线。

参数:

p1:点

p2:点

斜率:SymPy 表达式

direction_ratio:列表

equation:线的方程

注意

(Line)将根据(p1)的维度自动子类化为(Line2D)或(Line3D)。 (slope)参数仅与(Line2D)相关,(direction_ratio)参数仅与(Line3D)相关。

点的顺序将定义用于计算线之间角度的线的方向。

示例

>>> from sympy import Line, Segment, Point, Eq
>>> from sympy.abc import x, y, a, b 
  • 1
  • 2
>>> L = Line(Point(2,3), Point(3,5))
>>> L
Line2D(Point2D(2, 3), Point2D(3, 5))
>>> L.points
(Point2D(2, 3), Point2D(3, 5))
>>> L.equation()
-2*x + y + 1
>>> L.coefficients
(-2, 1, 1) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

使用关键字slope进行实例化:

>>> Line(Point(0, 0), slope=0)
Line2D(Point2D(0, 0), Point2D(1, 0)) 
  • 1
  • 2

用另一个线性对象实例化

>>> s = Segment((0, 0), (0, 1))
>>> Line(s).equation()
x 
  • 1
  • 2
  • 3

对应于方程(ax + by + c = 0)的线,可以输入:

>>> Line(3*x + y + 18)
Line2D(Point2D(0, -18), Point2D(1, -21)) 
  • 1
  • 2

如果(x)或(y)有不同的名称,则也可以指定为字符串(以匹配名称)或符号:

>>> Line(Eq(3*a + b, -18), x='a', y=b)
Line2D(Point2D(0, -18), Point2D(1, -21)) 
  • 1
  • 2

另请参见

sympy.geometry.point.Point, sympy.geometry.line.Line2D, sympy.geometry.line.Line3D

contains(other)
  • 1

如果 (other) 在此直线上,则返回 True;否则返回 False。

示例

>>> from sympy import Line,Point
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> l = Line(p1, p2)
>>> l.contains(p1)
True
>>> l.contains((0, 1))
True
>>> l.contains((0, 0))
False
>>> a = (0, 0, 0)
>>> b = (1, 1, 1)
>>> c = (2, 2, 2)
>>> l1 = Line(a, b)
>>> l2 = Line(b, a)
>>> l1 == l2
False
>>> l1 in l2
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
distance(other)
  • 1

查找线与点之间的最短距离。

引发:

如果 other 不是点,则会引发 NotImplementedError

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> s = Line(p1, p2)
>>> s.distance(Point(-1, 1))
sqrt(2)
>>> s.distance((-1, 2))
3*sqrt(2)/2
>>> p1, p2 = Point(0, 0, 0), Point(1, 1, 1)
>>> s = Line(p1, p2)
>>> s.distance(Point(-1, 1, 1))
2*sqrt(6)/3
>>> s.distance((-1, 1, 1))
2*sqrt(6)/3 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
equals(other)
  • 1

如果自身与其他数学实体相同,则返回 True。

plot_interval(parameter='t')
  • 1

线的默认几何图形绘制区间。提供将产生长度为 +/- 5 个单位的线的值(其中单位是定义线的两点之间的距离)。

参数:

parameter:字符串,可选

默认值为 ‘t’。

返回:

plot_interval:列表(绘图区间)

[parameter, lower_bound, upper_bound]

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.plot_interval()
[t, -5, 5] 
  • 1
  • 2
  • 3
  • 4
  • 5
class sympy.geometry.line.Ray(p1, p2=None, **kwargs)
  • 1

射线是空间中的半线,具有源点和方向。

参数:

p1:点

射线的源点

p2:点或弧度值

此点确定射线传播的方向。如果以角度给出,则按弧度解释,正方向为逆时针。

注意

(Ray) 将根据 (p1) 的维度自动分为 (Ray2D) 或 (Ray3D)。

示例

>>> from sympy import Ray, Point, pi
>>> r = Ray(Point(2, 3), Point(3, 5))
>>> r
Ray2D(Point2D(2, 3), Point2D(3, 5))
>>> r.points
(Point2D(2, 3), Point2D(3, 5))
>>> r.source
Point2D(2, 3)
>>> r.xdirection
oo
>>> r.ydirection
oo
>>> r.slope
2
>>> Ray(Point(0, 0), angle=pi/4).slope
1 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

另请参阅

sympy.geometry.line.Ray2Dsympy.geometry.line.Ray3Dsympy.geometry.point.Pointsympy.geometry.line.Line

属性

source
contains(other)
  • 1

其他几何实体是否包含在此射线内?

示例

>>> from sympy import Ray,Point,Segment
>>> p1, p2 = Point(0, 0), Point(4, 4)
>>> r = Ray(p1, p2)
>>> r.contains(p1)
True
>>> r.contains((1, 1))
True
>>> r.contains((1, 3))
False
>>> s = Segment((1, 1), (2, 2))
>>> r.contains(s)
True
>>> s = Segment((1, 2), (2, 5))
>>> r.contains(s)
False
>>> r1 = Ray((2, 2), (3, 3))
>>> r.contains(r1)
True
>>> r1 = Ray((2, 2), (3, 5))
>>> r.contains(r1)
False 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
distance(other)
  • 1

查找射线与点之间的最短距离。

引发:

如果 other 不是点,则会引发 NotImplementedError

示例

>>> from sympy import Point, Ray
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> s = Ray(p1, p2)
>>> s.distance(Point(-1, -1))
sqrt(2)
>>> s.distance((-1, 2))
3*sqrt(2)/2
>>> p1, p2 = Point(0, 0, 0), Point(1, 1, 2)
>>> s = Ray(p1, p2)
>>> s
Ray3D(Point3D(0, 0, 0), Point3D(1, 1, 2))
>>> s.distance(Point(-1, -1, 2))
4*sqrt(3)/3
>>> s.distance((-1, -1, 2))
4*sqrt(3)/3 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
equals(other)
  • 1

如果自身与其他数学实体相同,则返回 True。

plot_interval(parameter='t')
  • 1

射线的默认几何图形绘制区间。提供将产生长度为 10 个单位的射线的值(其中单位是定义射线的两点之间的距离)。

参数:

parameter:字符串,可选

默认值为 ‘t’。

返回:

plot_interval:列表

[parameter, lower_bound, upper_bound]

示例

>>> from sympy import Ray, pi
>>> r = Ray((0, 0), angle=pi/4)
>>> r.plot_interval()
[t, 0, 10] 
  • 1
  • 2
  • 3
  • 4
property source
  • 1

射线发出的点。

示例

>>> from sympy import Point, Ray
>>> p1, p2 = Point(0, 0), Point(4, 1)
>>> r1 = Ray(p1, p2)
>>> r1.source
Point2D(0, 0)
>>> p1, p2 = Point(0, 0, 0), Point(4, 1, 5)
>>> r1 = Ray(p2, p1)
>>> r1.source
Point3D(4, 1, 5) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

另请参阅

sympy.geometry.point.Point

class sympy.geometry.line.Segment(p1, p2, **kwargs)
  • 1

空间中的线段。

参数:

p1:点

p2:点

注意

如果使用 2D 或 3D 点来定义 (Segment),它将自动分为 (Segment2D) 或 (Segment3D)。

示例

>>> from sympy import Point, Segment
>>> Segment((1, 0), (1, 1)) # tuples are interpreted as pts
Segment2D(Point2D(1, 0), Point2D(1, 1))
>>> s = Segment(Point(4, 3), Point(1, 1))
>>> s.points
(Point2D(4, 3), Point2D(1, 1))
>>> s.slope
2/3
>>> s.length
sqrt(13)
>>> s.midpoint
Point2D(5/2, 2)
>>> Segment((1, 0, 0), (1, 1, 1)) # tuples are interpreted as pts
Segment3D(Point3D(1, 0, 0), Point3D(1, 1, 1))
>>> s = Segment(Point(4, 3, 9), Point(1, 1, 7)); s
Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7))
>>> s.points
(Point3D(4, 3, 9), Point3D(1, 1, 7))
>>> s.length
sqrt(17)
>>> s.midpoint
Point3D(5/2, 2, 8) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

另请参阅

sympy.geometry.line.Segment2Dsympy.geometry.line.Segment3Dsympy.geometry.point.Pointsympy.geometry.line.Line

属性

length(数字或 SymPy 表达式)
midpoint(点)
contains(other)
  • 1

其他几何实体是否包含在此线段内?

示例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> s = Segment(p1, p2)
>>> s2 = Segment(p2, p1)
>>> s.contains(s2)
True
>>> from sympy import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 1, 1), Point3D(3, 4, 5)
>>> s = Segment3D(p1, p2)
>>> s2 = Segment3D(p2, p1)
>>> s.contains(s2)
True
>>> s.contains((p1 + p2)/2)
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
distance(other)
  • 1

查找线段与点之间的最短距离。

引发:

如果other不是点,则抛出NotImplementedError

示例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> s = Segment(p1, p2)
>>> s.distance(Point(10, 15))
sqrt(170)
>>> s.distance((0, 12))
sqrt(73)
>>> from sympy import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 0, 3), Point3D(1, 1, 4)
>>> s = Segment3D(p1, p2)
>>> s.distance(Point3D(10, 15, 12))
sqrt(341)
>>> s.distance((10, 15, 12))
sqrt(341) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
equals(other)
  • 1

如果 self 和 other 是相同的数学实体则返回 True

property length
  • 1

线段的长度。

示例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(4, 3)
>>> s1 = Segment(p1, p2)
>>> s1.length
5
>>> from sympy import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(4, 3, 3)
>>> s1 = Segment3D(p1, p2)
>>> s1.length
sqrt(34) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

参见

sympy.geometry.point.Point.distance

property midpoint
  • 1

线段的中点。

示例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(4, 3)
>>> s1 = Segment(p1, p2)
>>> s1.midpoint
Point2D(2, 3/2)
>>> from sympy import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(4, 3, 3)
>>> s1 = Segment3D(p1, p2)
>>> s1.midpoint
Point3D(2, 3/2, 3/2) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

参见

sympy.geometry.point.Point.midpoint

perpendicular_bisector(p=None)
  • 1

此线段的垂直平分线。

如果未指定点或指定的点不在平分线上,则返回平分线作为线。否则,返回一个连接指定点和平分线与线段交点的段。

参数:

p:点

返回:

bisector:线或段

示例

>>> from sympy import Point, Segment
>>> p1, p2, p3 = Point(0, 0), Point(6, 6), Point(5, 1)
>>> s1 = Segment(p1, p2)
>>> s1.perpendicular_bisector()
Line2D(Point2D(3, 3), Point2D(-3, 9)) 
  • 1
  • 2
  • 3
  • 4
  • 5
>>> s1.perpendicular_bisector(p3)
Segment2D(Point2D(5, 1), Point2D(3, 3)) 
  • 1
  • 2

参见

LinearEntity.perpendicular_segment

plot_interval(parameter='t')
  • 1

Segment 的默认几何绘图的绘图区间给出将在绘图中生成完整线段的值。

参数:

parameter:str,可选

默认值为‘t’。

返回:

plot_interval:列表

[参数, 下界, 上界]

示例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> s1 = Segment(p1, p2)
>>> s1.plot_interval()
[t, 0, 1] 
  • 1
  • 2
  • 3
  • 4
  • 5
class sympy.geometry.line.LinearEntity2D(p1, p2=None, **kwargs)
  • 1

在二维欧几里德空间中所有线性实体(直线、射线和线段)的基类。

注意

这是一个抽象类,不能被实例化。

参见

sympy.geometry.entity.GeometryEntity

属性

p1
p2
系数
斜率
property bounds
  • 1

返回一个元组(xmin,ymin,xmax,ymax),表示几何图形的边界矩形。

perpendicular_line(p)
  • 1

创建一个通过点(p)且垂直于此线性实体的新线。

参数:

p:点

返回:

line:线

示例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2)
>>> L = Line(p1, p2)
>>> P = L.perpendicular_line(p3); P
Line2D(Point2D(-2, 2), Point2D(-5, 4))
>>> L.is_perpendicular(P)
True 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在二维空间中,垂直线的第一个点是必须经过的点;第二个点是任意选择的。要获得明确使用线中的点的线,请从线到点的垂直线段创建一条线:

>>> Line(L.perpendicular_segment(p3))
Line2D(Point2D(-2, 2), Point2D(4/13, 6/13)) 
  • 1
  • 2

参见

sympy.geometry.line.LinearEntity.is_perpendicularperpendicular_segment

property slope
  • 1

此线性实体的斜率,如果是垂直线则为无穷大。

返回:

slope:数字或 SymPy 表达式

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> l1 = Line(p1, p2)
>>> l1.slope
5/3 
  • 1
  • 2
  • 3
  • 4
  • 5
>>> p3 = Point(0, 4)
>>> l2 = Line(p1, p3)
>>> l2.slope
oo 
  • 1
  • 2
  • 3
  • 4

参见

coefficients

class sympy.geometry.line.Line2D(p1, pt=None, slope=None, **kwargs)
  • 1

二维空间中的无限直线。

一条线由两个不同的点或使用关键字(slope)定义的点和斜率声明。

参数:

p1:点

pt:点

slope:SymPy 表达式

示例

>>> from sympy import Line, Segment, Point
>>> L = Line(Point(2,3), Point(3,5))
>>> L
Line2D(Point2D(2, 3), Point2D(3, 5))
>>> L.points
(Point2D(2, 3), Point2D(3, 5))
>>> L.equation()
-2*x + y + 1
>>> L.coefficients
(-2, 1, 1) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

使用关键字slope实例化:

>>> Line(Point(0, 0), slope=0)
Line2D(Point2D(0, 0), Point2D(1, 0)) 
  • 1
  • 2

使用另一个线性对象实例化

>>> s = Segment((0, 0), (0, 1))
>>> Line(s).equation()
x 
  • 1
  • 2
  • 3

参见

sympy.geometry.point.Point

property coefficients
  • 1

方程 (ax + by + c = 0) 的系数 ((a, b, c))。

示例

>>> from sympy import Point, Line
>>> from sympy.abc import x, y
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.coefficients
(-3, 5, 0) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
>>> p3 = Point(x, y)
>>> l2 = Line(p1, p3)
>>> l2.coefficients
(-y, x, 0) 
  • 1
  • 2
  • 3
  • 4

另见

sympy.geometry.line.Line2D.equation

equation(x='x', y='y')
  • 1

线的方程:ax + by + c。

参数:

x : str, 可选项

用于 x 轴的名称,默认值为 ‘x’。

y : str, 可选项

用于 y 轴的名称,默认值为 ‘y’。

返回:

equation : SymPy 表达式

示例

>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.equation()
-3*x + 4*y + 3 
  • 1
  • 2
  • 3
  • 4
  • 5

另见

sympy.geometry.line.Line2D.coefficients

class sympy.geometry.line.Ray2D(p1, pt=None, angle=None, **kwargs)
  • 1

光线是空间中带有源点和方向的半线。

参数:

p1 : 点

光线的来源

p2 : 点或弧度值

此点确定射线传播的方向。若作为角度给出,则解释为弧度,正方向为逆时针方向。

示例

>>> from sympy import Point, pi, Ray
>>> r = Ray(Point(2, 3), Point(3, 5))
>>> r
Ray2D(Point2D(2, 3), Point2D(3, 5))
>>> r.points
(Point2D(2, 3), Point2D(3, 5))
>>> r.source
Point2D(2, 3)
>>> r.xdirection
oo
>>> r.ydirection
oo
>>> r.slope
2
>>> Ray(Point(0, 0), angle=pi/4).slope
1 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

另见

sympy.geometry.point.Point, Line

属性

源点
x 方向
y 方向
closing_angle(r2)
  • 1

返回 r2 必须旋转的角度,以使其面对与 r1 相同的方向。

参数:

r1 : Ray2D

r2 : Ray2D

返回:

angle : 弧度制的角度(逆时针角度为正)

示例

>>> from sympy import Ray, pi
>>> r1 = Ray((0, 0), (1, 0))
>>> r2 = r1.rotate(-pi/2)
>>> angle = r1.closing_angle(r2); angle
pi/2
>>> r2.rotate(angle).direction.unit == r1.direction.unit
True
>>> r2.closing_angle(r1)
-pi/2 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

另见

LinearEntity.angle_between

property xdirection
  • 1

光线的 x 方向。

如果光线指向正 x 方向则为正无穷,如果光线指向负 x 方向则为负无穷,若光线为竖直则为 0。

示例

>>> from sympy import Point, Ray
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, -1)
>>> r1, r2 = Ray(p1, p2), Ray(p1, p3)
>>> r1.xdirection
oo
>>> r2.xdirection
0 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

另见

ydirection

property ydirection
  • 1

光线的 y 方向。

如果光线指向正 y 方向则为正无穷,如果光线指向负 y 方向则为负无穷,若光线为水平则为 0。

示例

>>> from sympy import Point, Ray
>>> p1, p2, p3 = Point(0, 0), Point(-1, -1), Point(-1, 0)
>>> r1, r2 = Ray(p1, p2), Ray(p1, p3)
>>> r1.ydirection
-oo
>>> r2.ydirection
0 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

另见

xdirection

class sympy.geometry.line.Segment2D(p1, p2, **kwargs)
  • 1

2D 空间中的线段。

参数:

p1 : 点

p2 : 点

示例

>>> from sympy import Point, Segment
>>> Segment((1, 0), (1, 1)) # tuples are interpreted as pts
Segment2D(Point2D(1, 0), Point2D(1, 1))
>>> s = Segment(Point(4, 3), Point(1, 1)); s
Segment2D(Point2D(4, 3), Point2D(1, 1))
>>> s.points
(Point2D(4, 3), Point2D(1, 1))
>>> s.slope
2/3
>>> s.length
sqrt(13)
>>> s.midpoint
Point2D(5/2, 2) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

另见

sympy.geometry.point.Point, Line

属性

长度(数字或 SymPy 表达式)
中点(点)
class sympy.geometry.line.LinearEntity3D(p1, p2, **kwargs)
  • 1

所有在三维欧几里得空间中的线性实体(线、射线和线段)的基类。

注释

这是一个基类,不应该被实例化。

属性

p1
p2
方向比
方向余弦
property direction_cosine
  • 1

3D 空间中给定直线的归一化方向比。

示例

>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(5, 3, 1)
>>> l = Line3D(p1, p2)
>>> l.direction_cosine
[sqrt(35)/7, 3*sqrt(35)/35, sqrt(35)/35]
>>> sum(i**2 for i in _)
1 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

另见

sympy.geometry.line.Line3D.equation

property direction_ratio
  • 1

3D 空间中给定直线的方向比。

示例

>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(5, 3, 1)
>>> l = Line3D(p1, p2)
>>> l.direction_ratio
[5, 3, 1] 
  • 1
  • 2
  • 3
  • 4
  • 5

另见

sympy.geometry.line.Line3D.equation

class sympy.geometry.line.Line3D(p1, pt=None, direction_ratio=(), **kwargs)
  • 1

3D 空间中的无限线。

用两个不同点或使用关键字(direction_ratio)定义的点和方向比例声明一条线。

参数:

p1 : Point3D

pt : Point3D

direction_ratio : 列表

示例

>>> from sympy import Line3D, Point3D
>>> L = Line3D(Point3D(2, 3, 4), Point3D(3, 5, 1))
>>> L
Line3D(Point3D(2, 3, 4), Point3D(3, 5, 1))
>>> L.points
(Point3D(2, 3, 4), Point3D(3, 5, 1)) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

参见

sympy.geometry.point.Point3D, sympy.geometry.line.Line, sympy.geometry.line.Line2D

distance(other)
  • 1

查找线与另一个对象之间的最短距离。

参数:

Point3D, Line3D, Plane, tuple, list

返回:

距离

注意

此方法只接受 3D 实体作为其参数

元组和列表转换为 Point3D,因此必须是长度为 3、2 或 1。

如果(other)不是指定类(Point3D、Line3D 或 Plane)的实例,则引发 NotImplementedError。

示例

>>> from sympy.geometry import Line3D
>>> l1 = Line3D((0, 0, 0), (0, 0, 1))
>>> l2 = Line3D((0, 1, 0), (1, 1, 1))
>>> l1.distance(l2)
1 
  • 1
  • 2
  • 3
  • 4
  • 5

计算得到的距离可能也是符号的:

>>> from sympy.abc import x, y
>>> l1 = Line3D((0, 0, 0), (0, 0, 1))
>>> l2 = Line3D((0, x, 0), (y, x, 1))
>>> l1.distance(l2)
Abs(x*y)/Abs(sqrt(y**2)) 
  • 1
  • 2
  • 3
  • 4
  • 5
equation(x='x', y='y', z='z')
  • 1

返回在 3D 中定义线的方程。

参数:

x : 字符串,可选

用于 x 轴的名称,默认值为‘x’。

y : 字符串,可选

用于 y 轴的名称,默认值为‘y’。

z : 字符串,可选

用于 z 轴的名称,默认值为‘z’。

返回:

equation : 同时方程组的元组

示例

>>> from sympy import Point3D, Line3D, solve
>>> from sympy.abc import x, y, z
>>> p1, p2 = Point3D(1, 0, 0), Point3D(5, 3, 0)
>>> l1 = Line3D(p1, p2)
>>> eq = l1.equation(x, y, z); eq
(-3*x + 4*y + 3, z)
>>> solve(eq.subs(z, 0), (x, y, z))
{x: 4*y/3 + 1} 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
class sympy.geometry.line.Ray3D(p1, pt=None, direction_ratio=(), **kwargs)
  • 1

射线是带有源点和方向的空间半线。

参数:

p1 : Point3D

射线的源点

p2 : 点或方向向量

direction_ratio: 确定射线传播的方向。

示例

>>> from sympy import Point3D, Ray3D
>>> r = Ray3D(Point3D(2, 3, 4), Point3D(3, 5, 0))
>>> r
Ray3D(Point3D(2, 3, 4), Point3D(3, 5, 0))
>>> r.points
(Point3D(2, 3, 4), Point3D(3, 5, 0))
>>> r.source
Point3D(2, 3, 4)
>>> r.xdirection
oo
>>> r.ydirection
oo
>>> r.direction_ratio
[1, 2, -4] 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

参见

sympy.geometry.point.Point3D, Line3D

属性

source
xdirection
ydirection
zdirection
property xdirection
  • 1

射线的 x 方向。

如果射线指向正 x 方向则为正无穷,如果射线指向负 x 方向则为负无穷,如果射线为竖直则为 0。

示例

>>> from sympy import Point3D, Ray3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, -1, 0)
>>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3)
>>> r1.xdirection
oo
>>> r2.xdirection
0 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

参见

ydirection

property ydirection
  • 1

射线的 y 方向。

如果射线指向正 y 方向则为正无穷,如果射线指向负 y 方向则为负无穷,如果射线为水平则为 0。

示例

>>> from sympy import Point3D, Ray3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(-1, -1, -1), Point3D(-1, 0, 0)
>>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3)
>>> r1.ydirection
-oo
>>> r2.ydirection
0 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

参见

xdirection

property zdirection
  • 1

射线的 z 方向。

如果射线指向正 z 方向则为正无穷,如果射线指向负 z 方向则为负无穷,如果射线为水平则为 0。

示例

>>> from sympy import Point3D, Ray3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(-1, -1, -1), Point3D(-1, 0, 0)
>>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3)
>>> r1.ydirection
-oo
>>> r2.ydirection
0
>>> r2.zdirection
0 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

参见

xdirection

class sympy.geometry.line.Segment3D(p1, p2, **kwargs)
  • 1

3D 空间中的线段。

参数:

p1 : Point3D

p2 : Point3D

示例

>>> from sympy import Point3D, Segment3D
>>> Segment3D((1, 0, 0), (1, 1, 1)) # tuples are interpreted as pts
Segment3D(Point3D(1, 0, 0), Point3D(1, 1, 1))
>>> s = Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7)); s
Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7))
>>> s.points
(Point3D(4, 3, 9), Point3D(1, 1, 7))
>>> s.length
sqrt(17)
>>> s.midpoint
Point3D(5/2, 2, 8) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

参见

sympy.geometry.point.Point3D, Line3D

属性

length(number or SymPy expression)
midpoint(Point3D)
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/813689
推荐阅读
相关标签
  

闽ICP备14008679号