def hilbert_3D_test():
    l = 1
    d = 0.2 * l
    r = d
    regions = []
    with brlcad_tcl("hilbert_3d_test.g", "Hilbert-pipe 3D",
                    stl_quality=0.5) as brl_db:
        for o1 in (-1, 1):
            for o2 in (-1, 1):
                for crt_dir in NEGATE:
                    points_generator = generate_points(2,
                                                       direction=crt_dir,
                                                       order=(o1, o2),
                                                       x_vec=(l, 0, 0),
                                                       y_vec=(0, l, 0),
                                                       z_vec=(0, 0, l))
                    segments = [(x, d, 0, r) for x in points_generator]
                    shape_name = "hilbert_pipe_{}{}{}{}{}.s".format(
                        o1, o2, *crt_dir)
                    region_name = "hilbert_pipe_{}{}{}{}{}.r".format(
                        o1, o2, *crt_dir)

                    brl_db.pipe(shape_name, points=segments)
                    brl_db.region(region_name, 'u {}'.format(shape_name))
                    regions.append(region_name)

    # process the tcl script into a g database by calling mged
    brl_db.save_g()
    # process the g database into an STL file with a list of regions
    brl_db.save_stl(regions)
def hilbert_pipe(file_name,
                 size=10,
                 recursions=4,
                 dc=0.2,
                 direction=ZP,
                 variant=0,
                 x_vec=(1, 0, 0),
                 y_vec=(0, 1, 0),
                 z_vec=(0, 0, 1)):
    l = float(size) / (2**recursions)
    d = dc * l
    r = d
    points = [(x, d, 0, r) for x in generate_points(recursions,
                                                    direction=direction,
                                                    variant=variant,
                                                    x_vec=Vector(x_vec) * l,
                                                    y_vec=Vector(y_vec) * l,
                                                    z_vec=Vector(z_vec) * l)]
    with brlcad_tcl(file_name, "Hilbert-pipe 3D", stl_quality=0.5) as brl_db:
        pipe_name = "hilbert_3d.s"
        brl_db.pipe(pipe_name, points)
        region_name = "hilbert_3d.r"
        brl_db.region(region_name, 'u {}'.format(pipe_name))
    # process the tcl script into a g database by calling mged
    brl_db.save_g()
    # process the g database into an STL file with a list of regions
    brl_db.save_stl([region_name])
def main(argv):
	with brlcad_tcl(argv[1], "My Database") as brl_db:
		new_cone_example = cone_example(brl_db)
		# All units in the database file are stored in millimeters. This constrains
		# the arguments to the mk_* routines to also be in millimeters.
	# process the tcl script into a g database by calling mged
	brl_db.save_g()
	# process the g database into an STL file with a list of regions
	brl_db.save_stl(['new_cone_example'])
示例#4
0
def main(argv):
    #with wdb.WDB(argv[1], "My Database") as brl_db:
    with brlcad_tcl(argv[1], "My Database") as brl_db:
        shed = shed_example(brl_db)
        # All units in the database file are stored in millimeters. This constrains
        # the arguments to the mk_* routines to also be in millimeters.
    # process the tcl script into a g database by calling mged
    brl_db.save_g()
    # process the g database into an STL file with a list of regions
    #brl_db.save_stl(['room', 'mainroof', 'roof_window1', 'roof_window2'])  
    brl_db.save_stl(['shed'])
示例#5
0
def spiral_channel(width,
                   height,
                   inner_radius,
                   outer_radius,
                   degree_interval=0.1,
                   radius_interval=0.5):
    x = None
    y = None
    t = 0
    ang = 0
    method = 'use_square'
    # default keypoint is bottom corner, the box base center is at x: 0, y: 0
    xkey = 0
    ykey = 0
    with brlcad_tcl("spiral.tcl", "Spiral", stl_quality=0.5) as brl_db:
        segments = []
        while inner_radius < outer_radius:
            x = inner_radius * math.cos(t)
            y = inner_radius * math.sin(t)
            inner_radius += radius_interval
            ang = 90.0 - math.atan2(y, x) * 180.0 / math.pi

            shape_name = "spiral_segment_{}_{}.s".format(ang, inner_radius)
            #shape_name = "spiral_segment_{}_{}.s".format(t, inner_radius)
            if method == 'use_cylinder':
                brl_db.rcc(shape_name, (x, y, 0), (0, 0, height), width / 2.0)
            else:
                brl_db.rpp(shape_name, (x - width / 2.0, y - width / 2.0, 0),
                           (x + width / 2.0, y + width / 2.0, height))
                #brl_db.rotate_primitive(shape_name, 0,0, 1, t%360.0)

                brl_db.rotate_primitive(shape_name, 0, 0, ang)

                #ang+=45
                #brl_db.rotate_primitive(shape_name, 1,1, 0, degree_interval)
            t += degree_interval

            segments.append(shape_name)
        brl_db.region('spiral.r', 'u ' + ' u '.join(segments))
        #region_name = "hilbert_pipe_{}{}{}{}{}.r".format(o1, o2, *crt_dir)
        #brl_db.region(region_name, 'u {}'.format(shape_name))

    # process the tcl script into a g database by calling mged
    brl_db.save_g()
    # process the g database into an STL file with a list of regions
    brl_db.save_stl(['spiral.r'])
            'flow_out',
            *get_box_face_center_coord(c3, c4, xyz_desired=[1, 0, 0]))
        self.final_name = self.get_next_name(self, "COMPLETE.r")

        # finally create a region (a special combination that means it's going to be rendered)
        # by unioning together the main combinations we just created
        brl_db.region(
            self.final_name,
            'u {} u {} u {} u {}'.format(self.f1, self.f2, self.f3,
                                         self.flowtube))
        print('pump done')


