Ejemplo n.º 1
0
 def dice(edge=15, fn=32):
     """ dice
     """
     edge = float(edge)
     # dice
     c = ops.Cube(edge, center=True)
     s = ops.Sphere(edge * 3 / 4, center=True)
     dice = c & s
     # points
     c = ops.Circle(edge / 12, _fn=fn)
     h = 0.7
     point = c.linear_extrude(height=h)
     point1 = point.translate([0, 0, edge / 2 - h / 2])
     point2_1 = point1.rotate(a=90,
                              v=[1, 0,
                                 0]).translate([edge / 6, 0, edge / 6])
     point2_2 = point2_1.mirror([-edge / 6, 0, -edge / 6])
     point2 = point2_1 + point2_2
     point3 = point2.rotate(a=90, v=[0, 0, 1]) + point1.rotate(a=90,
                                                               v=[0, 1, 0])
     point4_12 = point2.rotate(a=-90, v=[0, 0, 1])
     point4 = point4_12 + point4_12.mirror([0, 1, 0])
     point5_123 = point3.rotate(a=90, v=[0, 0, 1])
     point5 = point5_123 + point5_123.mirror([1, 0, 0])
     point6_1 = point.translate([0, 0, -(edge / 2 + h / 2)
                                 ]).translate([0, edge / 6, 0])
     point6_2 = point6_1.translate([edge / 4, 0, 0])
     point6_3 = point6_1.translate([-edge / 4, 0, 0])
     point6_123 = point6_1 + point6_2 + point6_3
     point6_456 = point6_123.mirror([0, 1, 0])
     point6 = point6_123 + point6_456
     dice_with_holes = dice - point1 - point2 - point3 - point4 - point5 - point6
     dice_with_holes = dice_with_holes.mirror([0, 0, 1])
     return (dice_with_holes)
def create_plan(data, outname, wall_height=9, ratio=0.05):
    union = ops.Union()
    for coords in data["walls"]:
        z = 0
        x = coords[0][0]
        y = coords[0][1]
        w = coords[1][0] - x
        h = coords[2][1] - y

        offsety = -y * ratio - h * ratio

        c = ops.Cube([w * ratio, h * ratio,
                      wall_height]).translate([x * ratio, offsety, z])
        union.append(c)

    diff = ops.Difference()
    diff.append(union)

    for coords in data["doors"]:
        z = 0
        x = coords[0][0]
        y = coords[0][1]
        w = coords[1][0] - x
        h = coords[2][1] - y

        offsety = -y * ratio - h * ratio

        c = ops.Cube([w * ratio, h * ratio,
                      wall_height * 0.75]).translate([x * ratio, offsety, z])
        diff.append(c)

    for coords in data["windows"]:
        z = wall_height * 0.5
        x = coords[0][0]
        y = coords[0][1]
        w = coords[1][0] - x
        h = coords[2][1] - y

        offsety = -y * ratio - h * ratio

        c = ops.Cube([w * ratio, h * ratio,
                      wall_height * 0.33]).translate([x * ratio, offsety, z])
        diff.append(c)

    scadfile = "out.scad"
    diff.write(scadfile)
    call([openscad_path, "-o", outname, scadfile])
