Exemple #1
0
def upper_tabletop_2(d, dressup=True):
    m = Part.makeBox(d["length"], d["width"], d["upper_tabletop_t"])
    m.translate(Base.Vector(-d["length"] / 2, -d["width"] / 2, 0))
    m = dc.model.fillet_edges_by_length(m, 35, d["upper_tabletop_t"])

    print("Upper tabletop length: ", d["length"])
    print("Upper tabletop width: ", d["width"])

    ccx = d["length"] - 2 * math.sqrt(
        ((d["cx"] + d["leg_distance_from_corner"])**2) / 2.0)
    ccy = d["width"] - 2 * math.sqrt(
        ((d["cx"] + d["leg_distance_from_corner"])**2) / 2.0)
    hx = ccx / 2.0
    hy = ccy / 2.0

    hole_points = [
        Base.Vector(hx, hy, 0),
        Base.Vector(-hx, hy, 0),
        Base.Vector(-hx, -hy, 0),
        Base.Vector(hx, -hy, 0)
    ]

    a = 135
    for p in hole_points:
        hole = Part.makeCylinder(d["hole_dia_tabletop"] / 2.0,
                                 d["upper_tabletop_t"], p,
                                 Base.Vector(0, 0, 1), 360)

        insert_1 = Part.makeBox(d["leg_t"], d["insertion_width_1"],
                                d["insertion_length"])
        insert_1 = dc.model.fillet_edges_by_length(insert_1,
                                                   d["leg_edge_radii"],
                                                   d["insertion_length"])
        insert_1.translate(Base.Vector(-d["leg_t"] / 2, -d["cx"], 0))
        insert_1.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), a)
        insert_1.translate(p)

        insert_2 = Part.makeBox(d["leg_t"], d["insertion_width_2"],
                                d["insertion_length"])
        insert_2 = dc.model.fillet_edges_by_length(insert_2,
                                                   d["leg_edge_radii"],
                                                   d["insertion_length"])
        insert_2.translate(
            Base.Vector(-d["leg_t"] / 2, -d["insertion_width_3"] / 2.0, 0))
        insert_2.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), a)
        insert_2.translate(p)

        m = m.cut(insert_1).cut(insert_2).cut(hole)
        a = a + 90

    if dressup:
        m = dc.model.fillet_edges_longer_than(m, d["tabletop_edge_radii"], 300)

    m.translate(Base.Vector(0, 0, -d["upper_tabletop_t"]))
    return m
Exemple #2
0
def lower_tabletop_2(d, dressup=True):
    ccx = d["length"] - 2 * math.sqrt(
        ((d["cx"] + d["leg_distance_from_corner"])**2) / 2.0)
    ccy = d["width"] - 2 * math.sqrt(
        ((d["cx"] + d["leg_distance_from_corner"])**2) / 2.0)

    length = ccx + (2 * d["leg_distance_from_corner"] +
                    d["insertion_width_3"]) / math.sqrt(2.0)
    width = ccy + (2 * d["leg_distance_from_corner"] +
                   d["insertion_width_3"]) / math.sqrt(2.0)

    print("Lower tabletop length: ", length)
    print("Lower tabletop width: ", width)

    m = Part.makeBox(length, width, d["lower_tabletop_t"])
    m.translate(Base.Vector(-length / 2.0, -width / 2.0, 0))
    m = dc.model.fillet_edges_by_length(m, 35, d["lower_tabletop_t"])

    hx = ccx / 2.0
    hy = ccy / 2.0

    hole_points = [
        Base.Vector(hx, hy, 0),
        Base.Vector(-hx, hy, 0),
        Base.Vector(-hx, -hy, 0),
        Base.Vector(hx, -hy, 0)
    ]

    a = 45
    for p in hole_points:
        hole = Part.makeCylinder(d["hole_dia_tabletop"] / 2.0,
                                 d["lower_tabletop_t"], p,
                                 Base.Vector(0, 0, 1), 360)
        insert = Part.makeBox(d["leg_t"], d["insertion_width_3"],
                              d["insertion_length"])
        insert = dc.model.fillet_edges_by_length(insert, d["leg_edge_radii"],
                                                 d["insertion_length"])
        insert.translate(
            Base.Vector(-d["leg_t"] / 2, -d["insertion_width_3"] / 2, 0))
        insert.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), -a)
        insert.translate(p)
        m = m.cut(hole).cut(insert)
        a = a + 90

    if dressup:
        m = dc.model.fillet_edges_longer_than(m, d["tabletop_edge_radii"], 150)

    m.translate(Base.Vector(0, 0, -d["lower_tabletop_t"]))
    return m
