Пример #1
0
    def random_directions_bounded_density_3d(center, radius, N):

        S = random_directions_bounded(3, radius, N, center=center)
        distances = distances_from(S, center)

        if not (distances <= radius).all():
            invalid = np.nonzero(distances > radius)[0]
            msg = 'Invalid distances: %s > %f' % (distances[invalid], radius)
            raise Exception(msg)

        subs = 6
        A = spherical_cap_area(cap_radius=radius)
        da = A / subs
        dist = np.zeros(subs, dtype='int')
        for s in range(subs):
            lower = s * da
            upper = lower + da

            r1 = spherical_cap_with_area(lower)
            r2 = spherical_cap_with_area(upper)
            num_here = np.logical_and(distances >= r1, distances < r2).sum()

            dist[s] = num_here

        assert dist.sum() == N
        return DiscreteUniformDistribution(dist,
                                    'Distribution of distances from center')
    def random_directions_bounded_density_3d(center, radius, N):

        S = random_directions_bounded(3, radius, N, center=center)
        distances = distances_from(S, center)

        if not (distances <= radius).all():
            invalid = np.nonzero(distances > radius)[0]
            msg = 'Invalid distances: %s > %f' % (distances[invalid], radius)
            raise Exception(msg)

        subs = 6
        A = spherical_cap_area(cap_radius=radius)
        da = A / subs
        dist = np.zeros(subs, dtype='int')
        for s in range(subs):
            lower = s * da
            upper = lower + da

            r1 = spherical_cap_with_area(lower)
            r2 = spherical_cap_with_area(upper)
            num_here = np.logical_and(distances >= r1, distances < r2).sum()

            dist[s] = num_here

        assert dist.sum() == N
        return DiscreteUniformDistribution(dist,
                                    'Distribution of distances from center')
Пример #3
0
def spherical_cap_area_test():
    for radius, area in couples:
        yield  assert_allclose, spherical_cap_area(radius), area
Пример #4
0
def spherical_cap_area_test():
    for radius, area in couples:
        yield assert_allclose, spherical_cap_area(radius), area