Ejemplo n.º 3
0
    def _get_connector(self, maincube, position, type):
        '''
        Add a connector of the given type to the cube
        '''

        middle_of_cube = self.x / 2

        connector_length = 5
        connector_shape = ops.Cube([5, connector_length, self.height
                                    ])  # Start out with a small cube

        slopped_part = ops.Cylinder(h=connector_length, r1=20, r2=20,
                                    _fn=3)  # Add a slopped part
        slopped_part = slopped_part.rotate([0, 90, 270])
        slopped_part = slopped_part.translate([
            connector_length / 2, 0, (self.height / 2)
        ])  # todo: not sure if x is correct but it seems to work

        connector_shape = connector_shape + slopped_part  # add connector and slope together

        connector_shape = connector_shape.rotate([180, 0,
                                                  0])  # rotate the whole thing
        connector_shape = connector_shape.translate(
            [0, connector_length, self.height])

        if type == 0:
            # todo: scale negative slightly bigger

            if position == 'top':
                connector_shape = connector_shape.rotate(
                    [0, 0, 180])  # rotate the shape around

                connector_shape = connector_shape.translate(
                    [middle_of_cube, self.y, 0])
                maincube = maincube - connector_shape

            # elif position == 'bottom':
            #     #todo: does not work with the current thickness of the lower part of the cube
            #     connector_shape = connector_shape.rotate([0,0,180])
            #     connector_shape = connector_shape.translate([middle_of_cube, -1, 0])
            #     maincube = maincube - connector_shape

        elif type == 1:

            # if position == 'top':
            #     connector_shape = connector_shape.translate([middle_of_cube, self.y, 0])
            #     maincube = maincube + connector_shape

            if position == 'bottom':
                connector_shape = connector_shape.rotate(
                    [0, 0, 180])  # Rotate the shape around

                # place the shape in the middle of the cube.
                # because it is rotated it also needs to be repositioned on the Z axis
                connector_shape = connector_shape.translate(
                    [middle_of_cube, 0, 0])
                maincube = maincube + connector_shape

        return maincube
def cutCurvature(shape, length, outerDiameter, curvatureRadius,
                 startOrientation):
    curvatureShape = (ops.Cube([outerDiameter+1, outerDiameter+1, length/2+1], center=True).translate([0,0, length/2 - curvatureRadius + math.sqrt(curvatureRadius**2-(length/2)**2)]) - \
        ops.Cylinder(h=length+3, r=curvatureRadius, center=True, _fn=300).rotate(v=[0,1,0], a=90).translate([0,0,length/2 - curvatureRadius]))
    if not startOrientation == 0:
        curvatureShape = curvatureShape.rotate(
            a=math.degrees(startOrientation), v=[0, 0, 1])
    return shape - curvatureShape
Ejemplo n.º 5
0
    def getcube(self):

        maincube = ops.Cube([self.x, self.y, self.height])
        if self.debug is True:
            maincube.transparent()

        previous_x = 0

        for radius in self.drill_holes:
            x = previous_x + (radius * 2)
            y = radius + self.spacing
            z = self.z_clearance

            previous_x = x  # Add the new x to previous

            print(f"Adding a cylinder at {x}, {y}, {z}")
            cyl = ops.Cylinder(h=self.height - self.z_clearance,
                               r=radius).translate([x, y, z])

            maincube = maincube - cyl

        # Add text, if available
        if self.text:
            maincube = maincube + self._add_text(maincube)

        if self.top_connector == 0:
            # needs to be taken out of the cube

            maincube = self._get_connector(maincube=maincube,
                                           position='top',
                                           type=0)

        elif self.top_connector == 1:
            print("Positive top connector is not supported")
            # # needs to be added next to the cube
            # maincube = self._get_connector(
            #     maincube=maincube,
            #     position='top',
            #     type=1)

        if self.bottom_connector == 0:
            print("Negative bottom connector is not supported")
            # # needs to be taken out of the cube
            #
            # maincube = self._get_connector(
            #     maincube=maincube,
            #     position='bottom',
            #     type=0)

        elif self.bottom_connector == 1:
            # needs to be added next to the cube
            maincube = self._get_connector(maincube=maincube,
                                           position='bottom',
                                           type=1)

        # todo: add connecting points
        return maincube
Ejemplo n.º 6
0
cell_w = 0.059*2. #m , (2.25")
cell_l = 0.0571 #m , (2.0")
cell_h = 0.00635 #m , (0.25")

# Render in OpenSCAD using the OpenPySCAD library
import openpyscad as ops

cell = ops.Cube([cell_w, cell_l, cell_h]).color("yellow") # Amprius Cell
heater = ops.Cylinder(h=0.11, r=0.003,  _fn=100).color("orange")
heater2 = ops.Cube([cell_w-0.002, cell_l-0.002, cell_h/5]).color("orange") # Amprius Cell

sim = ops.Union()
# module = ops.Union()
d = ops.Difference()

