SciPy's spatial Modul beinhaltet zum Beispiel eine Methode um die konvexe Hülle von Punkten finden zu können. Es ist ein front-end für QHull.
import numpy as np
from scipy.spatial import ConvexHull
pts = np.random.normal(size=(100,2))
chull = ConvexHull(pts)
chull.vertices
array([11, 81, 47, 36, 28, 80, 76, 17], dtype=int32)
%matplotlib inline
import matplotlib.pyplot as plt
for simplex in chull.simplices:
plt.plot(pts[simplex, 0], pts[simplex, 1], "g-", lw=2, zorder=1)
plt.scatter(pts[:,0], pts[:,1], zorder=2)
<matplotlib.collections.PathCollection at 0x4d252d0>
import sympy as sy
from sympy.geometry import Point, Segment, Circle, Line, Triangle
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
seg1 = Segment(x, z)
seg2 = Segment(y, zp)
seg1.intersection(seg2)
[Point(1, 1)]
seg1.midpoint
Point(1, 1)
c = Circle(x, 5)
l = Line(Point(5, -5), Point(5, 5))
c.is_tangent(l)
True
l2 = Line(Point(2, -4), Point(3, -2))
c.intersection(l2)
[Point(-sqrt(61)/5 + 16/5, -2*sqrt(61)/5 - 8/5), Point(sqrt(61)/5 + 16/5, -8/5 + 2*sqrt(61)/5)]