Exemple #3
0
def wettedArea(shape, draft, trim):
    """ Calculate wetted ship area.
    @param shape Ship external faces instance.
    @param draft Draft.
    @param trim Trim in degrees.
    @return Wetted ship area.
    """
    area     = 0.0
    nObjects = 0
    # We will take a duplicate of ship shape in order to place it
    shape = shape.copy()
    shape.translate(Vector(0.0,0.0,-draft))
    shape.rotate(Vector(0.0,0.0,0.0), Vector(0.0,-1.0,0.0), trim)
    # Now we need to know the x range of values
    bbox = shape.BoundBox
    xmin = bbox.XMin
    xmax = bbox.XMax
    # Create the box
    L = xmax - xmin
    B = bbox.YMax - bbox.YMin
    p = Vector(-1.5*L, -1.5*B, bbox.ZMin - 1.0)
    box = Part.makeBox(3.0*L, 3.0*B, - bbox.ZMin + 1.0, p)
    # Compute common part with ship
    for f in shape.Faces:
        # Get solids intersection
        try:
            common = box.common(f)
        except:
            continue
        area = area + common.Area
    return area
Exemple #4
0
def glasstop(d, dressup=True):
    m = Part.makeBox(d["length"], d["width"], d["glass_t"])
    m.translate(Base.Vector(-d["length"] / 2, -d["width"] / 2, -d["glass_t"]))

    if dressup:
        m = dc.model.chamfer_edges_longer_than(m, 2, 100)

    return m
Exemple #5
0
def mainFrameCoeff(ship, draft):
    """ Calculate main frame coefficient.
    @param ship Selected ship instance
    @param draft Draft.
    @return Main frame coefficient
    """
    cm       = 0.0
    maxY     = 0.0
    minY     = 0.0
    # We will take a duplicate of ship shape in order to place it
    shape = ship.Shape.copy()
    shape.translate(Vector(0.0,0.0,-draft))
    x    = 0.0
    area = 0.0
    # Now we need to know the x range of values
    bbox = shape.BoundBox
    xmin = bbox.XMin
    xmax = bbox.XMax
    # Create the box
    L = xmax - xmin
    B = bbox.YMax - bbox.YMin
    p = Vector(-1.5*L, -1.5*B, bbox.ZMin - 1.0)
    box = Part.makeBox(1.5*L + x, 3.0*B, - bbox.ZMin + 1.0, p)
    # Compute common part with ship
    for s in shape.Solids:
        # Get solids intersection
        try:
            common = box.common(s)
        except:
            continue
        if common.Volume == 0.0:
            continue
        # Recompute object adding it to the scene, when we have
        # computed desired data we can remove it.
        try:
            Part.show(common)
        except:
            continue
        # Divide by faces and compute only section placed ones
        faces  = common.Faces
        for f in faces:
            faceBounds = f.BoundBox
            # Orientation filter
            if faceBounds.XMax - faceBounds.XMin > 0.00001:
                continue
            # Place filter
            if abs(faceBounds.XMax - x) > 0.00001:
                continue
            # Valid face, compute area
            area = area + f.Area
            maxY = max(maxY, faceBounds.YMax)
            minY = max(minY, faceBounds.YMin)
        # Destroy last object generated
        App.ActiveDocument.removeObject(App.ActiveDocument.Objects[-1].Name)
    dy = maxY - minY
    if dy*draft > 0.0:
        cm = area / (dy*draft)
    return cm
Exemple #6
0
def upper_tabletop_3(d, dressup=True):
    s = 35
    x1 = d["length"] / 2.0
    y1 = d["width"] / 2.0
    x2 = x1 - 25
    y2 = y1 - 25

    p = [None] * 12

    p[0] = Base.Vector(-x1, y2, 0)
    p[1] = Base.Vector(-x2, y1, 0)

    p[3] = Base.Vector(x2, y1, 0)
    p[4] = Base.Vector(x1, y2, 0)

    p[6] = Base.Vector(x1, -y2, 0)
    p[7] = Base.Vector(x2, -y1, 0)

    p[9] = Base.Vector(-x2, -y1, 0)
    p[10] = Base.Vector(-x1, -y2, 0)

    p[2] = dc.model.sagpoint(p[1], p[3], s)
    p[5] = dc.model.sagpoint(p[4], p[6], s)
    p[8] = dc.model.sagpoint(p[7], p[9], s)
    p[11] = dc.model.sagpoint(p[10], p[0], s)

    wire = [
        Part.makeLine(p[0], p[1]),
        dc.model.makeArc(p[1:4]),
        Part.makeLine(p[3], p[4]),
        dc.model.makeArc(p[4:7]),
        Part.makeLine(p[6], p[7]),
        dc.model.makeArc(p[7:10]),
        Part.makeLine(p[9], p[10]),
        dc.model.makeArc([p[10], p[11], p[0]])
    ]

    face = Part.Face(Part.Wire(wire))
    m = face.extrude(Base.Vector(0, 0, d["upper_tabletop_t"]))
    m = dc.model.fillet_edges_by_length(m, 60, d["upper_tabletop_t"])

    print("Upper tabletop length: ", d["length"])
    print("Upper tabletop width: ", d["width"])

    ccx = d["length"] - 2 * math.sqrt(
        ((d["cx"] + d["leg_distance_from_corner"])**2) / 2.0)
    ccy = d["width"] - 2 * math.sqrt(
        ((d["cx"] + d["leg_distance_from_corner"])**2) / 2.0)
    hx = ccx / 2.0
    hy = ccy / 2.0

    hole_points = [
        Base.Vector(hx, hy, 0),
        Base.Vector(-hx, hy, 0),
        Base.Vector(-hx, -hy, 0),
        Base.Vector(hx, -hy, 0)
    ]

    a = 135
    for p in hole_points:
        hole = Part.makeCylinder(d["hole_dia_tabletop"] / 2.0,
                                 d["upper_tabletop_t"] / 2.0, p,
                                 Base.Vector(0, 0, 1), 360)

        insert_1 = Part.makeBox(d["leg_t"], d["insertion_width_1"],
                                d["insertion_length"])
        insert_1 = dc.model.fillet_edges_by_length(insert_1,
                                                   d["leg_edge_radii"],
                                                   d["insertion_length"])
        insert_1.translate(Base.Vector(-d["leg_t"] / 2, -d["cx"], 0))
        insert_1.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), a)
        insert_1.translate(p)

        insert_2 = Part.makeBox(d["leg_t"], d["insertion_width_2"],
                                d["insertion_length"])
        insert_2 = dc.model.fillet_edges_by_length(insert_2,
                                                   d["leg_edge_radii"],
                                                   d["insertion_length"])
        insert_2.translate(
            Base.Vector(-d["leg_t"] / 2, -d["insertion_width_3"] / 2.0, 0))
        insert_2.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), a)
        insert_2.translate(p)

        m = m.cut(insert_1).cut(insert_2).cut(hole)
        a = a + 90

    if dressup:
        m = dc.model.fillet_edges_longer_than(m, d["tabletop_edge_radii"], 300)

    m.translate(Base.Vector(0, 0, -d["upper_tabletop_t"]))
    return m
