当前位置: 首页>>代码示例>>Python>>正文


Python qhull.Delaunay方法代码示例

本文整理汇总了Python中scipy.spatial.qhull.Delaunay方法的典型用法代码示例。如果您正苦于以下问题:Python qhull.Delaunay方法的具体用法?Python qhull.Delaunay怎么用?Python qhull.Delaunay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.spatial.qhull的用法示例。


在下文中一共展示了qhull.Delaunay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: simplex_edge_difference

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def simplex_edge_difference(X):
    tri = Delaunay(X, qhull_options="QJ")

    simplices = []
    for e in tri.simplices:
        diff = X[e[1:]] - X[e[0]]
        det = np.linalg.det(diff)
        if det > 1e-6:
            simplices.append(e)

    val = []
    for triangle in simplices:
        dists = np.zeros(len(triangle))

        for i in range(len(triangle)):
            a, b = triangle[i], triangle[(i + 1) % len(triangle)]
            dists[i] = np.linalg.norm(X[a] - X[b])

        val.append(dists.max() - dists.min())

    val = np.array(val)

    return val.mean() 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:25,代码来源:performance.py

示例2: test_find_simplex

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_find_simplex(self):
        # Simple check that simplex finding works
        points = np.array([(0,0), (0,1), (1,1), (1,0)], dtype=np.double)
        tri = qhull.Delaunay(points)

        # +---+
        # |\ 0|
        # | \ |
        # |1 \|
        # +---+

        assert_equal(tri.vertices, [[3, 1, 2], [3, 1, 0]])

        for p in [(0.25, 0.25, 1),
                  (0.75, 0.75, 0),
                  (0.3, 0.2, 1)]:
            i = tri.find_simplex(p[:2])
            assert_equal(i, p[2], err_msg='%r' % (p,))
            j = qhull.tsearch(tri, p[:2])
            assert_equal(i, j) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:test_qhull.py

示例3: test_degenerate_barycentric_transforms

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_degenerate_barycentric_transforms(self):
        # The triangulation should not produce invalid barycentric
        # transforms that stump the simplex finding
        data = np.load(os.path.join(os.path.dirname(__file__), 'data',
                                    'degenerate_pointset.npz'))
        points = data['c']
        data.close()

        tri = qhull.Delaunay(points)

        # Check that there are not too many invalid simplices
        bad_count = np.isnan(tri.transform[:,0,0]).sum()
        assert_(bad_count < 20, bad_count)

        # Check the transforms
        self._check_barycentric_transforms(tri) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_qhull.py

示例4: test_smoketest

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_smoketest(self):
        x = np.array([(0, 0), (0, 2),
                      (1, 0), (1, 2), (0.25, 0.75), (0.6, 0.8)], dtype=float)
        tri = qhull.Delaunay(x)

        # Should be exact for linear functions, independent of triangulation

        funcs = [
            (lambda x, y: 0*x + 1, (0, 0)),
            (lambda x, y: 0 + x, (1, 0)),
            (lambda x, y: -2 + y, (0, 1)),
            (lambda x, y: 3 + 3*x + 14.15*y, (3, 14.15))
        ]

        for j, (func, grad) in enumerate(funcs):
            z = func(x[:,0], x[:,1])
            dz = interpnd.estimate_gradients_2d_global(tri, z, tol=1e-6)

            assert_equal(dz.shape, (6, 2))
            assert_allclose(dz, np.array(grad)[None,:] + 0*dz,
                            rtol=1e-5, atol=1e-5, err_msg="item %d" % j) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_interpnd.py

示例5: test_find_simplex

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_find_simplex(self):
        # Simple check that simplex finding works
        points = np.array([(0,0), (0,1), (1,1), (1,0)], dtype=np.double)
        tri = qhull.Delaunay(points)

        # +---+
        # |\ 0|
        # | \ |
        # |1 \|
        # +---+

        assert_equal(tri.vertices, [[1, 3, 2], [3, 1, 0]])

        for p in [(0.25, 0.25, 1),
                  (0.75, 0.75, 0),
                  (0.3, 0.2, 1)]:
            i = tri.find_simplex(p[:2])
            assert_equal(i, p[2], err_msg='%r' % (p,))
            j = qhull.tsearch(tri, p[:2])
            assert_equal(i, j) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:22,代码来源:test_qhull.py

示例6: test_degenerate_barycentric_transforms

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_degenerate_barycentric_transforms(self):
        # The triangulation should not produce invalid barycentric
        # transforms that stump the simplex finding
        data = np.load(os.path.join(os.path.dirname(__file__), 'data',
                                    'degenerate_pointset.npz'))
        points = data['c']
        data.close()

        tri = qhull.Delaunay(points)

        # Check that there are not too many invalid simplices
        bad_count = np.isnan(tri.transform[:,0,0]).sum()
        assert_(bad_count < 21, bad_count)

        # Check the transforms
        self._check_barycentric_transforms(tri) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:18,代码来源:test_qhull.py

