Ejemplo n.º 1
0
def axes(max_dist, axis_rad=0.25, axis_color='yellow'):
    """
    Generate X, Y, Z axes of length max_width in the form of a pythreejs
    Line object.

    Parameters
    ----------
    max_dist : float
                maximum extent of grid from origin in each dimension
    axis_rad : float
                radius of cylinder representing each axis (default: 0.25)
    axis_color : color
                color the axes are drawn in (default: 'yellow')

    Returns
    -------
    Xaxis, Yaxis, Zaxis : pythreejs.Mesh*3
            Three pythreejs Mesh objects representing the x, y, and z axes.
    """
    Xaxis = p3j.Mesh(geometry=p3j.CylinderBufferGeometry(radiusTop=axis_rad, radiusBottom=axis_rad, 
                                                height=max_dist, 
                                                radiusSegments=12, 
                                                heightSegments=1, 
                                                openEnded=False, 
                                                thetaStart=0, thetaLength=2*np.pi), 
                material=p3j.MeshBasicMaterial(color=axis_color),
                position=[max_dist/2, 0, 0])
    Xaxis.rotateZ(np.pi/2)
    
    Yaxis = p3j.Mesh(geometry=p3j.CylinderBufferGeometry(radiusTop=axis_rad, radiusBottom=axis_rad, 
                                                height=max_dist, 
                                                radiusSegments=12, 
                                                heightSegments=1, 
                                                openEnded=False, 
                                                thetaStart=0, thetaLength=2*np.pi), 
                material=p3j.MeshBasicMaterial(color=axis_color),
                position=[0, max_dist/2, 0])
    
    Zaxis = p3j.Mesh(geometry=p3j.CylinderBufferGeometry(radiusTop=axis_rad, radiusBottom=axis_rad, 
                                                height=max_dist, 
                                                radiusSegments=12, 
                                                heightSegments=1, 
                                                openEnded=False, 
                                                thetaStart=0, thetaLength=2*np.pi), 
                material=p3j.MeshBasicMaterial(color=axis_color),
                position=[0, 0, max_dist/2])
    Zaxis.rotateX(np.pi/2)

    return Xaxis, Yaxis, Zaxis
Ejemplo n.º 2
0
def test_cylinder():

    cylinder = Cylinder(10.0,
                        5.0,
                        name='cylinder',
                        color='blue',
                        material="METAL")
    assert cylinder.name == 'cylinder'
    assert cylinder.__str__() == \
        'Cylinder cylinder color:blue material:METAL length:10.0 radius:5.0'
    assert cylinder.__repr__() == 'Cylinder'
    assert cylinder.length == 10.0
    assert cylinder.radius == 5.0
    assert cylinder.color == 'blue'

    if p3js is not None:
        mesh = cylinder._p3js_mesh()
        expected_mesh = p3js.Mesh(p3js.CylinderBufferGeometry(radiusTop=5.0,
                                                              radiusBottom=5.0,
                                                              height=10.0),
                                  p3js.MeshStandardMaterial(color='blue'),
                                  name='cylinder')
        assert repr(mesh) == repr(expected_mesh)

    cylinder.name = 'cylinder1'
    assert cylinder.name == 'cylinder1'

    cylinder.length = 14.0
    assert cylinder.length == 14.0

    cylinder.radius = 7.0
    assert cylinder.radius == 7.0

    cylinder.color = 'cyan'
    assert cylinder.color == 'cyan'

    cylinder.material = 'FOIL'
    assert cylinder.material == 'FOIL'
    assert cylinder.generate_dict() == {
        "color": "cyan",
        "type": "Cylinder",
        "name": "cylinder1",
        "length": 14.0,
        "radius": 7.0,
        "material": "FOIL"
    }

    assert isinstance(cylinder, Shape)

    cylinder_ = Cylinder(10.0, 5.0, color='blue')
    assert cylinder_.name == 'unnamed'
    assert cylinder_.__str__() == \
        'Cylinder unnamed color:blue material:default length:10.0 radius:5.0'

    assert cylinder_.__repr__() == 'Cylinder'
Ejemplo n.º 3
0
def draw_cylinder(cylinder, color=None, radius_segments=8):
    geo = p3js.CylinderBufferGeometry(radiusTop=cylinder.circle.radius,
                                      radiusBottom=cylinder.circle.radius,
                                      height=cylinder.height,
                                      radiusSegments=radius_segments)
    mat = material_from_color(color)
    mesh = p3js.Mesh(geometry=geo, material=mat)
    mesh.position = list(cylinder.circle.plane.point)
    mesh.quaternion = list(
        Frame.from_plane(cylinder.circle.plane).quaternion.xyzw)
    return mesh
Ejemplo n.º 4
0
def test_cone():

    cone = Cone(10.0,
                5.0,
                name='cone',
                color='darkblue',
                material="CHECKERBOARD")
    assert cone.name == 'cone'
    assert cone.__str__() == \
        'Cone cone color:darkblue material:CHECKERBOARD length:10.0 radius:5.0'
    assert cone.__repr__() == 'Cone'
    assert cone.length == 10.0
    assert cone.radius == 5.0
    assert cone.color == 'darkblue'

    if p3js is not None:
        mesh = cone._p3js_mesh()
        expected_mesh = p3js.Mesh(p3js.CylinderBufferGeometry(radiusTop=0.0,
                                                              radiusBottom=5.0,
                                                              height=10.0),
                                  p3js.MeshStandardMaterial(color='darkblue'),
                                  name='cone')
        assert repr(mesh) == repr(expected_mesh)

    cone.name = 'cone1'
    assert cone.name == 'cone1'

    cone.length = 16.0
    assert cone.length == 16.0

    cone.radius = 3.0
    assert cone.radius == 3.0

    cone.color = 'darkcyan'
    assert cone.color == 'darkcyan'

    assert cone.generate_dict() == {
        "color": "darkcyan",
        "type": "Cone",
        "name": "cone1",
        "length": 16.0,
        "radius": 3.0,
        "material": "CHECKERBOARD"
    }
    assert isinstance(cone, Shape)

    cone_ = Cone(10.0, 5.0, color='darkblue')
    assert cone_.name == 'unnamed'
    assert cone_.__str__() == \
        'Cone unnamed color:darkblue material:default length:10.0 radius:5.0'
    assert cone_.__repr__() == 'Cone'