#!/usr/bin/env python # coding: utf-8 # # Geometrie # In[1]: # In[1]: # ## 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[19]: import numpy as np from scipy.spatial import ConvexHull pts = np.random.normal(size=(100,2)) chull = ConvexHull(pts) chull.vertices # In[24]: 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[13]: import sympy as sy from sympy.geometry import Point, Segment, Circle, Line, Triangle # In[24]: x = Point(0, 0) y = Point(1, 1) z = Point(2, 2) zp = Point(1, 0) # In[25]: Point.is_collinear(x, y, z) # In[26]: Point.is_collinear(x, y, zp) # In[27]: seg1 = Segment(x, z) seg2 = Segment(y, zp) # In[28]: seg1.intersection(seg2) # In[30]: seg1.midpoint # In[21]: c = Circle(x, 5) l = Line(Point(5, -5), Point(5, 5)) # In[20]: c.is_tangent(l) # In[50]: l2 = Line(Point(2, -4), Point(3, -2)) c.intersection(l2) # In[30]: # In[ ]: