Exemple #1
0
    def apply_single_gaussian_dispersion(self, normal, sigma_1):
        """
        Apply a single gaussian dispersion to the optical state

        Parameters
        ----------
        normal : Base.Vector
            normal vector of the surface at the point of incidence
        sigma_1 : float
            dispersion coefficient
         """
        # TODO: @Ramon: Review
        rad = np.pi / 180.0
        u = myrandom()
        theta = (-2. * sigma_1**2. * np.log(u))**0.5 / 1000.0 / rad
        v = self.direction
        axis_1 = normal.cross(self.direction)
        rotation_1 = Base.Rotation(axis_1, 2 * theta)
        new_v1 = rotation_1.multVec(v)
        u = myrandom()
        phi = 360. * u
        axis_2 = v
        rotation_2 = Base.Rotation(axis_2, phi)
        new_v2 = rotation_2.multVec(new_v1)
        polarization_vector = self.polarization
        new_pol_1 = rotation_1.multVec(polarization_vector)
        new_polarization_vector = rotation_2.multVec(new_pol_1)
        self.polarization = new_polarization_vector
        self.direction = new_v2
Exemple #2
0
def generate_eccentric_key_part(part,parameters):    
    eccentricity = parameters["eccentricity"]
    base_height = parameters["base_height"]
    clearance = parameters["clearance"]
    shaft_diameter = parameters["shaft_diameter"]
    disk_height = parameters["disk_height"]
    driver_disk_height = parameters["disk_height"]
    
    sketch = newSketch(part,'key1')
    SketchCircle(sketch,-eccentricity,0,shaft_diameter,-1,"Key1")    
    newPad(part,sketch,disk_height,'keyPad')
    
    sketch = newSketch(part,'key2')
    sketch.AttachmentOffset = Base.Placement(Base.Vector(0,0,disk_height),Base.Rotation(Base.Vector(0,0,1),0))     
    SketchCircle(sketch,eccentricity,0,shaft_diameter,-1,"Key1")    
    newPad(part,sketch,disk_height,'keyPad')
    
    pin_dia = eccentricity
    
    innershaftDia = (shaft_diameter  + eccentricity)  #(13+2) = 15
    innershaftRadius = innershaftDia /2 
    pinsketch1 = newSketch(part,'Pin1')
    pinsketch1.AttachmentOffset = Base.Placement(Base.Vector(0,0,base_height-driver_disk_height),Base.Rotation(Base.Vector(0,0,1),0))     
    SketchCircle(pinsketch1,-(innershaftRadius-pin_dia)/2,0,pin_dia,-1,"pin1")
    pock1 = newPocket(part,pinsketch1,driver_disk_height+disk_height,'Pin1');
    pock1.Reversed = False

    pinsketch2 = newSketch(part,'Pin2')
    pinsketch2.AttachmentOffset = Base.Placement(Base.Vector(0,0,base_height-driver_disk_height),Base.Rotation(Base.Vector(0,0,1),0))     
    SketchCircle(pinsketch2,-(innershaftRadius-(pin_dia/2*3)),0,pin_dia,-1,"pin2")
    pock2 = newPocket(part,pinsketch2,driver_disk_height+disk_height,'Pin2');
    pock2.Reversed = False
        
    part.Placement = Base.Placement(Base.Vector(0,0,base_height),Base.Rotation(Base.Vector(0,0,1),222))
Exemple #3
0
def axial_rotation_from_axis_and_angle(axis_origin, axis_dir, angle):
    """
    Returns a rotation with given axis and angle
    """
    z_axis = Base.Vector(0, 0, 1)
    local_cs = Base.Placement(axis_origin, Base.Rotation(z_axis, axis_dir))
    return local_cs.multiply(
        Base.Placement(Base.Vector(),
                       Base.Rotation(angle * 180.0 / pi, 0,
                                     0)).multiply(local_cs.inverse()))
Exemple #4
0
    def Activated(self):
        # do something here...
        def makePlane(plc):
            import FreeCAD, FreeCADGui
            from FreeCAD import Base
            import Part, PartGui
            FreeCAD.ActiveDocument.addObject("Part::Plane", "RefPlane")
            plane = FreeCAD.ActiveDocument.ActiveObject
            plane.Length = 10.000
            plane.Width = 10.000
            l = float(plane.Length)
            w = float(plane.Width)
            px = float(plc.Base.x)
            py = float(plc.Base.y)
            x = px - l / 2.0
            y = py - w / 2.0
            plane.Placement = Base.Placement(
                Base.Vector(x, y, 0.000),
                Base.Rotation(0.000, 0.000, 0.000, 1.000))
            FreeCADGui.ActiveDocument.getObject(plane.Name).Transparency = 60
            FreeCADGui.ActiveDocument.getObject(plane.Name).LineColor = (1.000,
                                                                         0.667,
                                                                         0.498)
            return plane

        sel = FreeCADGui.Selection.getSelection()
        if len(sel) == 1:
            if 'App::Part' in sel[0].TypeId or 'PartDesign::Body' in sel[0].TypeId \
                    or 'Part::FeaturePython' in sel[0].TypeId:
                from FreeCAD import Base
                try:
                    plc = FreeCAD.Placement(
                        Base.Vector(0.0, 0.0, 0.000),
                        Base.Rotation(0.000, 0.000, 0.000, 1.000))
                    plane = makePlane(plc)
                    sel[0].addObject(FreeCAD.ActiveDocument.ActiveObject)
                except:
                    plane.Placement = sel[0].Placement.multiply(
                        plane.Placement)
                    print(plane.Label, 'exception')
                #    FreeCAD.ActiveDocument.addObject('PartDesign::Plane','DatumPlane')
            else:
                plc = FreeCAD.Placement(
                    Base.Vector(0.0, 0.0, 0.000),
                    Base.Rotation(0.000, 0.000, 0.000, 1.000))
                makePlane(plc)
        else:
            from FreeCAD import Base
            plc = FreeCAD.Placement(Base.Vector(0.0, 0.0, 0.000),
                                    Base.Rotation(0.000, 0.000, 0.000, 1.000))
            makePlane(plc)
        FreeCAD.ActiveDocument.recompute()
Exemple #5
0
def set_Excitation(qwm_doc):
    QW_Modeller.addQWObject("QW_Modeller::TemplatePort", "inp")
    qwm_doc.inp.Length = 20.0
    qwm_doc.inp.Width = 10.0
    qwm_doc.inp.Placement = Base.Placement(Base.Vector(0.0, 0.0, 5.0),
                                           Base.Rotation(0.5, 0.5, 0.5, 0.5))
    qwm_doc.inp.Orientation = "X"
    qwm_doc.inp.Position = 0.0
    qwm_doc.inp.Activity = "PLUS"
    qwm_doc.inp.Type = "Source"
    qwm_doc.inp.SymmetryH = False
    qwm_doc.inp.SymmetryV = False
    qwm_doc.inp.PointCoordX = 0.0
    qwm_doc.inp.PointCoordY = 0.0
    qwm_doc.inp.PointCoordZ = 5.0
    qwm_doc.inp.effectivePermitivityMode = "AUTO"
    qwm_doc.inp.Excitation = QW_Modeller.TemplateExcitation(
        QW_Modeller.DriveFunction(QW_Modeller.Waveform('delta'), 1, 0, 1, 0),
        'TEM', 'Ex', 1,
        QW_Modeller.TemplateGenerationConf('Automatic', (10, 0.2),
                                           (9, 11, 0.01), 1, 50, 1, 0))
    qwm_doc.inp.MultiPointExcitation = QW_Modeller.MultiPointPortExcitation(
        0, "0.1")
    qwm_doc.inp.Postprocessing = QW_Modeller.PortPostprocessing(0, 0, 1)
    qwm_doc.inp.ReferenceOffset = abs(qwm_doc.inp.PointCoordX - 10.0)
    QW_Modeller.addQWObject("QW_Modeller::TemplatePort", "out")
    qwm_doc.out.Length = 20.0
    qwm_doc.out.Width = 10.0
    qwm_doc.out.Placement = Base.Placement(Base.Vector(60.0, 0.0, 5.0),
                                           Base.Rotation(0.5, 0.5, 0.5, 0.5))
    qwm_doc.out.Orientation = "X"
    qwm_doc.out.Position = 60.0
    qwm_doc.out.Activity = "MINUS"
    qwm_doc.out.Type = "Load"
    qwm_doc.out.SymmetryH = False
    qwm_doc.out.SymmetryV = False
    qwm_doc.out.PointCoordX = 60.0
    qwm_doc.out.PointCoordY = 0.0
    qwm_doc.out.PointCoordZ = 5.0
    qwm_doc.out.effectivePermitivityMode = "AUTO"
    qwm_doc.out.Excitation = QW_Modeller.TemplateExcitation(
        QW_Modeller.DriveFunction(QW_Modeller.Waveform('delta'), 1, 0, 1, 0),
        'TEM', 'Ex', 1,
        QW_Modeller.TemplateGenerationConf('Automatic', (10, 0.2),
                                           (9, 11, 0.01), 1, 50, 1, 0))
    qwm_doc.out.MultiPointExcitation = QW_Modeller.MultiPointPortExcitation(
        0, "0.1")
    qwm_doc.out.Postprocessing = QW_Modeller.PortPostprocessing(0, 0, 1)
    qwm_doc.out.ReferenceOffset = abs(qwm_doc.out.PointCoordX - 50.0)
Exemple #6
0
def dispersion_polarization(main_direction, polarization_vector, theta, phi):
    """
    Computes dispersion of polarization vector in terms of angles theta and phi
    """
    v = main_direction
    v_p = Base.Vector(v[1], -v[0], 0)
    if v_p == Base.Vector(0, 0, 0):
        # to avoid null vector at mynormal and incident parallel vectors
        v_p = Base.Vector(1, 0, 0)
    v_p.normalize()
    rotation_1 = Base.Rotation(v_p, theta)
    new_v1 = rotation_1.multVec(polarization_vector)
    axis_2 = main_direction
    rotation_2 = Base.Rotation(axis_2, phi)
    new_v2 = rotation_2.multVec(new_v1)
    return new_v2
Exemple #7
0
def generate_output_shaft_part(part,parameters):    
    sketch = newSketch(part,'OutputShaftBase') 
    min_radius,max_radius= calculate_min_max_radii(parameters)
    driver_disk_hole_count = parameters["driver_disk_hole_count"]
    eccentricity = parameters["eccentricity"]
    pin_disk_pin_diameter = parameters["pin_disk_pin_diameter"]
    shaft_diameter = parameters["shaft_diameter"]
    clearance = parameters["clearance"]
    base_height = parameters["base_height"]
    disk_height = parameters["disk_height"]
    driver_disk_diameter = parameters["driver_disk_diameter"]
    if driver_disk_diameter>min_radius*2-pin_disk_pin_diameter/2:
        print("driver diameter too big, resizing")
        driver_disk_diameter = min_radius*2-pin_disk_pin_diameter/2
        parameters["driver_disk_diameter"] = driver_disk_diameter

    SketchCircle(sketch,0,0,driver_disk_diameter,-1,"Base") #outer circle    
    pad = newPad(part,sketch,disk_height)
    sketchh = newSketch(part,'holes')
    driver_hole_diameter = (parameters["driver_hole_diameter"]+clearance)
    last = -1        
    DriveHoleRRadius = calc_DriveHoleRRadius(driver_disk_diameter,shaft_diameter);
    
    SketchCircle(sketchh,DriveHoleRRadius,0,driver_hole_diameter,-1,"DriverHoles")
    pocket = newPocket(part,sketchh,disk_height)
    pol = newPolar(part,pocket,sketchh,driver_disk_hole_count,"DriverHole")
    pol.Originals = [pocket]
    pocket.Visibility = False
    pol.Visibility = True
    
    keysketch = newSketch(part,'InputKey')
    generate_key_sketch(parameters,0,keysketch)
    pad = newPad(part,keysketch,20)
    part.Placement = Base.Placement(Base.Vector(0,0,base_height+disk_height*2),Base.Rotation(Base.Vector(0,0,1),0))
    part.Tip = pol