sim.append(heater.rotate([0, 90, 0]).translate([0.005,0.014,0.003]))
sim.append(heater.rotate([0, 90, 0]).translate([0.005,0.028,0.003]))
sim.append(heater.rotate([0, 90, 0]).translate([0.005,0.042,0.003]))
sim.append(cell.translate([0, 0, 0])) # simulator cell
sim.append(heater2.translate([0.001,cell_l*1.1+0.001,0.003]))
sim.append(cell.translate([0, cell_l*1.1, 0])) # sensor cell
    


(sim).write("sim_sens.scad")

Ejemplo n.º 7
0
def cube(x, y, z):
    (x, y, z) = (float(x), float(y), float(z))
    (tx, ty, tz) = (-(x / 2.0), -(y / 2.0), -(z / 2.0))
    return ops.Cube([x, y, z]).translate([tx, ty, tz])
Ejemplo n.º 8
0
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 27 12:00:00 2019

@author: prateekspawar
"""

import openpyscad as ops
l = 10
b = 20
h = 40
c1 = ops.Cube([l, h, b]).translate([-l / 2, -h / 2,
                                    -b / 2]).translate([10, 10, -10])

(c1).write("sample.scad")
Ejemplo n.º 9
0
        #        print("i is:",i,"j is:",j)
        if (i != j and cuboid[i] == cuboid[j]):
            cuboid.pop(j)
            #            print(j,"is popped")
            j = j - 1

        j = j + 1
    i = i + 1
    j = 0
print(cuboid)

print("front circles", circlef)
print("Top circles", circlet)
print("Side circles", circles)

ct = ops.Cube([0, 0, 0])
for i in range(0, len(cuboid)):

    l = cuboid[i][0]
    b = cuboid[i][1]
    h = cuboid[i][2]
    cgx = cuboid[i][3]
    cgy = cuboid[i][4]
    cgz = cuboid[i][5]
    c1 = ops.Cube([l, h, b]).translate([-l / 2, -h / 2,
                                        -b / 2]).translate([cgx, cgz, -cgy])
    if (cuboid[i][9] == 'a'):
        ct = ct + c1
    if (cuboid[i][9] == 'd'):
        ct = ct - c1
ct.write("circle1.scad")
Ejemplo n.º 10
0
 def build_shape(self):
     shape = []
     for t, offset in enumerate(self.time_steps):
         shape.append(ops.Cube(self.rects[t]).translate([offset, 0, 0]))
     return shape
Ejemplo n.º 11
0
                              _fn=100).translate([
                                  displacementFromAxis * math.cos(orientation),
                                  displacementFromAxis * math.sin(orientation),
                                  0
                              ])
    return shape


def ringBase(length, outerDiameter, curvatureRadius, cableGuideDiameter,
             cableGuideDisplacementFromAxis):
    s = ops.Cylinder(h=length, d=outerDiameter, center=True, _fn=300)
    s = cutCurvature(s, length, outerDiameter, curvatureRadius, math.pi / 4)

    s = cutHolesRevolute(s, length + 1, cableGuideDiameter,
                         cableGuideDisplacementFromAxis, 0, 8)
    return s


def main():
    s = ringBase(5, 5, 4, 1, 1.8)
    s.write(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "sample.scad"))


if __name__ == "__main__":
    main()

c1 = ops.Cube([10, 50, 10])
c2 = ops.Cube([20, 10, 10])
Ejemplo n.º 12
0
from PIL import Image
import numpy as np
import openpyscad as ops

c1 = ops.Cube([10, 10, 10])
c2 = ops.Cube([10, 10, 10]).translate([10, 10, 0])
(c1 + c2).write("sample.scad")


def load_image():
    img = Image.open("qr.PNG")
    img.load()
    data = np.array(img, dtype="int32")
    return data


ok = load_image()
print(ok[0].size / 4)
print(ok[0, 0, 0])
nul = np.array([0, 0, 0, 255])
print(nul)
for i in range(int(ok[0].size / 4)):
    for j in range(int(ok.size / ok[0].size / 4)):
        if (ok[i, j, 0] + ok[i, j, 1] + ok[i, j, 2] < 30):
            a = 1
Ejemplo n.º 13
0
plate_width = 40.6
bottom_screw_separation = 51
bottom_screw_pitch = 12
plate_thickness = 8.9
hole_pitch = 30
hole_diameter = 3.6
epsilon = 0.01
tail_width = 6.5
wall_thickness = 1.8

hole_edge_spacing = 2.0
adapter_width = plate_width + 2 * wall_thickness + 2 * tail_width
adapter_height = plate_width + wall_thickness
adapter_depth = bottom_screw_pitch + 5

adapter = ops.Cube([adapter_width, adapter_depth, adapter_height])
tail_cutout = ops.Cube([
    tail_width + epsilon, adapter_depth + epsilon,
    adapter_height - wall_thickness + epsilon
])
tail_cutout = tail_cutout.translate([-epsilon, -epsilon / 2, wall_thickness])

tail_cutout2 = ops.Cube([
    tail_width + epsilon, adapter_depth + epsilon,
    adapter_height - wall_thickness + epsilon
])
tail_cutout2 = tail_cutout2.translate(
    [epsilon + adapter_width - tail_width, -epsilon / 2, wall_thickness])

center_cutout = ops.Cube([
    plate_width, adapter_depth + epsilon,
Ejemplo n.º 14
0
        l = abs((xdifff[0] + xdifft[0]) / 2)
        b = abs(ydifff[0] + ydiffs[0]) / 2
        h = abs(ydifft[0] + xdiffs[0]) / 2
        print("Cuboid", "l=", l, "b=", b, "h=", h)
        vertexa = []
        for i in range(0, len(vertexf)):
            vertexa.append(vertexf[i][:])
            vertexa.append(vertexf[i][:])
#        print(vertexa)
#        print(vertexf)
        i = 0
        while (i < len(vertexf)):
            vertexa[i * 2].append(vertexs[2][0])
            vertexa[i * 2 + 1].append(vertexs[0][0])
            i = i + 1
        print(vertexa)
        cgx = vertexa[0][0] + l / 2
        cgy = vertexa[0][1] - b / 2
        cgz = vertexa[0][2] - h / 2
        print("cgx=", cgx, "cgy=", cgy, "cgz=", cgz)
        c1 = ops.Cube([l, b, h])
        c1.translate([cgx, cgy, cgz])
        (c1).write("cube1.scad")

#
#cv2.imshow('front',threshf)
#cv2.imshow('top',thresht)
#cv2.imshow('side',threshs)
cv2.waitKey(0)
cv2.destroyAllWindows()
Ejemplo n.º 15
0
t_PCM = float(case.get_val('t_PCM', units='mm'))
cell_w = float(case.get_val('cell_w'))
cell_l = float(case.get_val('cell_l'))
cell_h = float(case.get_val('cell_h'))
s_w = float(case.get_val('cell_s_w'))
s_h = float(case.get_val('cell_s_h'))
n_cpbl = int(np.ceil(case.get_val('n_cpb'))/2.)
n_bps = int(np.ceil(case.get_val('n_bps')))


s_h = 1.1 # horizontal spacing
s_v = 1.3 # vertical spacing
s_h2 = ((s_h-1)/2 +1)
n_stacks_show = 1

cell = ops.Cube([cell_w, cell_l, cell_h]) # Amprius Cell
pcm = ops.Cube([cell_w, cell_l, t_PCM]).color("Orange") # Phase Change Material
ohp = ops.Cube([cell_w, cell_l*n_cpb*s_h, cell_h]).color("Gray") # Oscillating Heat Pipe Straight-away
# ohp_turn = ops.Cylinder(h=cell_h, r=cell_w*s_h2, _fn=100).color("Gray") # OHP End Turn
# ohp_turn_d = ops.Cube([cell_w*2*s_h,cell_w*s_h,cell_h+0.02]) # Make it a semi-circl
#pack = ops.Union()
bar = ops.Union()
# d = ops.Difference()
# d2 = ops.Difference()
# insulation = ops.Cube([cell_w*2,cell_l*s_h*n_cpb*1.1,cell_h*s_v]).color("Blue")

stack_h = cell_h*2 + t_PCM*2

for b in range(n_cpbl):
    # Cell Array
    bar.append(cell.translate([0, cell_l*s_h*b, 0])) # first row cell