Exemple #7
0
def lower_tabletop_3(d, dressup=True):
    ccx = d["length"] - 2 * math.sqrt(
        ((d["cx"] + d["leg_distance_from_corner"])**2) / 2.0)
    ccy = d["width"] - 2 * math.sqrt(
        ((d["cx"] + d["leg_distance_from_corner"])**2) / 2.0)

    length = ccx + (2 * d["leg_distance_from_corner"] +
                    d["insertion_width_3"]) / math.sqrt(2.0)
    width = ccy + (2 * d["leg_distance_from_corner"] +
                   d["insertion_width_3"]) / math.sqrt(2.0)

    print("Lower tabletop length: ", length)
    print("Lower tabletop width: ", width)

    x1 = length / 2.0
    y1 = width / 2.0
    x2 = x1 - 25
    y2 = y1 - 25

    p = [None] * 12

    p[0] = Base.Vector(-x1, y2, 0)
    p[1] = Base.Vector(-x2, y1, 0)

    p[3] = Base.Vector(x2, y1, 0)
    p[4] = Base.Vector(x1, y2, 0)

    p[6] = Base.Vector(x1, -y2, 0)
    p[7] = Base.Vector(x2, -y1, 0)

    p[9] = Base.Vector(-x2, -y1, 0)
    p[10] = Base.Vector(-x1, -y2, 0)

    p[2] = dc.model.sagpoint(p[1], p[3], -45)
    p[5] = dc.model.sagpoint(p[4], p[6], -45)
    p[8] = dc.model.sagpoint(p[7], p[9], -45)
    p[11] = dc.model.sagpoint(p[10], p[0], -45)

    wire = [
        Part.makeLine(p[0], p[1]),
        dc.model.makeArc(p[1:4]),
        Part.makeLine(p[3], p[4]),
        dc.model.makeArc(p[4:7]),
        Part.makeLine(p[6], p[7]),
        dc.model.makeArc(p[7:10]),
        Part.makeLine(p[9], p[10]),
        dc.model.makeArc([p[10], p[11], p[0]])
    ]

    face = Part.Face(Part.Wire(wire))
    m = face.extrude(Base.Vector(0, 0, d["lower_tabletop_t"]))
    m = dc.model.fillet_edges_by_length(m, 20, d["lower_tabletop_t"])

    hx = ccx / 2.0
    hy = ccy / 2.0

    hole_points = [
        Base.Vector(hx, hy, 0),
        Base.Vector(-hx, hy, 0),
        Base.Vector(-hx, -hy, 0),
        Base.Vector(hx, -hy, 0)
    ]

    a = 45
    for p in hole_points:
        hole = Part.makeCylinder(d["hole_dia_tabletop"] / 2.0,
                                 d["lower_tabletop_t"], p,
                                 Base.Vector(0, 0, 1), 360)
        insert = Part.makeBox(d["leg_t"], d["insertion_width_3"],
                              d["insertion_length"])
        insert = dc.model.fillet_edges_by_length(insert, d["leg_edge_radii"],
                                                 d["insertion_length"])
        insert.translate(
            Base.Vector(-d["leg_t"] / 2, -d["insertion_width_3"] / 2, 0))
        insert.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), -a)
        insert.translate(p)
        m = m.cut(hole).cut(insert)
        a = a + 90

    if dressup:
        m = dc.model.fillet_edges_longer_than(m, d["tabletop_edge_radii"], 150)

    m.translate(Base.Vector(0, 0, -d["lower_tabletop_t"]))
    return m
Exemple #8
0
 def create_default_shape(cls):
     # Create default shape, a simple box
     cls.fcd_shape = Part.makeBox(cls.default_length, cls.default_width,
                                  cls.default_height)
Exemple #9
0
def areas(ship, draft, roll=0.0, trim=0.0, yaw=0.0, n=30):
    """ Compute ship transversal areas.
    @param ship Ship instance.
    @param draft Ship draft.
    @param roll Ship roll angle.
    @param trim Ship trim angle.
    @param yaw Ship yaw angle. Ussually you don't want to use this 
    value.
    @param n Number of sections to perform.
    @return Transversal areas (every area value is composed by x 
    coordinate and computed area)
    """
    if n < 2:
        return []
    # We will take a duplicate of ship shape in order to place it
    shape = ship.Shape.copy()
    shape.translate(Vector(0.0,0.0,-draft))
    # Rotations composition is Roll->Trim->Yaw
    shape.rotate(Vector(0.0,0.0,0.0), Vector(1.0,0.0,0.0), roll)
    shape.rotate(Vector(0.0,0.0,0.0), Vector(0.0,-1.0,0.0), trim)
    shape.rotate(Vector(0.0,0.0,0.0), Vector(0.0,0.0,1.0), yaw)
    # Now we need to know the x range of values
    bbox = shape.BoundBox
    xmin = bbox.XMin
    xmax = bbox.XMax
    dx   = (xmax - xmin) / (n-1.0)
    # First area is equal to zero.
    areas = [[xmin, 0.0]]
    # Since we need face entities, in order to compute sections we will
    # create boxes with front face at transversal area position, 
    # compute solid common, divide by faces, and preserve only desired
    # ones.
    App.Console.PrintMessage("Computing transversal areas...\n")
    App.Console.PrintMessage("Some Inventor representation errors can be shown, ignore it please.\n")
    for i in range(1,n-1):
        App.Console.PrintMessage("%d / %d\n" % (i, n-2))
        x    = xmin + i*dx
        area = 0.0
        # Create the box
        L = xmax - xmin
        B = bbox.YMax - bbox.YMin
        p = Vector(-1.5*L, -1.5*B, bbox.ZMin - 1.0)
        box = Part.makeBox(1.5*L + x, 3.0*B, - bbox.ZMin + 1.0, p)
        # Compute common part with ship
        for s in shape.Solids:
            # Get solids intersection
            try:
                common = box.common(s)
            except:
                continue
            if common.Volume == 0.0:
                continue
            # Recompute object adding it to the scene, when we have
            # computed desired data we can remove it.
            try:
                Part.show(common)
            except:
                continue
            # Divide by faces and compute only section placed ones
            faces  = common.Faces
            for f in faces:
                faceBounds = f.BoundBox
                # Orientation filter
                if faceBounds.XMax - faceBounds.XMin > 0.00001:
                    continue
                # Place filter
                if abs(faceBounds.XMax - x) > 0.00001:
                    continue
                # Valid face, compute area
                area = area + f.Area
            # Destroy last object generated
            App.ActiveDocument.removeObject(App.ActiveDocument.Objects[-1].Name)
        # Append transversal area
        areas.append([x, area])
    # Last area is equal to zero
    areas.append([xmax, 0.0])
    App.Console.PrintMessage("Done!\n")
    return areas