Exemple #8
0
def generate_driver_disk_part(part,parameters):
    sketch = newSketch(part,'DriverDiskBase')            
    min_radius,max_radius= calculate_min_max_radii(parameters)
    driver_disk_hole_count = parameters["driver_disk_hole_count"]
    pin_disk_pin_diameter = parameters["pin_disk_pin_diameter"]
    eccentricity = parameters["eccentricity"]
    shaft_diameter = parameters["shaft_diameter"]
    base_height = parameters["base_height"]
    clearance = parameters["clearance"]
    disk_height = parameters["disk_height"]
    driver_disk_diameter = parameters["driver_disk_diameter"]
    
    if driver_disk_diameter>min_radius-pin_disk_pin_diameter/2:
        print("driver diameter too big, resizing")
        driver_disk_diameter = min_radius*2-pin_disk_pin_diameter/2
        parameters["driver_disk_diameter"] = driver_disk_diameter
    driver_disk_diameter -= clearance
    SketchCircle(sketch,0,0,driver_disk_diameter,-1,"")    
    innershaftDia = (shaft_diameter  + eccentricity+clearance/2) 
    SketchCircle(sketch,0,0,innershaftDia,-1,"ShaftHole")
    pad = newPad(part,sketch,disk_height)
    driver_hole_diameter = parameters["driver_hole_diameter"]
    last = -1   
    DriveHoleRRadius = calc_DriveHoleRRadius(driver_disk_diameter,shaft_diameter);
    
    sketch1 = newSketch(part,'DriverShaft')
    SketchCircle(sketch1,DriveHoleRRadius,0,driver_hole_diameter,-1,"DriverShaft")    
    pad = newPad(part,sketch1,disk_height*4)    
    
    part.Placement = Base.Placement(Base.Vector(0,0,base_height - disk_height),Base.Rotation(Base.Vector(0,0,1),0))
    pol = newPolar(part,pad,sketch1,driver_disk_hole_count,'DriverDisk')
    pol.Originals = [pad]
    pad.Visibility = False
    pol.Visibility = True
    part.Tip = pol
Exemple #9
0
def make_cylinder(name, radius, height, base_vector, base_rotation):
    ac_doc = FreeCAD.ActiveDocument
    ac_doc.addObject("Part::Cylinder", name)
    getattr(ac_doc, name).Radius = radius
    getattr(ac_doc, name).Height = height
    getattr(ac_doc, name).Placement = Base.Placement(
        Base.Vector(base_vector[0], base_vector[1], base_vector[2]),
        Base.Rotation(base_rotation[0], base_rotation[1], base_rotation[2],
                      base_rotation[3]))
Exemple #10
0
def make_box(name, length, width, height, base_vector, base_rotation):
    ac_doc = FreeCAD.ActiveDocument
    ac_doc.addObject("Part::Box", name)
    getattr(ac_doc, name).Length = length
    getattr(ac_doc, name).Width = width
    getattr(ac_doc, name).Height = height
    getattr(ac_doc, name).Placement = Base.Placement(Base.Vector(base_vector[0], base_vector[1], base_vector[2]),
                                                     Base.Rotation(base_rotation[0], base_rotation[1], base_rotation[2],
                                                                   base_rotation[3]))
Exemple #11
0
def random_polarization(direction):
    """
    Returns a random polarization orthogonal to the given direction
    """
    orthogonal_vector = one_orthogonal_vector(direction)
    phi = 360.0 * myrandom()
    rotation = Base.Rotation(direction, phi)
    random_polarization_v = rotation.multVec(orthogonal_vector)
    return random_polarization_v
def set_Excitation(qwm_doc):
    QW_Modeller.addQWObject("QW_Modeller::TemplatePort","cwghinp1")
    qwm_doc.cwghinp1.Length = 100.0
    qwm_doc.cwghinp1.Width = 100.0
    qwm_doc.cwghinp1.Placement = Base.Placement(Base.Vector(0.0, 0.0, 0.0), Base.Rotation(0.0, 0.0, 0.0, 1.0))
    qwm_doc.cwghinp1.Orientation = "Z"
    qwm_doc.cwghinp1.Position = 0.0
    qwm_doc.cwghinp1.Activity = "PLUS"
    qwm_doc.cwghinp1.Type = "Source"
    qwm_doc.cwghinp1.SymmetryH = False
    qwm_doc.cwghinp1.SymmetryV = False
    qwm_doc.cwghinp1.PointCoordX = 0.0
    qwm_doc.cwghinp1.PointCoordY = 0.0
    qwm_doc.cwghinp1.PointCoordZ = 0.0
    qwm_doc.cwghinp1.effectivePermitivityMode = "AUTO"
    qwm_doc.cwghinp1.Excitation = QW_Modeller.TemplateExcitation(QW_Modeller.DriveFunction(QW_Modeller.Waveform('delta'),1,0,1,0),'TEM','Ex',1,QW_Modeller.TemplateGenerationConf('Automatic',(10,0.2),(9,11,0.01),1,50,1,0))
    qwm_doc.cwghinp1.MultiPointExcitation = QW_Modeller.MultiPointPortExcitation(0,"0.1")
    qwm_doc.cwghinp1.Postprocessing = QW_Modeller.PortPostprocessing(0,0,1)
    qwm_doc.cwghinp1.ReferenceOffset = abs(qwm_doc.cwghinp1.PointCoordZ - 30.0)
    QW_Modeller.addQWObject("QW_Modeller::TemplatePort","cwghout1")
    qwm_doc.cwghout1.Length = 100.0
    qwm_doc.cwghout1.Width = 100.0
    qwm_doc.cwghout1.Placement = Base.Placement(Base.Vector(0.0, 0.0, 300.0), Base.Rotation(0.0, 0.0, 0.0, 1.0))
    qwm_doc.cwghout1.Orientation = "Z"
    qwm_doc.cwghout1.Position = 300.0
    qwm_doc.cwghout1.Activity = "MINUS"
    qwm_doc.cwghout1.Type = "Load"
    qwm_doc.cwghout1.SymmetryH = False
    qwm_doc.cwghout1.SymmetryV = False
    qwm_doc.cwghout1.PointCoordX = 0.0
    qwm_doc.cwghout1.PointCoordY = 0.0
    qwm_doc.cwghout1.PointCoordZ = 300.0
    qwm_doc.cwghout1.effectivePermitivityMode = "AUTO"
    qwm_doc.cwghout1.Excitation = QW_Modeller.TemplateExcitation(QW_Modeller.DriveFunction(QW_Modeller.Waveform('delta'),1,0,1,0),'TEM','Ex',1,QW_Modeller.TemplateGenerationConf('Automatic',(10,0.2),(9,11,0.01),1,50,1,0))
    qwm_doc.cwghout1.MultiPointExcitation = QW_Modeller.MultiPointPortExcitation(0,"0.1")
    qwm_doc.cwghout1.Postprocessing = QW_Modeller.PortPostprocessing(0,0,1)
    qwm_doc.cwghout1.ReferenceOffset = abs(qwm_doc.cwghout1.PointCoordZ - 270.0)
Exemple #13
0
    def Prism(self):
        Angle = self.angle.text()
        Angle = int(Angle)
        App.activeDocument().addObject('PartDesign::Body', 'Body')
        App.ActiveDocument.recompute()

        App.ActiveDocument.addObject("Part::Box", "Box")
        App.ActiveDocument.Box.Length = 1000.00
        App.ActiveDocument.Box.Width = 1000.00
        App.ActiveDocument.Box.Height = 1000.00
        App.ActiveDocument.Box.Placement = Base.Placement(
            Base.Vector(0.00, 0.00, 0.00),
            Base.Rotation(0.00, 0.00, 0.00, 1.00))
        App.ActiveDocument.Box.Label = 'Box'
        App.ActiveDocument.Box.Placement = App.Placement(
            App.Vector(-500, -500, -500), App.Rotation(App.Vector(0, 0, 1), 0),
            App.Vector(0, 0, 0))
        App.ActiveDocument.recompute()

        App.ActiveDocument.addObject("Part::Box", "Box001")
        App.ActiveDocument.Box001.Length = 710.00
        App.ActiveDocument.Box001.Width = 1000.00
        App.ActiveDocument.Box001.Height = 1420.00
        App.ActiveDocument.Box001.Placement = Base.Placement(
            Base.Vector(0.00, 0.00, 0.00),
            Base.Rotation(0.00, 0.00, 0.00, 1.00))
        App.ActiveDocument.Box001.Label = 'Box'
        App.ActiveDocument.Box001.Placement = App.Placement(
            App.Vector(0, -500, -710), App.Rotation(App.Vector(0, 1, 0),
                                                    -Angle),
            App.Vector(0, 0, 710))
        App.ActiveDocument.recompute()

        App.activeDocument().addObject("Part::Cut", "Cut")
        App.activeDocument().Cut.Base = App.activeDocument().Box
        App.activeDocument().Cut.Tool = App.activeDocument().Box001
        App.ActiveDocument.recompute()
Exemple #14
0
    def apply_double_gaussian_dispersion(self, normal, sigma_1, sigma_2, k):
        """
        Apply a double gaussian dispersion to the state


        Parameters
        ----------
        normal : Base.Vector
            normal vector of the surface at the point of incidence
        sigma_1 : float
            dispersion coefficient (first case)
        sigma_2 : float
            dispersion coefficient (second case)
        k : float
            threshold for randomly applying first or second case
        """
        rad = np.pi / 180.0
        k_ran = myrandom()
        u = myrandom()
        if k_ran < k:
            theta = (-2. * sigma_1**2. * np.log(u))**0.5 / 1000.0 / rad
        else:
            theta = (-2. * sigma_2**2. * np.log(u))**0.5 / 1000.0 / rad
        v = self.direction
        axis_1 = normal.cross(self.direction)
        rotation_1 = Base.Rotation(axis_1, 2 * theta)
        new_v1 = rotation_1.multVec(v)
        u = myrandom()
        phi = 360. * u
        axis_2 = v
        rotation_2 = Base.Rotation(axis_2, phi)
        new_v2 = rotation_2.multVec(new_v1)
        polarization_vector = self.polarization
        new_pol_1 = rotation_1.multVec(polarization_vector)
        new_polarization_vector = rotation_2.multVec(new_pol_1)
        self.direction = new_v2
        self.polarization = new_polarization_vector
Exemple #15
0
def vir1():
    App.ActiveDocument.addObject("Part::Box", "Box")
    App.ActiveDocument.Box.Length = 62.00
    App.ActiveDocument.Box.Width = 7.00
    App.ActiveDocument.Box.Height = 5.6 - 4
    App.ActiveDocument.Box.Placement = Base.Placement(
        Base.Vector(0.00, 29.60, 0.00), Base.Rotation(0.00, 0.00, 0.00, 1.00))
    App.ActiveDocument.Box.Label = 'Vir1'
    App.activeDocument().addObject("Part::Cut", "Cut003")
    App.activeDocument().Cut003.Base = App.activeDocument().Cut002
    App.activeDocument().Cut003.Tool = App.activeDocument().Box
    Gui.activeDocument().Cut002.Visibility = False
    Gui.activeDocument().Box.Visibility = False
    Gui.ActiveDocument.Cut003.ShapeColor = Gui.ActiveDocument.Cut002.ShapeColor
    Gui.ActiveDocument.Cut003.DisplayMode = Gui.ActiveDocument.Cut002.DisplayMode
    App.ActiveDocument.recompute()
Exemple #16
0
def pole1():
    App.ActiveDocument.addObject("Part::Cylinder", "Cylinder")
    App.ActiveDocument.Cylinder.Radius = 0.80
    App.ActiveDocument.Cylinder.Height = 14.80
    App.ActiveDocument.Cylinder.Angle = 360.
    App.ActiveDocument.Cylinder.Placement = Base.Placement(
        Base.Vector(23.00, 32.00, 3.60), Base.Rotation(0.50, 0.50, 0.50, 0.50))
    App.ActiveDocument.Cylinder.Label = 'CYL1'
    App.activeDocument().addObject("Part::Cut", "Cut002")
    App.activeDocument().Cut002.Base = App.activeDocument().Cut001
    App.activeDocument().Cut002.Tool = App.activeDocument().Cylinder
    Gui.activeDocument().Cut001.Visibility = False
    Gui.activeDocument().Cylinder.Visibility = False
    Gui.ActiveDocument.Cut002.ShapeColor = Gui.ActiveDocument.Cut001.ShapeColor
    Gui.ActiveDocument.Cut002.DisplayMode = Gui.ActiveDocument.Cut001.DisplayMode
    App.ActiveDocument.recompute()
Exemple #17
0
    def testForaminatePlacement(self):
        pnt = Base.Vector(0.0, 0.0, 0.0)
        vec = Base.Vector(0.0, 1.0, 1.0)
        results = self.mesh.foraminate(pnt, vec)
        self.assertEqual(len(results), 4)

        # Apply placement to mesh
        plm = Base.Placement(Base.Vector(1,2,3), Base.Rotation(1,1,1,1))
        self.mesh.Placement = plm
        self.assertEqual(len(self.mesh.foraminate(pnt, vec)), 0)

        # Apply the placement on the ray as well
        pnt = plm.multVec(pnt)
        vec = plm.Rotation.multVec(vec)
        results2 = self.mesh.foraminate(pnt, vec)
        self.assertEqual(len(results2), 4)
        self.assertEqual(list(results.keys()), list(results2.keys()))
Exemple #18
0
 def makePlane(plc):
     import FreeCAD, FreeCADGui
     from FreeCAD import Base
     import Part,PartGui
     FreeCAD.ActiveDocument.addObject("Part::Plane","RefPlane")
     plane = FreeCAD.ActiveDocument.ActiveObject
     plane.Length=10.000
     plane.Width=10.000
     l=float(plane.Length)
     w=float(plane.Width)
     px=float(plc.Base.x)
     py=float(plc.Base.y)
     x=px-l/2.0
     y=py-w/2.0
     plane.Placement=Base.Placement(Base.Vector(x,y,0.000),Base.Rotation(0.000,0.000,0.000,1.000))
     FreeCADGui.ActiveDocument.getObject(plane.Name).Transparency = 60
     FreeCADGui.ActiveDocument.getObject(plane.Name).LineColor = (1.000,0.667,0.498)
     return plane
Exemple #19
0
def make_cylinder_slice(radius, height, start_angle, end_angle, angle,
                        output_filename):

    central_point = Base.Vector(0.00, 0.00, -0.5 * height)
    base_orientation = Base.Vector(0, 0.00, 1)

    cylinder_slice = Part.makeCylinder(radius, height, central_point,
                                       base_orientation, angle)
    cylinder_slice = Part.makeCompound([cylinder_slice])
    #cylinder_slice.exportStep(output_folder_stp+'cylinder_slice.stp')

    cylinder_slice.Placement = Base.Placement(
        Base.Vector(0.00, 0.00, 0.00),
        Base.Rotation(FreeCAD.Vector(0, 0, 1), start_angle))

    #'cylinder_slice_start_'+str(start_angle)+'_end_'+str(end_angle)+'_angle_'+str(angle)+'.stp'
    cylinder_slice.exportStep(output_filename)

    print('geometry saved to ' + str(output_filename))
Exemple #20
0
    def testFindNearest(self):
        self.assertEqual(len(self.mesh.nearestFacetOnRay((-2,2,-6),(0,0,1))), 0)
        self.assertEqual(len(self.mesh.nearestFacetOnRay((0.5,0.5,0.5),(0,0,1))), 1)
        self.assertEqual(len(self.mesh.nearestFacetOnRay((0.5,0.5,0.5),(0,0,1),-math.pi/2)), 0)
        self.assertEqual(len(self.mesh.nearestFacetOnRay((0.2,0.1,0.2),(0,0, 1))),
                         len(self.mesh.nearestFacetOnRay((0.2,0.1,0.2),(0,0,-1))))
        self.assertEqual(len(self.mesh.nearestFacetOnRay((0.2,0.1,0.2),(0,0, 1), math.pi/2)),
                         len(self.mesh.nearestFacetOnRay((0.2,0.1,0.2),(0,0,-1), math.pi/2)))
        # Apply placement to mesh
        plm = Base.Placement(Base.Vector(1,2,3), Base.Rotation(1,1,1,1))
        pnt = Base.Vector(0.5, 0.5, 0.5)
        vec = Base.Vector(0.0, 0.0, 1.0)

        self.mesh.Placement = plm
        self.assertEqual(len(self.mesh.nearestFacetOnRay(pnt,vec)), 0)

        # Apply the placement on the ray as well
        pnt = plm.multVec(pnt)
        vec = plm.Rotation.multVec(vec)
        self.assertEqual(len(self.mesh.nearestFacetOnRay(pnt,vec)), 1)
    def priSm(self):

        try:
            dbf = float(self.d1.text())
            nos = int(self.d2.text())
            hth = float(self.d3.text())
            aR = dbf / 2
            op1 = 180/float(nos)
            coS = cos(math.radians(op1))
            cR = aR / coS
            prism=App.ActiveDocument.addObject("Part::Prism","Prism")
            prism.Polygon=nos
            prism.Circumradius=cR
            prism.Height=hth
            prism.Placement=Base.Placement(Base.Vector(0.00,0.00,0.00),Base.Rotation(0.00,0.00,0.00,1.00))
            prism.Label='Prism'
            App.ActiveDocument.recompute()
            Gui.SendMsgToActiveView("ViewFit")
        except:
            FreeCAD.Console.PrintError("Unable to complete task")

            self.close()
