工具¶
- sympy.geometry.util.intersection(*entities, pairwise=False, **kwargs)[源代码][源代码]¶
一组 GeometryEntity 实例的交集。
- 参数:
- 实体GeometryEntity 的序列
- pairwise (关键字参数)可以是 True 或 False
- 返回:
- 交叉点GeometryEntity 列表
- Raises:
- NotImplementedError
当无法计算交集时。
注释
任何几何实体与其自身的交集应返回一个包含一个项目的列表:所讨论的实体。交集需要两个或更多的实体。如果只给出一个实体,则函数将返回一个空列表。\(intersection\) 可能会遗漏已知存在的交集,因为所需的量在内部没有完全简化。实数应转换为有理数,例如 Rational(str(real_num)),否则可能会由于浮点问题而导致失败。
当关键字参数 ‘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)[源代码][源代码]¶
包含在实体列表中的点的凸包。
- 参数:
- 参数点、线段和/或多边形的集合
- 返回:
- convex_hull : 如果
polygon为 True,则为 Polygon,否则为元组 \((U, L)\),其中多边形 如果 L和U分别是下壳和上壳。
- convex_hull : 如果
注释
这只能在坐标可以在数轴上排序的一组点上执行。
参考文献
[1][2]Andrew’s Monotone Chain 算法 (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
示例
>>> 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)])
- sympy.geometry.util.are_similar(e1, e2)[源代码][源代码]¶
两个几何实体是否相似。
一个几何实体能否均匀缩放到另一个?
- 参数:
- e1GeometryEntity
- e2GeometryEntity
- 返回:
- are_similar布尔
- Raises:
- 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)[源代码][源代码]¶
找到仅包含点、线段或多边形的集合的质心(重心)。质心是各个质心的加权平均值,其中权重是线段的长度或多边形的面积。重叠区域将增加该区域的权重。
如果没有对象(或对象混合),则返回 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)
将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)[源代码][源代码]¶
假设
eq == 0,返回dy/dx。- 参数:
- y因变量或因变量列表(y 在前)
- x求导所关于的变量
- n导数的阶数(默认是 1)
参见
sympy.core.function.Derivative表示未求值的导数
sympy.core.function.diff明确区分符号
示例
>>> 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
现在,通过在列表中将
a列在y之后,a的 x-依赖性被明确表示出来。>>> idiff(x + a + y, [y, a], x) -Derivative(a, x) - 1