if __name__ == "__main__":
    g_path_out = check_cmdline_args(__file__)
    with brlcad_tcl(g_path_out, "My Database") as brl_db:
        pump = peristaltic_3_finger_pump(brl_db)

        # tack on some pipes to the pneumatic and hydraluic connections
        # scale the 'away vector' dimension by 5000 to get some length
        # the 'away vector' will contain ONLY a single non-zero item
        # so the multiplication has no effect on non-set directions
        # (at least for cube faces, in the current implementation)
        a = pump.get_connection('flow_control_a_coord')
        brl_db.circular_cylinder('ap.s',
                                 a[1], [_c * 5000 for _c in a[2]],
                                 radius=750)

        b = pump.get_connection('flow_control_b_coord')
        brl_db.circular_cylinder('bp.s',
                                 b[1], [_c * 5000 for _c in b[2]],
示例#7
0
def main(argv):
    with brlcad_tcl(argv[1], "My Database") as brl_db:
        new_grip_example = grip_example(brl_db)
    brl_db.save_g()
    brl_db.save_stl(['new_grip_example'])
示例#8
0
"""
A small python-brlcad-tcl example that creates a spring with the pipe primitive
It creates a tcl file, then sends it to mged which creates and populates a .g file database,
 then the .g file is converted with g-stl to produce an STL file.

Run with:
python spring.py spring.tcl
"""

from python_brlcad_tcl.brlcad_tcl import *

if __name__ == "__main__":
    g_path_out = check_cmdline_args(__file__)
    with brlcad_tcl(g_path_out, "My Database1", stl_quality=0.5) as brl_db:

        # create a lookup table for 4 X,Y points on the spring circumference
        spring_outline_x_y_tuples = [(-50, -50), (-50, 50), (50, 50),
                                     (50, -50)]
        # create points, using the 10 for the z-step between points on the circumference.
        # the number of circumference points (4) times the z-step (10) yields 40, which is used to mod the z-value
        # this gets a series of 0,1,2,3 repeating, which is used as an index to the circumference X,Y values list
        # these tuples then get unpacked into the two x and y values using the * notation
        z_step = 10
        points = []
        for z in range(0, 110, 10):
            circumference_xy_index = (
                z % (len(spring_outline_x_y_tuples) * z_step)) / z_step
            x, y = spring_outline_x_y_tuples[circumference_xy_index]
            point = brl_db.pipe_point(x=x,
                                      y=y,
                                      z=z,
示例#9
0
def createPencilSharpener():

    #Create the two cylinders for the bottom layer
    #Also we're working in Inches
    brl = brlcad_tcl(tcl_filepath=outFileTCL,
                     title="Pencil Sharpener Gear",
                     make_g=False,
                     make_stl=True,
                     stl_quality=stlQuality,
                     units='in')

    #Create our cylinders, regions, names, etc...
    bottom = 'b'
    bottomNegative = 'bn'
    bottomRing = 'br'
    bottomFinal = 'bf'

    middle = 'm'
    middleNegative = 'mn'
    middleRing = 'mr'
    middleWithGuide = 'mh'
    middleFinal = 'mf'

    middleTop = 'mt'
    middleTopNegative = 'mtn'
    middleTopRing = 'mtr'

    top = 't'
    topNegative = 'tn'
    topRing = 'tr'
    topFinal = 'tf'

    shavingsHole = 'sh'

    leftGuide = 'l'
    rightGuide = 'r'

    gearName = 'gf'
    toothName = 'tooth'

    allFinal = 'finished'

    #Variables for their sizes and positions, in inches
    bottomOuterRadius = 0.650
    bottomInnerRadius = 0.460
    bottomHeight = 0.262
    bottomPosition = (0, 0, 0)

    middleOuterRadius = 0.502
    middleInnerRadius = 0.4575
    middleHeight = 0.275
    middlePosition = (0, 0, bottomHeight
                      )  #Placed right on top of the bottom one

    topOuterRadius = 0.49 / 2  #Measured diameter with Callipers
    topInnerRadius = 0.3937 / 2  #Measured diameter with Callipers
    topHeight = 0.383
    topPosition = (0, 0, bottomHeight + middleHeight)

    middleTopOuterRadius = middleOuterRadius  #This acts as the top for the middle, since it is too thin
    middleTopInnerRadius = topInnerRadius  #This is the hole that goes through the top, so the bushel can go through
    middleTopHeight = -middleHeight * 0.25  #Negative because we're going from the top downward
    middleTopPosition = (0, 0, bottomHeight + middleHeight)

    leftGuideOuterRadius = 0.0625  #GET BETTER MEASUREMENT?!?
    rightGuideOuterRadius = leftGuideOuterRadius
    leftGuideHeight = topHeight / 2  #ALSO GET BETTER
    rightGuideHeight = leftGuideHeight
    leftGuideYOffset = -leftGuideOuterRadius / 2  #Apparently they are offset a little.
    leftGuidePosition = (middleOuterRadius - leftGuideOuterRadius,
                         leftGuideYOffset, bottomHeight + middleHeight)
    rightGuidePosition = (-leftGuidePosition[0], leftGuidePosition[1],
                          leftGuidePosition[2])  #Put it on the other side

    #Now we need the box that'll make our pencil shavings hole
    holeWidthFull = 0.75
    holeWidth = holeWidthFull / 2
    holeHeightFull = middleHeight
    holeHeight = holeHeightFull / 2
    holeDepthFull = middleOuterRadius

    holeCenterHeight = bottomHeight + (middleHeight / 2)

    #Create the 8 points that make the box
    holePoints = (
        (-holeWidth, 0, holeCenterHeight - holeHeight),
        (holeWidth, 0, holeCenterHeight - holeHeight),
        (holeWidth, 0, holeCenterHeight + holeHeight),
        (-holeWidth, 0, holeCenterHeight + holeHeight),
        (-holeWidth, holeDepthFull, holeCenterHeight - holeHeight),
        (holeWidth, holeDepthFull, holeCenterHeight - holeHeight),
        (holeWidth, holeDepthFull, holeCenterHeight + holeHeight),
        (-holeWidth, holeDepthFull, holeCenterHeight + holeHeight),
    )

    #Get the lines for the gears
    toothHalfWidth = 0.27
    toothDepth = bottomInnerRadius + (
        (bottomOuterRadius - bottomInnerRadius) / 2)
    toothHeight = bottomHeight * 0.75  #3/4 of the height

    #Now we start building all of our shapes

    #Start with bottom...
    brl.rcc(bottom, bottomPosition, (0, 0, bottomHeight), bottomOuterRadius)
    brl.rcc(bottomNegative, bottomPosition, (0, 0, bottomHeight),
            bottomInnerRadius)

    #Now subtract inner from outer
    brl.region(bottomRing, subtract(bottom, bottomNegative))

    #Now make the middle and cut it into a ring
    brl.rcc(middle, middlePosition, (0, 0, middleHeight), middleOuterRadius)
    brl.rcc(middleNegative, middlePosition, (0, 0, middleHeight),
            middleInnerRadius)
    brl.region(middleRing, subtract(middle, middleNegative))

    #Now turn the top into a ring
    brl.rcc(top, topPosition, (0, 0, topHeight), topOuterRadius)
    brl.rcc(topNegative, topPosition, (0, 0, topHeight), topInnerRadius)
    brl.region(topRing, subtract(top, topNegative))

    #Now going from top down, we'll turn the top into a top-hat
    brl.rcc(middleTop, middleTopPosition, (0, 0, middleTopHeight),
            middleTopOuterRadius)
    brl.rcc(middleTopNegative, middleTopPosition, (0, 0, middleTopHeight),
            middleTopInnerRadius)
    brl.region(middleTopRing, subtract(middleTop, middleTopNegative))

    #And now add it to the top
    brl.region(topFinal, union(topRing, middleTopRing))

    #Next we will add the guides to the middle...
    brl.rcc(leftGuide, leftGuidePosition, (0, 0, leftGuideHeight),
            leftGuideOuterRadius)
    brl.rcc(rightGuide, rightGuidePosition, (0, 0, rightGuideHeight),
            rightGuideOuterRadius)

    #Now add them
    brl.region(middleWithGuide, union(middleRing, leftGuide, rightGuide))

    #And now cut the hole for pencil shavings
    brl.arb8(shavingsHole, holePoints)
    brl.region(middleFinal, subtract(middleWithGuide, shavingsHole))

    #Finally, we'll cut the gears out of the bottom...
    #Get all the content for the gears
    gearLines, gearName = toothGen.createGears(gearName=gearName,
                                               toFile=False,
                                               toothHalfWidth=toothHalfWidth,
                                               toothDepth=toothDepth,
                                               toothHeight=toothHeight,
                                               toothBaseName=toothName)

    #Now add those lines to the object...
    linesFlat = '\n'.join(gearLines)
    brl.add_script_string(linesFlat)

    #Now we want to subtract the gear from the bottom
    brl.region(bottomFinal, subtract(bottomRing, gearName))

    #We now have a bunch of final regions. Combine them into the final gear housing
    brl.region(allFinal, union(bottomFinal, middleFinal, topFinal))

    #Now we can convert the .g into a .stl, using the final region. save_stl requires a list.
    brl.run_and_save_stl([allFinal])
                                      0)
            brl_db.remove_object_from_combination(combination_name,
                                                  self.center_input)
            brl_db.end_combination_edit()

            all_items += to_union
            combinations.append(combination_name)

        all_arms = brl_db.combination('all_arms_combo.r',
                                      'u {}'.format(' u '.join(combinations)))
        return all_arms


if __name__ == "__main__":
    g_path_out = check_cmdline_args(__file__)
    with brlcad_tcl(g_path_out, "My Database", make_g=True,
                    verbose=False) as brl_db:
        device = tobacco_mesophyll_protoplast_fusion_device(
            input_port_diameter=1200,
            input_symmetric_bifurcation_inner_width=200,
            input_symmetric_bifurcation_outer_width=900,
            symmetric_bifurcation_post_w=20,
            symmetric_bifurcation_post_h=30,
            symmetric_bifurcation_post_roundness=15,
            symmetric_bifurcation_post_pitch=40,
            length_catcher=3200,
            width_catcher=900,
            catcher_post_w=20,
            catcher_post_h=30,
            catcher_post_roundness=20,
            catcher_post_pitch=20 + (20 / 2),
            distance_output_port_from_center=3200 + 200 + 800,
示例#11
0
def main(argv):
    with brlcad_tcl(argv[1], "My Database") as brl_db:
        new_polyhedron = polyhedron_example(brl_db)
    brl_db.save_g()
    brl_db.save_stl(['new_polyhedron'])
示例#12
0
def main(argv):
    with brlcad_tcl(argv[1], "My Database") as brl_db:
        example = wdb_example(brl_db)
    brl_db.save_g()
    brl_db.save_stl(['example'])
            pmax=(
                self.keyway_base_diameter / 2.0,  # x
                self.shaft_y_offset + (self.key_width / 2.0),  # y
                key_end)  # z
        )
        print 'Completed step 4 of shaft, part name: {}'.format(shaft4)

        shaft_key = self.get_next_name(self, "shaft_key.c")
        self.brl_db.combination(shaft_key, 'u {} + {}'.format(shaft3, shaft4))
        print 'Completed step 5 of shaft, part name: {}'.format(shaft_key)

        # Make a region that is the union of these two objects. To accomplish
        # this, we don't need anymore to create any linked list of the items ;-).
        shaft = self.get_next_name(self, "shaft.c")
        self.brl_db.combination(
            shaft, 'u {} u {} u {}'.format(shaft1, shaft2, shaft_key))
        return shaft

    def wires(self):
        pass


if __name__ == "__main__":
    #with wdb.WDB(argv[1], "My Database") as brl_db:
    g_path_out = check_cmdline_args(__file__)
    with brlcad_tcl(g_path_out, "My Database", make_g=True) as brl_db:
        motor = motor_28BYJ_48(brl_db)
        # All units in the database file are stored in millimeters. This constrains
        # the arguments to the mk_* routines to also be in millimeters.
    brl_db.save_stl([motor.final_name])
                                      (-tangent_chord_offset) * sin(angle_rad), 0)
            brl_db.remove_object_from_combination(combination_name, self.center_input)
            brl_db.end_combination_edit()

            all_items += to_union
            combinations.append(combination_name)
        
        all_arms = brl_db.combination('all_arms_combo.r',
                                      'u {}'
                                      .format(' u '.join(combinations)))
        return all_arms


if __name__ == "__main__":
    g_path_out = check_cmdline_args(__file__)
    with brlcad_tcl(g_path_out, "My Database", make_g=True, verbose=False) as brl_db:
        device = tobacco_mesophyll_protoplast_fusion_device(input_port_diameter=1200,
                                                            input_symmetric_bifurcation_inner_width=200,
                                                            input_symmetric_bifurcation_outer_width=900,
                                                            symmetric_bifurcation_post_w=20,
                                                            symmetric_bifurcation_post_h=30,
                                                            symmetric_bifurcation_post_roundness=15,
                                                            symmetric_bifurcation_post_pitch=40,
                                                            length_catcher=3200,
                                                            width_catcher=900,
                                                            catcher_post_w=20,
                                                            catcher_post_h=30,
                                                            catcher_post_roundness=20,
                                                            catcher_post_pitch=20 + (20 / 2),
                                                            distance_output_port_from_center=3200 + 200 + 800,
                                                            dist_center_catcher_to_center_device=(3200 / 2) + 800,