Exemple #10
0
def displacement(ship, draft, roll=0.0, trim=0.0, yaw=0.0):
    """ Compute ship displacement.
    @param ship Ship instance.
    @param draft Ship draft.
    @param roll Ship roll angle.
    @param trim Ship trim angle.
    @param yaw Ship yaw angle. Ussually you don't want to use this 
    value.
    @return [disp, B, Cb], \n
    disp = Ship displacement [ton].
    B    = Bouyance center [m].
    Cb   = Block coefficient.
    @note Bouyance center will returned as FreeCAD.Vector class.
    @note Returned Bouyance center is in non modified ship coordinates
    """
    # We will take a duplicate of ship shape in order to place it
    shape = ship.Shape.copy()
    shape.translate(Vector(0.0,0.0,-draft))
    # Rotations composition is Roll->Trim->Yaw
    shape.rotate(Vector(0.0,0.0,0.0), Vector(1.0,0.0,0.0), roll)
    shape.rotate(Vector(0.0,0.0,0.0), Vector(0.0,-1.0,0.0), trim)
    shape.rotate(Vector(0.0,0.0,0.0), Vector(0.0,0.0,1.0), yaw)
    # Now we need to know box dimensions
    bbox = shape.BoundBox
    xmin = bbox.XMin
    xmax = bbox.XMax
    # Create the box
    L = xmax - xmin
    B = bbox.YMax - bbox.YMin
    p = Vector(-1.5*L, -1.5*B, bbox.ZMin - 1.0)
    box = Part.makeBox(3.0*L, 3.0*B, -bbox.ZMin + 1.0, p)
    vol = 0.0
    cog = Vector()
    for solid in shape.Solids:
        # Compute common part with ship
        try:
            common = box.common(solid)
        except:
            continue
        # Get data
        vol = vol + common.Volume
        for s in common.Solids:
            sCoG  = s.CenterOfMass
            cog.x = cog.x + sCoG.x*s.Volume
            cog.y = cog.y + sCoG.y*s.Volume
            cog.z = cog.z + sCoG.z*s.Volume
    cog.x = cog.x / vol
    cog.y = cog.y / vol
    cog.z = cog.z / vol
    Vol = L*B*abs(bbox.ZMin)
    # Undo transformations
    B   = Vector()
    B.x = cog.x*math.cos(math.radians(-yaw)) - cog.y*math.sin(math.radians(-yaw))
    B.y = cog.x*math.sin(math.radians(-yaw)) + cog.y*math.cos(math.radians(-yaw))
    B.z = cog.z
    cog.x = B.x*math.cos(math.radians(-trim)) - B.z*math.sin(math.radians(-trim))
    cog.y = B.y
    cog.z = B.x*math.sin(math.radians(-trim)) + B.z*math.cos(math.radians(-trim))
    B.x = cog.x
    B.y = cog.y*math.cos(math.radians(-roll)) - cog.z*math.sin(math.radians(-roll))
    B.z = cog.y*math.sin(math.radians(-roll)) + cog.z*math.cos(math.radians(-roll))
    B.z = B.z + draft
    # Return data
    dens = 1.025 # [tons/m3], salt water
    return [dens*vol, B, vol/Vol]
Exemple #11
0
def leg(d, dressup=True):
    corner_protection = 14
    s1 = d["leg_s1"]
    s2 = d["leg_s2"]
    s3 = d["leg_s3"]
    s4 = d["leg_s4"]

    x0 = d["cx"] + d["insertion_width"] / 2.0 + corner_protection
    x1 = d["cx"] - d["insertion_width"] / 2.0 + corner_protection
    x2 = x1 - 25
    x3 = 100
    x4 = 80
    x5 = x3 - 55

    y0 = d["height"]
    y2 = d["height_1"] - d["tabletop_t"] + d["insertion_length"]
    y1 = y2 - 12
    y3 = y2 - d["insertion_length"]
    y5 = d["height_2"] - d["insertion_length"]
    y4 = y5 + d["insertion_length"]
    y6 = y5 + 12
    y7 = y0 - 30

    p = [None] * 19
    p[0] = Base.Vector(0, y0, 0)
    p[1] = Base.Vector(x4, y0, 0)

    p[3] = Base.Vector(x2, y1, 0)
    p[4] = Base.Vector(x1, y1, 0)
    p[5] = Base.Vector(x1, y2, 0)
    p[6] = Base.Vector(x0, y2, 0)
    p[7] = Base.Vector(x0, y3, 0)

    p[9] = Base.Vector(x0, y4, 0)
    p[10] = Base.Vector(x0, y5, 0)
    p[11] = Base.Vector(x1, y5, 0)
    p[12] = Base.Vector(x1, y6, 0)
    p[13] = Base.Vector(x2, y6, 0)

    p[15] = Base.Vector(x3, 0, 0)
    p[16] = Base.Vector(x5, 0, 0)

    p[18] = Base.Vector(0, y7, 0)

    p[2] = dc.model.sagpoint(p[1], p[3], s1)
    p[8] = dc.model.sagpoint(p[7], p[9], s2)
    p[14] = dc.model.sagpoint(p[13], p[15], s3)
    p[17] = dc.model.sagpoint(p[16], p[18], s4)

    wire = [
        Part.makeLine(p[0], p[1]),
        dc.model.makeArc(p[1:4]),
        Part.makeLine(p[3], p[4]),
        Part.makeLine(p[4], p[5]),
        Part.makeLine(p[5], p[6]),
        Part.makeLine(p[6], p[7]),
        dc.model.makeArc(p[7:10]),
        Part.makeLine(p[9], p[10]),
        Part.makeLine(p[10], p[11]),
        Part.makeLine(p[11], p[12]),
        Part.makeLine(p[12], p[13]),
        dc.model.makeArc(p[13:16]),
        Part.makeLine(p[15], p[16]),
        dc.model.makeArc([p[16], p[17], p[18]]),
        Part.makeLine(p[18], p[0])
    ]

    face = Part.Face(Part.Wire(wire))
    m = face.extrude(Base.Vector(0, 0, d["leg_t"]))

    m = dc.model.fillet_edge_xy(m, 100, p[18])
    m = dc.model.fillet_edge_xy(m, 20, p[3])
    m = dc.model.fillet_edge_xy(m, 8, p[4])
    m = dc.model.fillet_edge_xy(m, 8, p[12])
    m = dc.model.fillet_edge_xy(m, 20, p[13])

    m.rotate(Base.Vector(0, 0, 0), Base.Vector(1, 0, 0), 90)
    m.translate(Base.Vector(-corner_protection, d["leg_t"] / 2.0, 0))

    hole = Part.makeCylinder(d["hole_dia_leg"] / 2.0, d["height"],
                             Base.Vector(d["cx"], 0, 0), Base.Vector(0, 0, 1),
                             360)
    m = m.cut(hole)
    corner_cutout = Part.makeBox(4.0 * d["leg_t"], 4.0 * d["leg_t"],
                                 d["glass_t"] + 2.0)
    corner_cutout.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), -45.0)
    corner_cutout.translate(
        Base.Vector(-2, 0, d["height"] - d["glass_t"] - 2.0))
    m = m.cut(corner_cutout)

    if dressup:
        m = dc.model.fillet_edges_longer_than(m, 7, 100)

    return m