Exemple #22
0
def generate_eccentric_shaft_part(body,parameters):
    eccentricity = parameters["eccentricity"] #default 2
    base_height = parameters["base_height"]
    shaft_diameter = parameters["shaft_diameter"] # default 13
    clearance = parameters["clearance"] #defualt .5
    disk_height = parameters["disk_height"]
    driver_disk_height = parameters["disk_height"]
    sketch1 = newSketch(body,'Shaft')
    
    SketchCircle(sketch1,0,0,shaft_diameter,-1,"Shaft")
    newPad(body,sketch1,base_height - driver_disk_height,'bearinghole');
        
    sketch2 = newSketch(body,'Shaft1')
    sketch2.AttachmentOffset = Base.Placement(Base.Vector(0,0,base_height-driver_disk_height),Base.Rotation(Base.Vector(0,0,1),0))     
    innershaftDia = (shaft_diameter  + eccentricity)  
    SketchCircle(sketch2,0,0,innershaftDia,-1,"InnerShaft")
    newPad(body,sketch2,driver_disk_height,'shaftabovebase');
    pin_dia = eccentricity
    innershaftRadius = innershaftDia /2 
    #key_radius = parameters["key_diameter"]/2
    #generate_key_sketch(parameters,clearance,sketch2,shaft_diameter-(key_radius+clearance))    
    pinsketch1 = newSketch(body,'Pin1')
    pinsketch1.AttachmentOffset = Base.Placement(Base.Vector(0,0,base_height-driver_disk_height),Base.Rotation(Base.Vector(0,0,1),0))     
    SketchCircle(pinsketch1,-(innershaftRadius-pin_dia)/2,0,pin_dia,-1,"pin1")
    newPad(body,pinsketch1,driver_disk_height+disk_height,'Pin1');
    
    pinsketch2 = newSketch(body,'Pin2')
    pinsketch2.AttachmentOffset = Base.Placement(Base.Vector(0,0,base_height-driver_disk_height),Base.Rotation(Base.Vector(0,0,1),0))     
    SketchCircle(pinsketch2,-(innershaftRadius-(pin_dia/2*3)),0,pin_dia,-1,"pin2")
    newPad(body,pinsketch2,driver_disk_height+disk_height,'Pin2');
    
    keysketch = newSketch(body,'InputKey')
    generate_key_sketch(parameters,0,keysketch)
    newPocket(body,keysketch,base_height+driver_disk_height,'InputKey')
    
    body.Placement = Base.Placement(Base.Vector(0,0,0),Base.Rotation(Base.Vector(0,0,1),222))
docname = re.sub('\.fcstd$', '', docname)
m = re.match('^(.*)/(.*?)$', docname)
if m:
    outdir = m.group(1)
    docname = m.group(2)

from FreeCAD import Base
import Part, Sketcher
import ProfileLib.RegularPolygon as Poly

doc = FreeCAD.newDocument(docname)

ske = doc.addObject('Sketcher::SketchObject', 'Sketch')
# FIXME: sketch is rendered invisible
# We need a DocumentViewProviderObject to set Visibility=True
ske.Placement = Base.Placement(Base.Vector(0, 0, 0), Base.Rotation(0, 0, 0, 1))
i = int(ske.GeometryCount)  # 0
geo = [
    Part.LineSegment(Base.Vector(4, 8, 0), Base.Vector(9, 8, 0)),
    Part.LineSegment(Base.Vector(9, 8, 0), Base.Vector(9, 2, 0)),
    Part.LineSegment(Base.Vector(9, 2, 0), Base.Vector(3, 2, 0)),
    Part.LineSegment(Base.Vector(3, 2, 0), Base.Vector(3, 7, 0)),
    Part.Circle(Center=Base.Vector(6, 5, 0),
                Normal=Base.Vector(0, 0, 1),
                Radius=2),
    # North: math.pi/2
    # SouthEast: -math.pi/4
    # West: math.pi, -math.pi
    # East: 0
    #Part.ArcOfCircle(Part.Circle(Base.Vector(4,7,0), Base.Vector(0,0,1), 1), math.pi/2, -math.pi)
    #
Exemple #24
0
def simple_polarization_refraction(incident, normal, normal_parallel_plane, c2,
                                   polarization_vector):
    c1 = -normal.dot(incident)
    angle = rad_to_deg(arccos(c2.real) - arccos(c1))
    rotation = Base.Rotation(normal_parallel_plane, angle)
    return rotation.multVec(polarization_vector)
Exemple #25
0
radius = 0.01
height = 0.1

cyl = doc.addObject("Part::Cylinder", "cyl")
cyl.Radius = radius
cyl.Height = height

sph = doc.addObject("Part::Sphere", "sph")
sph.Radius = radius

uni = doc.addObject("Part::MultiFuse", "uni")
uni.Shapes = [cyl, sph]

ske = doc.addObject('Sketcher::SketchObject', 'Sketch')
ske.Placement = Base.Placement(Base.Vector(0, 0, 0),
                               Base.Rotation(-0.707107, 0, 0, -0.707107))
Poly.makeRegularPolygon('Sketch', 5, Base.Vector(-1.2 * radius, 0.9 * height,
                                                 0),
                        Base.Vector(-0.8 * radius, 0.9 * height, 0))

cut = doc.addObject("PartDesign::Revolution", "Revolution")
cut.Sketch = ske
cut.ReferenceAxis = (ske, ['V_Axis'])
cut.Angle = 360.0

dif = doc.addObject("Part::Cut", "dif")
dif.Base = uni
dif.Tool = cut

cyl1 = doc.addObject("Part::Cylinder", "cyl1")
cyl1.Radius = 0.2 * radius
Exemple #26
0
def simple_polarization_reflection(incident, normal, normal_parallel_plane,
                                   polarization):
    c1 = -normal.dot(incident)
    angle = rad_to_deg(np.pi - 2.0 * arccos(c1))
    rotation = Base.Rotation(normal_parallel_plane, angle)
    return rotation.multVec(polarization)
Exemple #27
0
##################################################
# Create Helix that serves as the spine for the threads

thread_spine = App.ActiveDocument.addObject("Part::Helix", "Helix")
thread_spine.Label = 'Thread Spine'

thread_spine.Pitch = thread_pitch
thread_spine.Height = 2 * (total_core_height + length_margin - chamfer_length)
thread_spine.Radius = hole_diameter / 2
thread_spine.Angle = 0.00
thread_spine.LocalCoord = 0  # Right-Handed Helix
thread_spine.Style = 1  # Clockwise

thread_spine.Placement  = \
    Base.Placement(Base.Vector(0.00,0.00,chamfer_length),
                   Base.Rotation(0.00,0.00,0.00,1.00))

# Recompute and fit model to screen
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")

##################################################
# Create a profile sketch to sweep Helix

#Activate the Sketcher Workbench
Gui.activateWorkbench("SketcherWorkbench")

thread_profile = App.activeDocument().addObject('Sketcher::SketchObject',
                                                'Sketch')
thread_profile.Placement = \
    App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(-0.707107,0.000000,0.000000,-0.707107))
