Exemplo n.º 1
0
def reflect(p0, v0, face):
    h_surf = BRep_Tool.Surface(face)
    ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0)))
    uvw = GeomAPI_IntCS(ray.GetHandle(), h_surf).Parameters(1)
    u, v, w = uvw
    p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
    vz = vx.Crossed(vy)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz)))
    return p1, v1
Exemplo n.º 2
0
def reflect_axs2(beam, surf, axs=gp_Ax3(), indx=1):
    p0, v0 = beam.Location(), dir_to_vec(beam.Direction())
    h_surf = BRep_Tool.Surface(surf)
    ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0)))
    if GeomAPI_IntCS(ray, h_surf).NbPoints() == 0:
        return beam, beam, None
    elif GeomAPI_IntCS(ray, h_surf).NbPoints() == 1:
        return beam, beam, None
    GeomAPI_IntCS(ray, h_surf).IsDone()
    u, v, w = GeomAPI_IntCS(ray, h_surf).Parameters(indx)
    p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
    vz = vx.Crossed(vy)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz), vec_to_dir(vx)))
    norm_ax = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
    beam_ax = gp_Ax3(p1, vec_to_dir(v1), beam.XDirection().Reversed())
    return beam_ax, norm_ax, 1
Exemplo n.º 3
0
def reflect(beam, face, axs=gp_Ax3()):
    p0, v0 = beam.Location(), dir_to_vec(beam.Direction())
    h_surf = BRep_Tool.Surface(face)
    ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0)))
    if GeomAPI_IntCS(ray, h_surf).NbPoints() == 0:
        print("Out of Surface", axs.Location())
        pln = make_plane(axs.Location(), dir_to_vec(axs.Direction()), 500,
                         -500, 500, -500)
        h_surf = BRep_Tool.Surface(pln)
    GeomAPI_IntCS(ray, h_surf).IsDone()
    uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1)
    u, v, w = uvw
    p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
    vz = vx.Crossed(vy)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz), vec_to_dir(vx)))
    return gp_Ax3(p1, vec_to_dir(v1), beam.XDirection().Reversed())
Exemplo n.º 4
0
 def Reflect(self, beam=gp_Ax3(), surf=make_plane()):
     h_surf = BRep_Tool.Surface(surf)
     ray = Geom_Line(beam.Location(), beam.Direction())
     if GeomAPI_IntCS(ray, h_surf).NbPoints() == 0:
         beam_v1 = beam
     else:
         GeomAPI_IntCS(ray, h_surf).IsDone()
         uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1)
         u, v, w = uvw
         p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
         GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
         vz = vx.Crossed(vy)
         vx.Normalize()
         vy.Normalize()
         vz.Normalize()
         norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
         beam_v0 = beam
         beam_v0.SetLocation(p1)
         beam_v1 = beam_v0.Mirrored(norm.Ax2())
         beam_v1.XReverse()
     return beam_v1
Exemplo n.º 5
0
 def check_ground(self):
     if len(self.pts) != 1:
         ray = spl_2pnt(self.pts[-2], self.pts[-1])
         vec = gp_Vec(self.pts[-2], self.pts[-1])
         self.p_trce.Perform(ray, self.h_surf)
         if self.p_trce.NbPoints() != 0 and vec.Z() < 0:
             print()
             uvw = self.p_trce.Parameters(1)
             u, v, w = uvw
             p0, v0 = gp_Pnt(), gp_Vec()
             GeomLProp_CurveTool.D1(ray, w, p0, v0)
             p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
             GeomLProp_SurfaceTool.D1(self.h_surf, u, v, p1, vx, vy)
             vz = vx.Crossed(vy)
             self.pts[-1] = p0
             print(self.r.t, w, p0)
             print(v0)
             print(gp_Vec(self.pts[-2], self.pts[-1]))
             norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
             v1 = v0
             v1.Mirror(norm.Ax2())
             self.r.set_initial_value(self.gen_condition(p0, v1),
                                      self.r.t + self.dt)
Exemplo n.º 6
0
 def reflect_b2(self, num=1):
     h_surf = BRep_Tool.Surface(self.b2)
     ray = Geom_Line(self.beam.Axis())
     self.RayTrace.Perform(ray, h_surf)
     if self.RayTrace.NbPoints() == 0:
         beam = self.beam
     else:
         self.num += 1
         uvw = self.RayTrace.Parameters(num)
         u, v, w = uvw
         p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
         GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
         vz = vx.Crossed(vy).Reversed()
         norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
         self.show_axs_pln(norm, scale=10)
         beam = self.beam
         beam.SetLocation(p1)
         beam.SetDirection(beam.Direction().Reversed())
         beam.Mirror(norm.Axis())
         print(self.num, self.b2, p1)
         self.pts.append(p1)
         # self.beam.XReverse()
         # self.beam.Mirror(norm.Ax2())
     return beam
