#!/usr/bin/env python # coding: utf-8 # # Geometrie # In[ ]: # In[ ]: # ## Konvexe Hülle # # SciPy's [spatial Modul](http://docs.scipy.org/doc/scipy-dev/reference/spatial.html) # beinhaltet zum Beispiel eine Methode um die [konvexe Hülle](http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.spatial.ConvexHull.html) von Punkten finden zu können. # Es ist ein front-end für [QHull](http://www.qhull.org/). # In[1]: import numpy as np from scipy.spatial import ConvexHull pts = np.random.normal(size=(100,2)) chull = ConvexHull(pts) chull.vertices # In[2]: get_ipython().run_line_magic('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) # ## Sympy Geometry Module # In[3]: import sympy as sy from sympy.geometry import Point, Segment, Circle, Line, Triangle # In[4]: x = Point(0, 0) y = Point(1, 1) z = Point(2, 2) zp = Point(1, 0) # In[5]: Point.is_collinear(x, y, z) # In[6]: Point.is_collinear(x, y, zp) # In[7]: seg1 = Segment(x, z) seg2 = Segment(y, zp) # In[8]: seg1.intersection(seg2) # In[9]: seg1.midpoint # In[10]: c = Circle(x, 5) l = Line(Point(5, -5), Point(5, 5)) # In[11]: c.is_tangent(l) # In[12]: l2 = Line(Point(2, -4), Point(3, -2)) c.intersection(l2) # In[ ]: # In[ ]: