Esempio n. 1
0
    def scene_texcylinder2():
        def test(face, u, v):
            if face == 0:
                return (0.1, 1.0, 0.1), 0.3, 0.2, 6
            u = u - 0.5
            v = v - 0.5
            b = u / (math.sqrt(u * u + v * v))
            if 0.0 < v:
                c = math.degrees(math.asin(b))
            else:
                c = 360 - math.degrees(math.asin(b))
            c = c + 180.8
            c = c / 30.0
            c = math.floor(c)
            c = evaluator.modi(c, 2)
            if c == 1:
                return (1.0, 0.1, 0.1), 0.3, 0.2, 6
            else:
                return (0.1, 0.1, 1.0), 0.3, 0.2, 6

        l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))]
        c = Cylinder(test)
        c.translate(0.0, -0.5, 0.0)
        c.rotatex(60.0)
        c.rotatey(20.0)
        c.rotatez(40.0)
        return c, l
Esempio n. 2
0
    def scene_cylinder():
        def green(face, u, v):
            return (0.1, 1.0, 0.1), 0.3, 0.2, 6

        l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))]
        c = Cylinder(green)
        c.translate(0.0, -0.5, 0.0)
        c.rotatex(60.0)
        c.rotatey(20.0)
        c.rotatez(40.0)
        return c, l
Esempio n. 3
0
 def create_primitive_from_dict(d):
     assert d['type'] == 'cylinder'
     location = np.array(
         [d['location_x'], d['location_y'], d['location_z']], dtype=float)
     axis = np.array([d['axis_x'], d['axis_y'], d['axis_z']], dtype=float)
     radius = float(d['radius'])
     return Cylinder(center=location, radius=radius, axis=axis)
Esempio n. 4
0
    def __init__(self):
        super(Circular, self).__init__()

        self.cyl = Cylinder(np.array([0.0, 0.0, 0.0]),
                            np.array([0.0, 0.0, 1.0]), 1.0)

        self.addObject(self.cyl)
Esempio n. 5
0
    def __init__(self, link_radii=arm_radius, joint_radii=arm_radius, link_lengths=[15,15,5,5], joint_colors=arm_color,
        link_colors=arm_color, base_loc=np.array([2., 0., -15]), **kwargs):
        '''
        Instantiate the graphics and the virtual arm for a kinematic chain
        '''
        num_joints = 2
        self.num_joints = 2

        self.link_radii = make_list(link_radii, num_joints)
        self.joint_radii = make_list(joint_radii, num_joints)
        self.link_lengths = make_list(link_lengths, num_joints)
        self.joint_colors = make_list(joint_colors, num_joints)
        self.link_colors = make_list(link_colors, num_joints)

        self.curr_vecs = np.zeros([num_joints, 3]) #rows go from proximal to distal links

        # set initial vecs to correct orientations (arm starts out vertical)
        self.curr_vecs[0,2] = self.link_lengths[0]
        self.curr_vecs[1:,0] = self.link_lengths[1:]

        # Create links
        self.links = []

        for i in range(self.num_joints):
            joint = Sphere(radius=self.joint_radii[i], color=self.joint_colors[i])

            # The most distal link gets a tapered cylinder (for purely stylistic reasons)
            if i < self.num_joints - 1:
                link = Cylinder(radius=self.link_radii[i], height=self.link_lengths[i], color=self.link_colors[i])
            else:
                link = Cone(radius1=self.link_radii[-1], radius2=self.link_radii[-1]/2, height=self.link_lengths[-1], color=self.link_colors[-1])
            link_i = Group((link, joint))
            self.links.append(link_i)

        link_offsets = [0] + self.link_lengths[:-1]
        self.link_groups = [None]*self.num_joints
        for i in range(self.num_joints)[::-1]:
            if i == self.num_joints-1:
                self.link_groups[i] = self.links[i]
            else:
                self.link_groups[i] = Group([self.links[i], self.link_groups[i+1]])

            self.link_groups[i].translate(0, 0, link_offsets[i])

        # Call the parent constructor
        super(RobotArmGen3D, self).__init__([self.link_groups[0]], **kwargs)

        # Instantiate the kinematic chain object
        if self.num_joints == 2:
            self.kin_chain = robot_arms.PlanarXZKinematicChain(link_lengths)
            self.kin_chain.joint_limits = [(-pi,pi), (-pi,0)]
        else:
            self.kin_chain = robot_arms.PlanarXZKinematicChain(link_lengths)

            # TODO the code below is (obviously) specific to a 4-joint chain
            self.kin_chain.joint_limits = [(-pi,pi), (-pi,0), (-pi/2,pi/2), (-pi/2, 10*pi/180)]

        self.base_loc = base_loc
        self.translate(*self.base_loc, reset=True)
Esempio n. 6
0
    def scene_difference():
        def blue(face, u, v):
            return (0.1, 0.1, 1.0), 0.3, 0.2, 6

        def red(face, u, v):
            return (1.0, 0.1, 0.1), 0.3, 0.2, 6

        l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))]
        c1 = Cylinder(blue)
        c1.translate(0.0, -0.5, 0.0)
        c2 = Cylinder(red)
        c2.translate(0.0, -0.5, 0.0)
        c2.scale(0.8, 1.2, 0.8)
        d = Difference(c1, c2)
        d.rotatex(60.0)
        d.rotatey(20.0)
        d.rotatez(40.0)
        return d, l