Exemple #12
0
def tabletop(d, dressup=True):
    r3 = 60  # d["tabletop_r3"]
    s1 = d["tabletop_s1"]
    s2 = -100  #d["tabletop_s2"]
    s3 = d["tabletop_s3"]
    x2 = (d["length"] - 120) / 2.0
    x1 = x2 - r3
    y1 = (d["width"] - 120) / 2.0
    y2 = y1 - r3

    p = [None] * 17

    p[0] = Base.Vector(-x1, y1, 0)
    p[2] = Base.Vector(x1, y1, 0)
    p[4] = Base.Vector(x2, y2, 0)
    p[6] = Base.Vector(x2, -y2, 0)
    p[8] = Base.Vector(x1, -y1, 0)
    p[10] = Base.Vector(-x1, -y1, 0)
    p[12] = Base.Vector(-x2, -y2, 0)
    p[14] = Base.Vector(-x2, y2, 0)
    p[16] = Base.Vector(-x1, y1, 0)

    p[1] = dc.model.sagpoint_by_r(p[0], p[2], -2500)
    p[3] = dc.model.sagpoint_by_r(p[2], p[4], s2)
    p[5] = dc.model.sagpoint(p[4], p[6], s3)
    p[7] = dc.model.sagpoint_by_r(p[6], p[8], s2)
    p[9] = dc.model.sagpoint_by_r(p[8], p[10], -2500)
    p[11] = dc.model.sagpoint_by_r(p[10], p[12], s2)
    p[13] = dc.model.sagpoint(p[12], p[14], s3)
    p[15] = dc.model.sagpoint_by_r(p[14], p[0], s2)

    face = Part.Face(Part.Wire(dc.model.create_arcs(p)))
    m = face.extrude(Base.Vector(0, 0, d["tabletop_t"]))
    m = dc.model.fillet_edges_by_length(m, 20, d["tabletop_t"])

    hx = d["length"] / 2.0 - math.sqrt((d["cx"]**2) / 2.0)
    hy = d["width"] / 2.0 - math.sqrt((d["cx"]**2) / 2.0)

    print("Holes: x distance", hx * 2)
    print("Holes: y distance", hy * 2)
    print("Holes: diagonal distance", math.sqrt((hx * 2)**2 + (hy * 2)**2))

    hole_points = [
        Base.Vector(hx, hy, 0),
        Base.Vector(-hx, hy, 0),
        Base.Vector(-hx, -hy, 0),
        Base.Vector(hx, -hy, 0)
    ]

    a = 45
    for p in hole_points:
        hole = Part.makeCylinder(d["hole_dia_tabletop"] / 2.0, d["tabletop_t"],
                                 p, Base.Vector(0, 0, 1), 360)
        insert = Part.makeBox(d["leg_t"], d["insertion_width"],
                              d["insertion_length"])
        insert = dc.model.fillet_edges_by_length(insert, 5,
                                                 d["insertion_length"])
        insert.translate(
            Base.Vector(-d["leg_t"] / 2.0, -d["insertion_width"] / 2.0, 0))
        insert.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), -a)
        insert.translate(p)
        m = m.cut(hole).cut(insert)
        a = a + 90

    if dressup:
        m = dc.model.fillet_edges_longer_than(m, 7, 300)

    m.translate(Base.Vector(0, 0, -d["tabletop_t"]))
    return m
#TORRE DE HANOI - Felipe Miranda

from FreeCAD import Part
from FreeCAD import Base

#a base da torre
base = Part.makeBox(380, 150,20)

#os cilindros onde de encaixam os discos
cilindro1 = Part.makeCylinder(10,150)
cilindro1.translate(Base.Vector(70, 75))

cilindro2 = Part.makeCylinder(10,150)
cilindro2.translate(Base.Vector(190, 75))

cilindro3 = Part.makeCylinder(10,150)
cilindro3.translate(Base.Vector(310, 75))

#modelos dos discos para furá-lo
modeldisco1 = Part.makeCylinder(50, 20)
furo1 = Part.makeCylinder(10, 20)

modeldisco2 = Part.makeCylinder(45, 20)
furo2 = Part.makeCylinder(10, 20)

modeldisco3 = Part.makeCylinder(40, 20)
furo3 = Part.makeCylinder(10, 20)

modeldisco4 = Part.makeCylinder(35, 20)
furo4 = Part.makeCylinder(10, 20)