コード例 #1
0
def xyz_cone():
    """Fixture to generate random set of cone points."""
    cone = geometry.Cone(0.5, 0.5, rot_x=3., rot_y=1., base_pos=geometry.Point(8, 10, -48))

    np.random.seed(1)
    n_steps = 10
    xyz = np.array(geometry.cone_surface(cone, n_steps=n_steps))
    xyz = xyz.reshape(3, n_steps * n_steps)

    return xyz
コード例 #2
0
def test_thick_cone_base_positions():
    """Test thick_cone_base_positions."""
    cone = geometry.Cone(0.5, 0.5)

    thickness = 0.2

    theta = cone.opening_angle()
    base_pos_distance = thickness / np.sin(theta)

    b1, b2 = geometry.thick_cone_base_positions(cone, thickness)
    assert np.allclose(np.array(b1), -np.array((0, 0, base_pos_distance / 2)))
    assert np.allclose(np.array(b2), np.array((0, 0, base_pos_distance / 2)))
コード例 #3
0
def test_cone_surface():
    """Test geometry.cone_surface."""
    cone = geometry.Cone(0.5, 0.5)

    xyz = np.array(geometry.cone_surface(cone, n_steps=3))

    # using buffer to preserve exact, non-rounded floating point numbers
    prebaked = np.frombuffer(
        b'\x00\x00\x00\x00\x00\x00\xe0?\xfe\xff\xff\xff\xff\xff\xcf?\x07\\\x143&\xa6\xa1\xbc\x00\x00\x00\x00\x00\x00\xe0\xbf\x01\x00\x00\x00\x00\x00\xd0\xbf\x07\\\x143&\xa6\xa1\xbc\x00\x00\x00\x00\x00\x00\xe0?\xfe\xff\xff\xff\xff\xff\xcf?\x07\\\x143&\xa6\xa1\xbc\x00\x00\x00\x00\x00\x00\x00\x00\x07\\\x143&\xa6\x91<\x07\\\x143&\xa6\xa1<\x07\\\x143&\xa6\x91<\n\x8a\x9eL9y\x9a<\x07\\\x143&\xa6\xa1<\x07\\\x143&\xa6\xa1\xbc\xbf\x8f\xed\xb7v\x19\x1f9\x07\\\x143&\xa6\xa1<\x07\\\x143&\xa6\xa1<\x01\x00\x00\x00\x00\x00\xd0?\x00\x00\x00\x00\x00\x00\xe0?\x08\\\x143&\xa6\xa1\xbc\xfe\xff\xff\xff\xff\xff\xcf?\x00\x00\x00\x00\x00\x00\xe0?\x08\\\x143&\xa6\xa1<\x01\x00\x00\x00\x00\x00\xd0?\x00\x00\x00\x00\x00\x00\xe0?'
    ).reshape(3, 3, 3)

    assert np.all(xyz == prebaked)
コード例 #4
0
def test_filter_points_cone():
    """Test geometry.filter_points_cone."""
    xyz = np.array([
        [0, 0, 0.5],  # inside blue, above red ("case 2")
        [0, 0.01,
         0.5 + np.sqrt(0.2**2 / 2)],  # slightly besides blue ("case 3")
        [0, 0.2, 0.3],  # somewhere between the directrices ("case 4")
        [
            0, 0, 0.7
        ],  # above blue (i.e. above both), within "thickness" from blue ("case 1")
        [0, 0, 1],  # far above both ("case 1")
        [0, 0, 0.3],  # inside red ("case 5")
        [0, 0, 0.1],  # inside red, "below" blue ("case 5")
        [0, 0, -0.7],  # below both ("case 1")
    ]).T

    cone = geometry.Cone(0.5, 0.5)
    p_filtered = geometry.filter_points_cone(xyz, cone, 0.2)
    assert np.all(
        np.array(p_filtered) == np.array([[0, 0, 0.5], [0, 0.2, 0.3]]))
コード例 #5
0
def test_point_distance_to_cone(point, expected_distance, expected_flag):
    """Test point_distance_to_cone."""
    cone = geometry.Cone(0.5, 0.5)
    distance, flag, _ = geometry.point_distance_to_cone(point, cone)
    assert np.isclose(distance, expected_distance)
    assert flag == expected_flag
コード例 #6
0
def plot_cone_fit(fit_result, **kwargs):
    """Plot the cone resulting from a cone fit to a point set."""
    cone = geometry.Cone(*fit_result['x'][:4],
                         base_pos=geometry.Point(*fit_result['x'][4:]))
    fig = plot_cone(cone, **kwargs)
    return fig
コード例 #7
0
def initial_cone():
    """Fixture to generate initial cone guess."""
    return geometry.Cone(0.51, 0.51, rot_x=3.01, rot_y=0.99, base_pos=geometry.Point(7.9, 10., -48.1))