乌迪斯#
- sympy.geometry.util.intersection(*entities, pairwise=False, **kwargs)[源代码]#
几何实体实例集合的交集。
- 参数:
实体 :几何体序列
成对(关键字参数) :可以是真或假
- 返回:
交叉 :几何测量列表
- 加薪:
NotImplementedError
当无法计算交集时。
笔记
任何几何实体与其自身的交集应该返回一个包含一个项目的列表:有问题的实体。交叉点需要两个或多个图元。如果只给出一个实体,那么函数将返回一个空列表。有可能 \(intersection\) 错过已知存在的交叉口,因为所需数量没有在内部完全简化。实数应转换为有理数,例如有理数(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))]
- sympy.geometry.util.convex_hull(*args, polygon=True)[源代码]#
包含在实体列表中的点周围的凸包。
- 参数:
args :点、线段和/或多边形的集合
- 返回:
convex_hull :多边形如果
polygon
作为元组的else是真的吗 \((U, L)\) 在哪里?L
和U
分别是下部和上部船体。
可选参数
- 多边形布尔值。如果为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)])
工具书类
[R564]Andrew's Monotone Chain Algorithm (A.M. Andrew, "Another Efficient Algorithm for Convex Hulls in Two Dimensions", 1979) https://web.archive.org/web/20210511015444/http://geomalgorithms.com/a10-_hull-1.html
- sympy.geometry.util.are_similar(e1, e2)[源代码]#
是两个相似的几何实体。
一个几何实体可以统一缩放到另一个吗?
- 参数:
e1 :几何体
e2 :几何体
- 返回:
are_similar :布尔值
- 加薪:
GeometryError
什么时候? \(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
- sympy.geometry.util.centroid(*args)[源代码]#
查找仅包含点、线段或多边形的集合的质心(质心)。质心是单个质心的加权平均值,其中权重是长度(分段)或面积(多边形)。重叠区域将增加该区域的权重。
如果没有对象(或对象的混合体),则不返回任何对象。
实例
>>> 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)
将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)
在p的上方和下方垂直堆叠方块具有相同的效果:
>>> centroid(p, p.translate(0, 1), p.translate(0, -1), q) Point2D(11/10, 1/2)
- sympy.geometry.util.idiff(eq, y, x, n=1)[源代码]#
返回
dy/dx
假设eq == 0
.- 参数:
y :因变量或因变量列表(以y开头)
x :对其进行求导的变量
n :导数的顺序(默认值为1)
实例
>>> from sympy.abc import x, y, a >>> from sympy.geometry.util import idiff
>>> circ = x**2 + y**2 - 4 >>> idiff(circ, y, x) -x/y >>> idiff(circ, y, x, 2).simplify() (-x**2 - y**2)/y**3
在这里,
a
假设独立于x
:>>> idiff(x + a + y, y, x) -1
现在的x依赖性
a
通过列出a
之后y
在列表中。>>> idiff(x + a + y, [y, a], x) -Derivative(a, x) - 1
参见
sympy.core.function.Derivative
表示未估值的衍生工具
sympy.core.function.diff
明确区分wrt符号