示例7: test_tri_input_rescale

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_tri_input_rescale(self):
        # Test at single points
        x = np.array([(0,0), (-5,-5), (-5,5), (5, 5), (2.5, 3)],
                     dtype=np.double)
        y = np.arange(x.shape[0], dtype=np.double)
        y = y - 3j*y

        tri = qhull.Delaunay(x)
        try:
            interpnd.LinearNDInterpolator(tri, y, rescale=True)(x)
        except ValueError as e:
            if str(e) != ("Rescaling is not supported when passing a "
                          "Delaunay triangulation as ``points``."):
                raise
        except:
            raise 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:18,代码来源:test_interpnd.py

示例8: test_plane_distance

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_plane_distance(self):
        # Compare plane distance from hyperplane equations obtained from Qhull
        # to manually computed plane equations
        x = np.array([(0,0), (1, 1), (1, 0), (0.99189033, 0.37674127),
                      (0.99440079, 0.45182168)], dtype=np.double)
        p = np.array([0.99966555, 0.15685619], dtype=np.double)

        tri = qhull.Delaunay(x)

        z = tri.lift_points(x)
        pz = tri.lift_points(p)

        dist = tri.plane_distance(p)

        for j, v in enumerate(tri.vertices):
            x1 = z[v[0]]
            x2 = z[v[1]]
            x3 = z[v[2]]

            n = np.cross(x1 - x3, x2 - x3)
            n /= np.sqrt(np.dot(n, n))
            n *= -np.sign(n[2])

            d = np.dot(n, pz - x3)

            assert_almost_equal(dist[j], d) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:28,代码来源:test_qhull.py

示例9: test_convex_hull

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_convex_hull(self):
        # Simple check that the convex hull seems to works
        points = np.array([(0,0), (0,1), (1,1), (1,0)], dtype=np.double)
        tri = qhull.Delaunay(points)

        # +---+
        # |\ 0|
        # | \ |
        # |1 \|
        # +---+

        assert_equal(tri.convex_hull, [[1, 2], [3, 2], [1, 0], [3, 0]]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:14,代码来源:test_qhull.py

示例10: test_rectangle

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_rectangle(self):
        points = np.array([(0,0), (0,1), (1,1), (1,0)], dtype=np.double)
        tri = qhull.Delaunay(points)
        self._check(tri) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:test_qhull.py

示例11: test_complicated

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_complicated(self):
        points = np.array([(0,0), (0,1), (1,1), (1,0),
                           (0.5, 0.5), (0.9, 0.5)], dtype=np.double)
        tri = qhull.Delaunay(points)
        self._check(tri) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_qhull.py

示例12: test_nd_simplex

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_nd_simplex(self):
        # simple smoke test: triangulate a n-dimensional simplex
        for nd in xrange(2, 8):
            points = np.zeros((nd+1, nd))
            for j in xrange(nd):
                points[j,j] = 1.0
            points[-1,:] = 1.0

            tri = qhull.Delaunay(points)

            tri.vertices.sort()

            assert_equal(tri.vertices, np.arange(nd+1, dtype=np.int)[None,:])
            assert_equal(tri.neighbors, -1 + np.zeros((nd+1), dtype=np.int)[None,:]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:test_qhull.py

示例13: test_2d_square

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_2d_square(self):
        # simple smoke test: 2d square
        points = np.array([(0,0), (0,1), (1,1), (1,0)], dtype=np.double)
        tri = qhull.Delaunay(points)

        assert_equal(tri.vertices, [[3, 1, 2], [3, 1, 0]])
        assert_equal(tri.neighbors, [[-1, -1, 1], [-1, -1, 0]]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:test_qhull.py

示例14: test_duplicate_points

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_duplicate_points(self):
        x = np.array([0, 1, 0, 1], dtype=np.float64)
        y = np.array([0, 0, 1, 1], dtype=np.float64)

        xp = np.r_[x, x]
        yp = np.r_[y, y]

        # shouldn't fail on duplicate points
        tri = qhull.Delaunay(np.c_[x, y])
        tri2 = qhull.Delaunay(np.c_[xp, yp]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_qhull.py

示例15: test_joggle

# 需要导入模块: from scipy.spatial import qhull [as 别名]
# 或者: from scipy.spatial.qhull import Delaunay [as 别名]
def test_joggle(self):
        # Check that the option QJ indeed guarantees that all input points
        # occur as vertices of the triangulation

        points = np.random.rand(10, 2)
        points = np.r_[points, points]  # duplicate input data

        tri = qhull.Delaunay(points, qhull_options="QJ Qbb Pp")
        assert_array_equal(np.unique(tri.simplices.ravel()),
                           np.arange(len(points))) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_qhull.py


注:本文中的scipy.spatial.qhull.Delaunay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。