Exemplo n.º 7
0
 def reflect_beam(self, beam0=gp_Ax3(), tr=0):
     v0 = dir_to_vec(beam0.Direction())
     v1 = dir_to_vec(beam0.XDirection())
     surf = BRep_Tool.Surface(self.surf)
     ray = Geom_Line(beam0.Axis())
     uvw = GeomAPI_IntCS(ray, surf).Parameters(1)
     u, v, w = uvw
     p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
     GeomLProp_SurfaceTool.D1(surf, u, v, p1, vx, vy)
     vz = vx.Crossed(vy)
     if vz.Dot(v0) > 0:
         vz.Reverse()
     vx.Normalize()
     vy.Normalize()
     vz.Normalize()
     self.beam = gp_Ax3(p1, vec_to_dir(v0.Reversed()),
                        vec_to_dir(v1.Reversed()))
     self.norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
     if tr == 0:
         self.beam.Mirror(self.norm.Ax2())
         if self.beam.Direction().Dot(self.norm.Direction()) < 0:
             self.beam.ZReverse()
     elif tr == 1:
         self.beam.ZReverse()
Exemplo n.º 8
0
    def __init__(self):
        plotocc.__init__(self)
        self.compound = TopoDS_Compound()
        self.builder = BRep_Builder()
        self.builder.MakeCompound(self.compound)

        self.beam = gp_Ax3()
        self.beam.SetLocation(gp_Pnt(0.5, 0.5, 0.0))
        self.beam.SetDirection(gp_Dir(0.0, 0.5, 1.0))
        self.beam_line = line_from_axs(self.beam, length=20)
        self.builder.Add(self.compound, self.beam_line)

        ax = gp_Ax3(gp_Pnt(0, 0, 10), gp_Dir(0, 0, -1))
        px = np.linspace(-1, 1, 10) * 10
        py = np.linspace(-1, 1, 10) * 10
        mesh = np.meshgrid(px, py)
        surf = mesh[0]**2 / 100 + mesh[1]**2 / 150
        self.surf = spl_face(*mesh, surf, ax)
        self.surf_bound = self.make_PolySurf(radi=5, axs=ax)

        self.beam_glin = Geom_Line(self.beam.Location(), self.beam.Direction())
        self.ics = GeomAPI_IntCS(self.beam_glin, BRep_Tool.Surface(self.surf))
        print(self.ics.NbPoints())
        # print(self.ics.Point(1))

        self.ics = GeomAPI_IntCS(self.beam_glin,
                                 BRep_Tool.Surface(self.surf_bound))
        print(self.ics.NbPoints())

        #self.display.DisplayShape(self.surf, transparency=0.7)
        self.display.DisplayShape(self.surf_bound, transparency=0.7)
        self.plns = TopoDS_Shell()
        self.builder.MakeShell(self.plns)
        for ix in np.linspace(0, 1, 5):
            for iy in np.linspace(0, 1, 5):
                p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
                GeomLProp_SurfaceTool.D1(BRep_Tool.Surface(self.surf), ix, iy,
                                         p1, vx, vy)
                vz = vx.Crossed(vy)
                axs = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
                pln = self.make_PolyPlane(axs=axs, radi=2.5, shft=15.0)
                print(pln)

                self.builder.Add(self.compound, make_vertex(p1))
                self.builder.Add(self.plns, pln)
        self.builder.Add(self.compound, self.plns)

        for face in Topo(self.plns).faces():
            self.ics.Perform(self.beam_glin, BRep_Tool.Surface(face))
            uvw = self.ics.Parameters(1)
            u, v, w = uvw
            p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
            GeomLProp_SurfaceTool.D1(BRep_Tool.Surface(face), u, v, p1, vx, vy)
            vz = vx.Crossed(vy)
            if u > 0 and v > 0:
                print(u, v)
                print(p1)
                print(self.ics.Point(1))
                self.display.DisplayShape(p1)
                self.display.DisplayShape(face, color="BLUE")
            else:
                print(u, v)