Esempio n. 7
0
    def scene_texcylinder():
        def pattern(face, u, v):
            up = int(u * 24) % 2
            vp = int(v * 12) % 2
            r, g, b = 0.0, 0.1, 0.0
            if up == 0:
                r = u
            if vp == 0:
                b = v
            return (r, g, b), 0.3, 0.2, 6

        l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))]
        c = Cylinder(pattern)
        c.translate(0.0, -0.5, 0.0)
        c.rotatex(60.0)
        c.rotatey(20.0)
        c.rotatez(40.0)
        return c, l
Esempio n. 8
0
    def __init__(self, link_radii=(.2, .2), ball_radii=(.5,.5),lengths=(20, 20), ball_colors = ((1,1,1,1),(1,1,1,1)),\
        link_colors = ((1,1,1,1), (1,1,1,1)), base_loc=np.array([2., 0., -10.]), **kwargs):
        self.link_radii = link_radii
        self.ball_radii = ball_radii
        self.lengths = lengths

        self.endpt_cursor = Sphere(radius=ball_radii[1], color=(1, 0, 1, 1)) #ball_colors[1])
        self.forearm = Group([
            Cylinder(radius=link_radii[1], height=lengths[1], color=link_colors[1]), 
            self.endpt_cursor.translate(0, 0, lengths[1])]).translate(0,0,lengths[0])
        self.upperarm = Group([
            Cylinder(radius=link_radii[0], height=lengths[0],color=link_colors[0]), 
            Sphere(radius=ball_radii[0],color=ball_colors[0]).translate(0, 0, lengths[0]),
            self.forearm])
        self.system = TwoJoint(self.upperarm, self.forearm, lengths = (self.lengths))
        super(RobotArm, self).__init__([self.upperarm], **kwargs)

        self.num_links = len(link_radii)
        self.num_joints = 3 # abstract joints. this system is fully characterized by the endpoint position since the elbow angle is determined by IK

        self.base_loc = base_loc

        self.translate(*self.base_loc, reset=True)
Esempio n. 9
0
 def extract_predicted_parameters_as_json(fetched, k):
     cylinder = Cylinder(fetched['cylinder_center'][k],
                         np.sqrt(fetched['cylinder_radius_squared'][k]),
                         fetched['cylinder_axis'][k],
                         height=5)
     return {
         'type': 'cylinder',
         'center_x': cylinder.center[0],
         'center_y': cylinder.center[1],
         'center_z': cylinder.center[2],
         'radius': cylinder.radius,
         'axis_x': cylinder.axis[0],
         'axis_y': cylinder.axis[1],
         'axis_z': cylinder.axis[2],
         'height': cylinder.height,
     }
Esempio n. 10
0
    def scene_viewhole():
        def blue(face, u, v):
            return (0.1, 0.1, 1.0), 0.3, 0.2, 6

        def red(face, u, v):
            return (1.0, 0.1, 0.1), 0.3, 0.2, 6

        def green(face, u, v):
            return (0.1, 1.0, 0.1), 0.3, 0.2, 6

        def yellow(face, u, v):
            return (0.1, 1.0, 1.0), 0.3, 0.2, 6

        def cyan(face, u, v):
            return (1.0, 1.0, 0.1), 0.3, 0.2, 6

        def magenta(face, u, v):
            return (1.0, 0.1, 1.0), 0.3, 0.2, 6

        def white(face, u, v):
            return (1.0, 1.0, 1.0), 0.3, 0.2, 6

        def apex(rot):
            p1 = Plane(white)
            p1.rotatex(90)
            p2 = Plane(red)
            p2.rotatex(-90)
            p2.rotatey(30)
            i = Intersect(p1, p2)
            i.rotatey(rot)
            return i

        l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))]
        cyl3 = Cylinder(red)
        cyl3.scale(0.9999, 0.9999, 0.999)
        cyl3.translate(0.0, 3.0, 0.0)
        cyl4 = Cylinder(blue)
        cyl4.scale(0.7, 4.0, 0.7)
        a1 = apex(15)
        a2 = apex(75)
        a3 = apex(135)
        a4 = apex(195)
        a5 = apex(255)
        a6 = apex(315)
        u3 = Union(Union(Union(Union(Union(a1, a2), a3), a4), a5), a6)
        cyl5 = Cylinder(magenta)
        i2 = Intersect(u3, cyl5)
        u4 = Union(cyl4, i2)
        u4.translate(0.0, 3.5, 0.0)
        d = Difference(cyl3, u4)
        d.translate(0.0, -4.0, 2.0)
        d.uscale(4.0)
        d.rotatex(-50)
        return d, l

        d1 = Difference(u2, u4)
        #d1.uscale(0.4)
        d1.translate(0.0, -3.0, 2.0)
        d1.rotatex(-50)
        return d1, l