def axs_curvature(h_surf, u=0, v=0): prop = GeomLProp_SLProps(2, 0.01) prop.SetSurface(h_surf) prop.SetParameters(u, v) d1, d2 = gp_Dir(), gp_Dir() prop.CurvatureDirections(d1, d2) vz = dir_to_vec(prop.Normal()) v1 = dir_to_vec(d1) v2 = dir_to_vec(d2) c1 = prop.MaxCurvature() c2 = prop.MinCurvature() if c1 == 0: r1 = 0 else: r1 = 1 / c1 if c2 == 0: r2 = 0 else: r2 = 1 / c2 print("Max", c1, r1, v1) print("Min", c2, r1, v2) print(v1.Dot(v2)) print(prop.Value()) return vz, v1, v2, r1, r2
def axs_line(axs): p0, dx, dy = axs.Location(), axs.XDirection(), axs.YDirection() px = gp_Pnt((gp_Vec(p0.XYZ()) + dir_to_vec(dx) * 50).XYZ()) py = gp_Pnt((gp_Vec(p0.XYZ()) + dir_to_vec(dy) * 100).XYZ()) lx = make_line(p0, px) ly = make_line(p0, py) return lx, ly
def axs_pln(axs): pnt = axs.Location() vx = dir_to_vec(axs.XDirection()).Scaled(100) vy = dir_to_vec(axs.YDirection()).Scaled(200) vz = dir_to_vec(axs.Direction()).Scaled(300) lx = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vx).XYZ())) ly = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vy).XYZ())) lz = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vz).XYZ())) return lx, ly, lz
def prop_axs(self, axs=gp_Ax3(), scale=100, xyz="z"): if xyz == "x": vec = dir_to_vec(axs.XDirection()).Scaled(scale) elif xyz == "y": vec = dir_to_vec(axs.YDirection()).Scaled(scale) elif xyz == "z": vec = dir_to_vec(axs.Direction()).Scaled(scale) else: vec = dir_to_vec(axs.Direction()).Scaled(scale) return axs.Translated(vec)
def second_derivative(h_surf, u=0, v=0): p1 = gp_Pnt() pu, pv = gp_Vec(), gp_Vec() puu, pvv = gp_Vec(), gp_Vec() puv = gp_Vec() prop = GeomLProp_SLProps(h_surf, u, v, 1, 1) GeomLProp_SurfaceTool.D2(h_surf, u, v, p1, pu, pv, puu, pvv, puv) e0 = pu.Crossed(pv) pu.Normalize() pv.Normalize() e0.Normalize() puu.Normalize() pvv.Normalize() puv.Normalize() print(p1) print("pu", pu) print("pv", pv) print("e0", e0) print("puu", puu) print("pvv", pvv) print("puv", puv) first_form = np.array([[pu.Dot(pu), pu.Dot(pv)], [pv.Dot(pu), pv.Dot(pv)]]) secnd_form = np.array([[e0.Dot(puu), e0.Dot(puv)], [e0.Dot(puv), e0.Dot(pvv)]]) print(first_form) print(secnd_form) print(prop.GaussianCurvature()) print(prop.MeanCurvature()) d1, d2 = gp_Dir(), gp_Dir() prop.CurvatureDirections(d1, d2) a1 = gp_Ax3() v1 = dir_to_vec(d1) v2 = dir_to_vec(d2) if pu.IsParallel(v1, 1 / 1000): c1 = prop.MaxCurvature() c2 = prop.MinCurvature() print(v1.Dot(pu), v1.Dot(pv)) print(v2.Dot(pu), v2.Dot(pv)) else: c1 = prop.MinCurvature() c2 = prop.MaxCurvature() print(v1.Dot(pu), v1.Dot(pv)) print(v2.Dot(pu), v2.Dot(pv)) print(c1, 1 / c1) print(c2, 1 / c2) px = np.linspace(-1, 1, 100) * 100 p1_y = px**2 / c1 p2_y = px**2 / c1 curv1 = curv_spl(px, p1_y) curv2 = curv_spl(px, p2_y)
def MovXYZSurf(self, dst=0.0, axs="z"): if axs == "x": vec = dir_to_vec(self.rot.XDirection()) elif axs == "y": vec = dir_to_vec(self.rot.YDirection()) elif axs == "z": vec = dir_to_vec(self.rot.Direction()) else: vec = dir_to_vec(self.rot.Direction()) trf = gp_Trsf() trf.SetTranslation(vec.Scaled(dst)) self.rot.Transform(trf) self.axs.Transform(trf) self.surf.Move(TopLoc_Location(trf))
def get_deg(axs, vec): vx = dir_to_vec(axs.XDirection()) vy = dir_to_vec(axs.YDirection()) vz = dir_to_vec(axs.Direction()) pln_x = Geom_Plane(axs.Location(), axs.YDirection()) pln_y = Geom_Plane(axs.Location(), axs.XDirection()) vec_p = gp_Pnt((gp_Vec(axs.Location().XYZ()) + vec).XYZ()) pnt_x = GeomAPI_ProjectPointOnSurf(vec_p, pln_x).Point(1) pnt_y = GeomAPI_ProjectPointOnSurf(vec_p, pln_y).Point(1) vec_x = gp_Vec(axs.Location(), pnt_x) vec_y = gp_Vec(axs.Location(), pnt_y) deg_x = vec_x.AngleWithRef(vz, vy) deg_y = vec_y.AngleWithRef(vz, vx) print(np.rad2deg(deg_x), np.rad2deg(deg_y)) return deg_x, deg_y
def run_beam(self, beam=gp_Ax3()): pts = [beam.Location()] print(beam.Location(), dir_to_vec(beam.Direction())) beam = self.Reflect(beam, self.surf1.face) pts.append(beam.Location()) print(beam.Location(), dir_to_vec(beam.Direction())) beam = self.Reflect(beam, self.surf2.face) pts.append(beam.Location()) pnt = move_pnt_to_dir(beam, 2500) pts.append(pnt) beam_ray = make_polygon(pts) return beam, beam_ray
def show_axs_pln(self, axs=gp_Ax3(), scale=100): pnt = axs.Location() dx = axs.XDirection() dy = axs.YDirection() dz = axs.Direction() vx = dir_to_vec(dx).Scaled(1 * scale) vy = dir_to_vec(dy).Scaled(2 * scale) vz = dir_to_vec(dz).Scaled(3 * scale) pnt_x = pnt_trf_vec(pnt, vx) pnt_y = pnt_trf_vec(pnt, vy) pnt_z = pnt_trf_vec(pnt, vz) self.display.DisplayShape(pnt) self.display.DisplayShape(make_line(pnt, pnt_x), color="RED") self.display.DisplayShape(make_line(pnt, pnt_y), color="GREEN") self.display.DisplayShape(make_line(pnt, pnt_z), color="BLUE")
def run_beam_face(self, beam0=gp_Ax3(), shpe=TopoDS_Shape(), tr=0): v0 = dir_to_vec(beam0.Direction()) v1 = dir_to_vec(beam0.XDirection()) p0 = beam0.Location() lin = gp_Lin(beam0.Axis()) api = BRepIntCurveSurface_Inter() api.Init(shpe, lin, 1.0E-9) dst = np.inf num = 0 sxy = p0 uvw = [0, 0, 0] fce = None while api.More(): p1 = api.Pnt() dst1 = p0.Distance(p1) if dst1 < dst and api.W() > 1.0E-6: dst = dst1 uvw = [api.U(), api.V(), api.W()] sxy = api.Pnt() fce = api.Face() api.Next() else: api.Next() print(*uvw) u, v, w = uvw surf = BRepAdaptor_Surface(fce) prop = BRepLProp_SLProps(surf, u, v, 2, 1.0E-9) p1, vx, vy = prop.Value(), prop.D1U(), prop.D1V() vz = vx.Crossed(vy) if vz.Dot(v0) > 0: vz.Reverse() vx.Normalize() vy.Normalize() vz.Normalize() beam1 = gp_Ax3(p1, vec_to_dir(v0.Reversed()), vec_to_dir(v1.Reversed())) norm1 = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx)) if tr == 0: beam1.Mirror(norm1.Ax2()) if beam1.Direction().Dot(norm1.Direction()) < 0: beam1.ZReverse() elif tr == 1: beam1.ZReverse() return beam1
def __init__(self, axs=gp_Ax3()): self.rot = axs self.axs = gp_Ax3(self.rot.Ax2()) self.rim = make_edge(gp_Circ(self.axs.Ax2(), 100)) self.pln = dispocc.make_plane_axs(self.axs) self.surf = make_plane(self.axs.Location(), dir_to_vec(self.axs.Direction()), -500, 500, -500, 500)
def OptAxs(self, axs="y"): print(self.ini.name, "->", self.tar.name) if axs == None: ref = gp_Dir(0, 0, 1) pnt = gp_Pnt(0, 0, 0) ax = gp_Ax3(pnt, ref) elif axs == "x": ref = self.ini.beam.XDirection() pnt = self.tar.BeamLocal().Location() pnt.SetZ(0.0) pnt.SetY(0.0) ax = gp_Ax3(pnt, gp_Dir(0, 0, 1)) elif axs == "y": ref = self.ini.beam.YDirection() pnt = self.tar.BeamLocal().Location() pnt.SetZ(0.0) pnt.SetX(0.0) ax = gp_Ax3(pnt, gp_Dir(0, 0, 1)) else: ref = gp_Dir(0, 0, 1) pnt = gp_Pnt(0, 0, 0) ax = gp_Ax3(pnt, gp_Dir(0, 0, 1)) print("Detect Target Position") print(self.ini.axs.Location()) print(self.tar.axs.Location()) print(self.ini.beam.Location()) print(self.tar.beam.Location()) print(self.ini.BeamLocal().Location()) print(self.tar.BeamLocal().Location()) ax = self.tar.Move_Axs(ax, gp_Ax3(), self.tar.axs) v0 = dir_to_vec(self.ini.beam.Direction()) v1 = gp_Vec(self.ini.beam.Location(), ax.Location()).Normalized() rf = dir_to_vec(ref) deg = np.rad2deg(v0.AngleWithRef(v1, rf)) print("Detect Rotation Angle") print(ax.Location()) print(self.ini.name, axs, deg) print(v0) print(v1) print(rf) self.ini.RotAxs(deg / 2, axs=axs)
def face_rotate(self, face=TopoDS_Face(), axs=gp_Ax1()): plan = self.pln_on_face(face) plan_axs = plan.Position() self.display.DisplayShape(plan_axs.Location()) v0 = dir_to_vec(self.tmp_axis.Direction()) v1 = dir_to_vec(plan_axs.Direction()) print(v0.Dot(v1)) lin_vec = gp_Vec(axs.Location(), plan_axs.Location()) edg_circl = Geom_Circle( gp_Circ( gp_Ax2(axs.Location(), axs.Direction(), vec_to_dir(lin_vec)), 5)) rim_u0, rim_u1 = edg_circl.FirstParameter(), edg_circl.LastParameter() rim_p0 = edg_circl.Value(rim_u0) pln_angle = self.tmp_axis.Angle(plan_axs) ref_angle = self.tmp_axis.Direction().AngleWithRef( plan_axs.Direction(), axs.Direction()) print(np.rad2deg(pln_angle), np.rad2deg(ref_angle)) rim_u2 = -ref_angle rim_p2 = edg_circl.Value(rim_u2) rim_angle = Geom_TrimmedCurve(edg_circl, rim_u0, rim_u2) trf = gp_Trsf() #trf.SetRotation(axs, 2*np.pi - ref_angle) if np.abs(ref_angle) >= np.pi / 2: trf.SetRotation(axs, -ref_angle) elif 0 < ref_angle < np.pi / 2: trf.SetRotation(axs, np.pi - ref_angle) elif -np.pi / 2 < ref_angle < 0: trf.SetRotation(axs, -ref_angle - np.pi) else: trf.SetRotation(axs, -ref_angle) #trf.SetTransformation(axs3.Rotated(axs, angle), axs3) loc_face = TopLoc_Location(trf) new_face = face.Moved(loc_face) self.display.DisplayShape(new_face, transparency=0.5) self.display.DisplayShape(rim_angle) self.display.DisplayShape(rim_p0) self.display.DisplayShape(rim_p2) return new_face
def GO_Prop(self, s=0): h_ini_wave = BRep_Tool.Surface(self.ini.wave) vz, v1, v2, r1, r2 = axs_curvature(h_ini_wave, 0.5, 0.5) r1_z = r1 + s / 2 r2_z = r2 + s / 2 ini_wave_axs = self.ini.beam.Translated( dir_to_vec(self.ini.beam.Direction()).Scaled(s / 2)) ini_wave_axs.SetXDirection(vec_to_dir(v1)) ini_wave = wavefront([r1_z, r2_z], ini_wave_axs) self.display.DisplayShape(ini_wave) r1_z = r1 + s r2_z = r2 + s self.ini_wave_axs = self.ini.beam.Translated( dir_to_vec(self.ini.beam.Direction()).Scaled(s)) self.ini_wave_axs.SetXDirection(vec_to_dir(v1)) self.ini_wave = wavefront([r1_z, r2_z], self.ini_wave_axs) self.display.DisplayShape(self.ini_wave)
def display_obj(self, name, size=100): self.display_shapes(self.obj[name], "pts") self.display.DisplayMessage(self.obj[name]["pnt"], name) self.display.DisplayVector(self.obj[name]["xyz"][0].Scaled(size), self.obj[name]["pnt"]) self.display.DisplayVector(self.obj[name]["xyz"][1].Scaled(size), self.obj[name]["pnt"]) self.display.DisplayVector(self.obj[name]["xyz"][2].Scaled(size), self.obj[name]["pnt"]) self.display.DisplayShape(self.obj[name]["frm"]) self.display.DisplayShape(self.obj[name]["pln"]) p = self.obj[name]["axs"].Location() v0 = gp_Vec(p.XYZ()) + dir_to_vec( self.obj[name]["axs"].XDirection()).Scaled(50) v1 = gp_Vec(p.XYZ()) + dir_to_vec( self.obj[name]["axs"].YDirection()).Scaled(100) self.display.DisplayShape(make_line(p, gp_Pnt(v0.XYZ()))) self.display.DisplayShape(make_line(p, gp_Pnt(v1.XYZ())))
def Reflect(self): h_surf = BRep_Tool.Surface(self.tar.srf) g_line = gp_Lin(self.ini.beam.Location(), self.ini.beam.Direction()) ray = Geom_Line(g_line) if GeomAPI_IntCS(ray, h_surf).NbPoints(): self.tar.beam = reflect(self.ini.beam, self.tar.srf) else: pln = make_plane(self.tar.axs.Location(), dir_to_vec(self.tar.axs.Direction()), 500, -500, 500, -500) self.tar.beam = reflect(self.ini.beam, pln)
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())
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()
def __init__(self): plotocc.__init__(self) self.compound = TopoDS_Compound() self.builder = BRep_Builder() self.builder.MakeCompound(self.compound) box = BRepPrimAPI_MakeBox(100, 200, 300).Shape() self.display.DisplayShape(box) con = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(500, 0, 0), gp_Dir(0, 0, 1)), 100, 200, 300).Shape() self.display.DisplayShape(con) # https://www.opencascade.com/doc/occt-7.4.0/refman/html/class_graphic3d___camera.html self.camera = self.display.View.Camera() print(self.camera.Scale(), dir_to_vec(self.camera.OrthogonalizedUp())) print(self.camera.ViewDimensions())
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
def Reflect(self): h_surf = BRep_Tool.Surface(self.tar.srf) g_line = gp_Lin(self.ini.beam.Location(), self.ini.beam.Direction()) ray = Geom_Line(g_line) if GeomAPI_IntCS(ray, h_surf).NbPoints(): self.tar.beam = reflect(self.ini.beam, self.tar.srf) else: pln = make_plane(self.tar.axs.Location(), dir_to_vec(self.tar.axs.Direction()), 500, -500, 500, -500) h_surf = BRep_Tool.Surface(pln) self.tar.beam = reflect(self.ini.beam, pln) print(self.ini.beam.Location()) print(self.tar.beam.Location()) GeomAPI_IntCS(ray, h_surf).IsDone() uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1) u, v, w = uvw print(u, v, w) vz, v1, v2, r1, r2 = axs_curvature(h_surf, u, v) tar_surf_axs = gp_Ax3(self.tar.beam.Location(), vec_to_dir(vz), vec_to_dir(v1)) tar_surf = wavefront([r1, r2], tar_surf_axs) self.display.DisplayShape(tar_surf, color="BLUE") self.display.DisplayShape(axs_pln(tar_surf_axs)) self.GO_Prop(w) h_tar_wave = BRep_Tool.Surface(self.ini_wave) vz, v1, v2, r1, r2 = axs_curvature(h_tar_wave, u, v) tar_wave_axs = self.tar.beam.Translated(gp_Vec(0, 0, 0)) tar_wave_axs.SetXDirection(vec_to_dir(v1)) self.tar.wave = wavefront([r1, r2], tar_wave_axs) self.display.DisplayShape(self.tar.wave, color="RED") self.display.DisplayShape(axs_pln(tar_wave_axs))
def move_pnt_to_dir(axs=gp_Ax3(), scale=100): vec = point_to_vector(axs.Location()) + dir_to_vec(axs.Direction()) * scale return vector_to_point(vec)
def show_plane(self, axs=gp_Ax3(), scale=100): pnt = axs.Location() vec = dir_to_vec(axs.Direction()) pln = make_plane(pnt, vec, -scale, scale, -scale, scale) self.display.DisplayShape(pln)
def show_vec(self, beam=gp_Ax3(), scale=1.0): pnt = beam.Location() vec = dir_to_vec(beam.Direction()).Scaled(scale) print(vec.Magnitude()) self.display.DisplayVector(vec, pnt)
def pnt_from_axs(axs=gp_Ax3(), length=100): vec = point_to_vector(axs.Location()) + \ dir_to_vec(axs.Direction()) * length return vector_to_point(vec)
print(GeomAPI_IntCS(Geom_Line(ax1.Axis()), surf).NbPoints()) u, v, w = GeomAPI_IntCS(Geom_Line(ax1.Axis()), surf).Parameters(1) p, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec() api = GeomLProp_SLProps(surf, u, v, 1, 0.1E-03) pnt = api.Value() dst = pnt.Distance(ax1.Location()) ax2 = obj.prop_axs(ax1, dst) rim_u = surf.UIso(u) rim_v = surf.VIso(v) print(v, rim_u.FirstParameter(), rim_u.LastParameter()) print(u, rim_v.FirstParameter(), rim_v.LastParameter()) obj.display.DisplayShape(rim_u, color="BLUE") obj.display.DisplayShape(rim_v, color="BLUE") print(api.GaussianCurvature()) print(api.MinCurvature(), api.MeanCurvature(), api.MaxCurvature()) print(dir_to_vec(api.Normal())) du, dv = gp_Dir(), gp_Dir() api.TangentU(du) api.TangentV(dv) print(dir_to_vec(du)) print(dir_to_vec(dv)) dx, dy = gp_Dir(), gp_Dir() api.CurvatureDirections(dx, dy) print(dir_to_vec(dx)) print(dir_to_vec(dy)) axs_x = gp_Ax3(pnt, dx, api.Normal()) axs_x = obj.prop_axs(axs_x, -np.abs(1 / api.MaxCurvature()), xyz="x") rim_x = Geom_TrimmedCurve(Geom_Circle(axs_x.Ax2(), np.abs(1 / api.MaxCurvature())), -np.pi / 2 / 10, np.pi / 2 / 10) # obj.display.DisplayShape(rim_x) axs_y = gp_Ax3(pnt, dy, api.Normal())
def line_from_axs(axs=gp_Ax3(), length=100): vec = point_to_vector(axs.Location()) + \ dir_to_vec(axs.Direction()) * length return make_edge(axs.Location(), vector_to_point(vec))
parser.add_option("--px", dest="px", default=0.0, type="float") parser.add_option("--dx", dest="dx", default=0.0, type="float") parser.add_option("--py", dest="py", default=0.0, type="float") parser.add_option("--dy", dest="dy", default=0.0, type="float") opt, argc = parser.parse_args(argvs) ax, pln = def_ax(0, 0, 0, lx=100, ly=100) m1_ax, m1_pln = def_ax(0, 0, 470, dx=-45) m2_ax, m2_pln = def_ax(0, -250, 470, dx=45, dy=180) wg_ax, wg_pln = def_ax(0, -250, 470 + 360, lx=100, ly=100, dy=0) ax0 = gp_Ax3(gp_Pnt(opt.px, opt.py, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0)) rot_axs(ax0, gp_Ax1(ax0.Location(), ax0.XDirection()), opt.dx) rot_axs(ax0, gp_Ax1(ax0.Location(), ax0.YDirection()), opt.dy) pnt = ax0.Location() vec = dir_to_vec(ax0.Direction()) m1_pnt, m1_vec = reflect(pnt, vec, m1_ax) m2_pnt, m2_vec = reflect(m1_pnt, m1_vec, m2_ax) wg_pnt, wg_vec = reflect(m2_pnt, m2_vec, wg_ax) wg_vec.Reverse() wg_p = wg_ax.Location() print(np.rad2deg(get_angle(wg_ax, wg_vec, dir_to_vec(wg_ax.Direction())))) print(wg_pnt.X() - wg_p.X(), wg_pnt.Y() - wg_p.Y()) """ display, start_display, add_menu, add_function_to_menu = init_display() display.DisplayShape (pnt) display.DisplayShape (pln) display.DisplayShape (m1_pln) display.DisplayShape (m2_pln) display.DisplayShape (wg_pln)
if __name__ == "__main__": argvs = sys.argv parser = argparse.ArgumentParser() parser.add_argument("--dir", dest="dir", default="./") parser.add_argument("--out", dest="out", default="./") parser.add_argument("--refe", dest="refe", default="surf1") parser.add_argument("--surf", dest="surf", default="surf2") parser.add_argument("--pxyz", dest="pxyz", default=(0, 0, 0), type=float, nargs=3) parser.add_argument("--rxyz", dest="rxyz", default=(0, 0, 0), type=float, nargs=3) opt = parser.parse_args() print(opt, argvs) filename = opt.dir + opt.refe + ".cor" ax = get_axs(filename) print(dir_to_vec(ax.Direction()), ax.Location()) ax.Translate(gp_Vec(gp_Pnt(), gp_Pnt(*opt.pxyz))) for i, deg in enumerate(opt.rxyz): if i == 0: axs = gp_Ax1(ax.Location(), ax.XDirection()) elif i == 1: axs = gp_Ax1(ax.Location(), ax.YDirection()) elif i == 2: axs = gp_Ax1(ax.Location(), ax.Direction()) else: axs = gp_Ax1(ax.Location(), ax.Direction()) ax.Rotate(axs, np.deg2rad(deg)) print(dir_to_vec(ax.Direction()), ax.Location()) occ_to_grasp_cor(ax, opt.surf, opt.out + opt.surf + ".cor")
if __name__ == "__main__": argvs = sys.argv parser = OptionParser() parser.add_option("--dir", dest="dir", default="./") opt, argc = parser.parse_args(argvs) print(argc, opt) display, start_display, add_menu, add_function_to_menu = init_display() beam = get_axs("./beam_cyl.cor") surf = set_surface("./cylinder.stp") display.DisplayShape(surf) # display.DisplayShape(axs_pln(gp_Ax3())) # display.DisplayShape(axs_pln(beam)) axs1 = beam val = 1 while val != None: axs0 = axs1 axs1, axs, val = reflect_axs2(axs0, surf, indx=2) get_deg(axs, dir_to_vec(axs1.Direction())) if val != None: display.DisplayShape( make_line(axs0.Location(), axs1.Location()), color="GREEN") # display.DisplayShape(axs_pln(axs1)) display.FitAll() start_display()