Exemple #28
0
 def RotateU(self, angle):
     self.notMoved = False
     r = Base.Rotation(self.u, angle * 180 / math.pi)
     self.Rotate(r)
Exemple #29
0
def addCylinder(tetra_position, direction, name, offset_cylinders = False, add_AABB=False, MinorRadius=default_MinorRadius, MajorRadius=default_MajorRadius, smooth_ends=False, tiltedEdges=True, smooth_A = False, smooth_B = False):
  
  # smooth_ends = True
  # smooth_A = False
  # smooth_B = False
  
  # .. todo: smooth only one end...
  
  # make sure that tetra_position is a FreeCAD.Vector
  tetra_position = FreeCAD.Vector(*tetra_position)
  
  rod_dir = FreeCAD.Vector(*direction)*(1/4)
  
  # # hack to reduce unnecessary smoothing:
  # smooth_ends = False
  # end_point = tetra_position + rod_dir
  # FreeCAD.Console.PrintMessage("start = {} end={}\n".format(tetra_position, end_point))
  # if end_point[0] in (-1/2, 1+1/2) or end_point[1] in (-1/2, 1+1/2) or end_point[2] in (-1/2, 1+1/2):
    # smooth_ends = True
  
  # FreeCAD.Console.PrintMessage("direction = {}\n".format(direction))
  rotation_centre = FreeCAD.Vector(0, 0, 0)
  
  # FreeCAD.Console.PrintMessage("MinorRadius = {}\n".format(MinorRadius))
  # FreeCAD.Console.PrintMessage("MajorRadius = {}\n".format(MajorRadius))
  # FreeCAD.Console.PrintMessage("2*MinorRadius = {}\n".format(2*MinorRadius))
  # FreeCAD.Console.PrintMessage("2*MajorRadius = {}\n".format(2*MajorRadius))
  rod_info = utilities.ellipse.EllipticalRod()
  rod_info.setEllipsoidWidth(2*MinorRadius)
  rod_info.setCylinderDiameterBig(2*MajorRadius)
  # rod_info.setEllipsoidWidth(1)
  # rod_info.setCylinderDiameterBig(1)
  #rod_info.setCylinderHeightZ(2*MajorRadius)
  # rod_info.setEllipsoidHeightZ(2*MajorRadius)
  #FreeCAD.Console.PrintMessage('{}\n'.format(rod_info))
  #rod_info.plot()
  
  rod_base = App.ActiveDocument.addObject("Part::Ellipse","Ellipse")
  rod_base.Label = '{}_base'.format(name)
  
  if not smooth_ends:
    
    # rod_base.MajorRadius = MajorRadius
    # rod_base.MinorRadius = MinorRadius
    rod_base.MajorRadius = 0.5*rod_info.getCylinderHeightZ()
    rod_base.MinorRadius = 0.5*rod_info.getEllipsoidWidth()
    
    ry_angle = 90
    rz_angle = numpy.degrees(numpy.arctan2(direction[1], direction[0]))
    
    ry = FreeCAD.Rotation(FreeCAD.Vector(0,1,0), ry_angle)
    rz = FreeCAD.Rotation(FreeCAD.Vector(0,0,1), rz_angle)
    
    rod_base.Placement = FreeCAD.Placement(tetra_position, rz.multiply(ry), rotation_centre)
    
  else:
    (cylinder_height_z, D_ell, D_cyl, (Xp, Yp), (Xm, Ym)) = rod_info.getInfo1()
    major_axis = numpy.array([Xp, Yp]) - numpy.array([Xm, Ym])
    
    major_radius = 0.5*numpy.linalg.norm(major_axis)
    minor_radius = 0.5*rod_info.getEllipsoidWidth()

    if major_radius < minor_radius:
      FreeCAD.Console.PrintMessage('major_radius <= minor_radius: {} <= {}\n'.format(major_radius, minor_radius))
    
    rod_base.MajorRadius = major_radius
    rod_base.MinorRadius = minor_radius
    
    ry_angle = 90
    rz_angle = numpy.degrees(numpy.arctan2(direction[1], direction[0]))
    
    ry = FreeCAD.Rotation(FreeCAD.Vector(0,1,0), ry_angle)
    rz = FreeCAD.Rotation(FreeCAD.Vector(0,0,1), rz_angle)
    
    # equivalent to [a,b,c] X [0,0,c], where direction=[a,b,c]
    minor_axis = FreeCAD.Vector(direction[1]*direction[2], -direction[0]*direction[2], 0)
    r_minor_axis_angle_deg = numpy.degrees(rod_info.getMajorAxisAngleWithRespectToVertical())
    r_minor_axis = FreeCAD.Rotation(minor_axis, r_minor_axis_angle_deg)
    
    rod_base.Placement = FreeCAD.Placement(tetra_position, r_minor_axis.multiply(rz.multiply(ry)), rotation_centre)

  # FreeCAD.Console.PrintMessage("rod_dir = {}, rz_angle = {}\n".format(rod_dir, rz_angle))
  # FreeCAD.Console.PrintMessage("ry = {}\n".format(ry))
  # FreeCAD.Console.PrintMessage("rz = {}\n".format(rz))
  # FreeCAD.Console.PrintMessage("tetra_position = {}\n".format(tetra_position))
  
  rod = App.ActiveDocument.addObject("Part::Extrusion","Extrude")
  rod.Base = rod_base
  rod.Dir = rod_dir
  rod.Solid = (True)
  rod_base.ViewObject.Visibility = False
  rod.Label = '{}-cyl'.format(name)
  
  rod_final = rod
  
  if smooth_ends:
    EllipsoidSmall1 = App.ActiveDocument.addObject("Part::Ellipsoid","Ellipsoid")
    EllipsoidSmall1.Radius1=rod_info.getEllipsoidHeightZ()/2
    EllipsoidSmall1.Radius2=rod_info.getEllipsoidWidth()/2
    EllipsoidSmall1.Radius3=rod_info.getEllipsoidWidth()/2
    EllipsoidSmall1.Placement=Base.Placement(tetra_position, Base.Rotation(0.0000,0.0000,0.0000,1.0000))
    EllipsoidSmall1.Label='EllipsoidSmall1'
    # EllipsoidSmall1.ViewObject.Visibility=False
    
    EllipsoidSmall2 = App.ActiveDocument.addObject("Part::Ellipsoid","Ellipsoid")
    EllipsoidSmall2.Radius1=rod_info.getEllipsoidHeightZ()/2
    EllipsoidSmall2.Radius2=rod_info.getEllipsoidWidth()/2
    EllipsoidSmall2.Radius3=rod_info.getEllipsoidWidth()/2
    EllipsoidSmall2.Placement=Base.Placement(tetra_position + rod_dir, Base.Rotation(0.0000,0.0000,0.0000,1.0000))
    EllipsoidSmall2.Label='EllipsoidSmall2'
    
    rod_final = App.activeDocument().addObject("Part::MultiFuse","rod_final")
    rod_final.Shapes = [rod, EllipsoidSmall1, EllipsoidSmall2]
    
  else:
    ellipsoid_list = []
    if smooth_A:
      EllipsoidBig1 = App.ActiveDocument.addObject("Part::Ellipsoid","Ellipsoid")
      EllipsoidBig1.Radius1=rod_info.getCylinderHeightZ()/2
      EllipsoidBig1.Radius2=rod_info.getEllipsoidWidth()/2
      EllipsoidBig1.Radius3=rod_info.getEllipsoidWidth()/2
      EllipsoidBig1.Placement=Base.Placement(tetra_position, Base.Rotation(0.0000,0.0000,0.0000,1.0000))
      EllipsoidBig1.Label='EllipsoidBig1'
      ellipsoid_list.append(EllipsoidBig1)
      
    if smooth_B:
      EllipsoidBig2 = App.ActiveDocument.addObject("Part::Ellipsoid","Ellipsoid")
      EllipsoidBig2.Radius1=rod_info.getCylinderHeightZ()/2
      EllipsoidBig2.Radius2=rod_info.getEllipsoidWidth()/2
      EllipsoidBig2.Radius3=rod_info.getEllipsoidWidth()/2
      EllipsoidBig2.Placement=Base.Placement(tetra_position + rod_dir, Base.Rotation(0.0000,0.0000,0.0000,1.0000))
      EllipsoidBig2.Label='EllipsoidBig2'
      ellipsoid_list.append(EllipsoidBig2)
    
    if len(ellipsoid_list) > 0:
      # .. todo:: BUG: figure out why the union of the objects is partially black. :(
      # .. todo:: export STL files are also wrong. cf: ~/Desktop/RCD-paper-ANONYMIZED-3/RCD-inverse-elliptical/0.4x0.5/FreeCAD-union-bug.png
      rod_final = App.activeDocument().addObject("Part::MultiFuse","rod_final")
      rod_final.Shapes = [rod] + ellipsoid_list
      # rod_final.Shapes = [EllipsoidBig1,rod,EllipsoidBig2]
    # group = App.ActiveDocument.addObject("App::DocumentObjectGroup", "EllipticalRod")
    # group.addObject(rod)
    # group.addObject(EllipsoidSmall1)
    # group.addObject(EllipsoidSmall2)
  
  rod_final.Label = name
  
  return(rod_final)
radius = 0.01
height = 0.1

cyl = doc.addObject("Part::Cylinder", "cyl")
cyl.Radius = radius
cyl.Height = height

sph = doc.addObject("Part::Sphere", "sph")
sph.Radius = radius

uni = doc.addObject("Part::MultiFuse", "uni")
uni.Shapes = [cyl, sph]

ske = doc.addObject('Sketcher::SketchObject', 'Sketch')
ske.Placement = Base.Placement(Base.Vector(0.0, 0.0, 0.0),
                               Base.Rotation(-0.707107, 0.0, 0.0, -0.707107))
Poly.makeRegularPolygon('Sketch', 5, Base.Vector(-1.2 * radius, 0.9 * height,
                                                 0),
                        Base.Vector(-0.8 * radius, 0.9 * height, 0))

cut = doc.addObject("PartDesign::Revolution", "Revolution")
cut.Sketch = ske
cut.ReferenceAxis = (ske, ['V_Axis'])
cut.Angle = 360.0

dif = doc.addObject("Part::Cut", "dif")
dif.Base = uni
dif.Tool = cut

cyl1 = doc.addObject("Part::Cylinder", "cyl1")
cyl1.Radius = 0.2 * radius