예제 #1
0
 def findIntersectPoints(curve, surface):
     ps = []
     tool = GeomAPI_IntCS(curve, surface)
     pCount = tool.NbPoints()
     for i in range(1, pCount + 1):
         ps += [tool.Point(i)]
     return ps
예제 #2
0
def getPntsCurveSurfaceIntersect(curve, surface):
    pnts = []
    tool = GeomAPI_IntCS(curve, surface)
    pCount = tool.NbPoints();
    for i in range(pCount):
       pnts += [tool.Point(1)]
    return pnts
예제 #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())
예제 #4
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
예제 #5
0
 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)
예제 #6
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
예제 #7
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
예제 #8
0
    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))
예제 #9
0
    def __init__(self, theDisplay: Viewer3d, statusBar, sg=None):
        self.myDisplay = theDisplay
        self.myContext: AIS_InteractiveContext = theDisplay.Context
        self.myView: V3d_View = theDisplay.View
        self.myStatusBar = statusBar

        self.myCurrentMethod = Part_ObjectTypeOfMethod.Nothing_Method

        self.myIntCS = GeomAPI_IntCS()

        self.myNode: SketchNode = None

        self.myData = []
        self.myCommands = []
        self.addCommand(Part_CommandBezierSurface())
        self.addCommand(Part_CommandRevolvedSurface())
        self.addCommand(Part_CommandExtrudedSurface())
        self.addCommand(Part_CommandSweepSurface())
예제 #10
0
    def __init__(self, crv, srf):
        super(IntersectCurveSurface, self).__init__(crv, srf)

        # Perform

        # OCC intersection.
        csi = GeomAPI_IntCS(crv.object, srf.object)
        results = []
        for i in range(1, csi.NbPoints() + 1):
            u, v, t = csi.Parameters(i, 0., 0., 0.)
            pc = crv.eval(t)
            ps = srf.eval(u, v)
            pi = mean([pc, ps], axis=0)
            pi = Point(*pi)
            results.append([(t, u, v), pi])

        npts = len(results)
        self._set_results(npts, results)
예제 #11
0
    def __init__(self):
        plotocc.__init__(self)
        self.b1 = self.get_face(gen_ellipsoid(rxyz=[100, 100, 105]))
        self.b2 = self.get_face(gen_ellipsoid(rxyz=[210, 210, 210]))
        self.beam = gp_Ax3(gp_Pnt(0, 150, 0), gp_Dir(1, 1.5, 0))
        print(self.b1)

        h_surf = BRep_Tool.Surface(self.b2)
        ray = Geom_Line(self.beam.Axis())
        self.RayTrace = GeomAPI_IntCS(ray, h_surf)
        print(self.RayTrace.NbPoints())
        self.num = 0
        self.pts = [self.beam.Location()]
        for i in range(5):
            self.beam = self.reflect_b1(num=1)
            self.beam = self.reflect_b1(num=2)
            self.beam = self.reflect_b2(num=1)
            self.beam = self.reflect_b2(num=2)
예제 #12
0
    def intersections_with_line(self, line):
        """Compute the intersections with a line.

        Parameters
        ----------
        line : :class:`~compas.geometry.Line`

        Returns
        -------
        list[:class:`~compas.geometry.Point`]

        """
        intersection = GeomAPI_IntCS(Geom_Line(line.to_occ()),
                                     self.occ_surface)
        points = []
        for index in range(intersection.NbPoints()):
            pnt = intersection.Point(index + 1)
            point = Point.from_occ(pnt)
            points.append(point)
        return points
예제 #13
0
    def __init__(self, pnt=gp_Pnt(-10, 0, -10), vec=gp_Vec(10, 20, 100)):
        plotocc.__init__(self)
        self.solver = ode(self.newton).set_integrator('dopri5')
        self.initial_conditions = self.gen_condition(pnt, vec)
        self.m = 10.0
        self.k = 0.0
        ray = spl_2pnt()

        px = np.linspace(-1, 1, 50) * 750
        py = np.linspace(-1, 1, 50) * 750
        mesh = np.meshgrid(px, py)
        surf = mesh[0]**2 / 500 + mesh[1]**2 / 750

        self.grd_axs = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(-0.25, 0, 1))
        #self.grd = pln_for_axs(self.grd_axs, [500, 500])
        self.grd = spl_face(*mesh, surf)
        self.h_surf = BRep_Tool.Surface(self.grd)
        self.p_trce = GeomAPI_IntCS(ray, self.h_surf)

        self.pts, self.vel = [], []
예제 #14
0
    def __init__(self, theDisplay, sg: Sketch_QTGUI = None):
        self.myCoordinateSystem = gp_Ax3(gp.XOY())
        self.myContext: AIS_InteractiveContext = theDisplay.Context
        self.myDisplay = theDisplay
        self.myView: V3d_View = theDisplay.View
        self.myGUI = sg
        self.myGUI.SetAx3(self.myCoordinateSystem)
        self.myGUI.SetContext(self.myContext)

        self.myCurrentMethod = Sketch_ObjectTypeOfMethod.Nothing_Method

        self.myCurrentDir: gp_Dir = gp.DZ()
        self.myTempPnt: gp_Pnt = gp.Origin()
        self.myCurrentPnt2d: gp_Pnt2d = gp.Origin2d()
        self.myCurrentPlane = Geom_Plane(self.myCoordinateSystem)
        self.myCurrentLine = Geom_Line(self.myTempPnt, self.myCurrentDir)

        self.myIntCS = GeomAPI_IntCS()

        self.PolylineFirstPoint = gp.Origin2d()
        self.PolylineFirstPointExist = False

        self.myData = []
        self.myNode: SketchObjectNode = None
        self.myModel = None
        self.SnapToGridPoint = False
        self.myCommands = []

        self.myAnalyserSnap = Sketch_AnalyserSnap(self.myContext, self.myData,
                                                  self.myCoordinateSystem)

        self.addCommand(Sketch_CommandPoint())
        self.addCommand(Sketch_CommandLine2P())
        self.addCommand(Sketch_CommandBezierCurve())
        self.addCommand(Sketch_CommandArcCenter2P())
        self.addCommand(Sketch_CommandCircleCenterRadius())
        self.addCommand(Sketch_CommandBSpline())
        self.addCommand(Sketch_CommandPointToBSpline())
        self.addCommand(Sketch_CommandMoveObject())
        self.addCommand(Sketch_CommandNurbCircleSquare())
        self.addCommand(Sketch_CommandNurbCircleTriangle())
예제 #15
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()
예제 #16
0
 def proj_pnt_pln(self, pnt, surf, axs=gp_Ax3()):
     lin = gp_Lin(pnt, axs.Direction())
     sxy = GeomAPI_IntCS(Geom_Line(lin), BRep_Tool.Surface(surf)).Point(1)
     return sxy
예제 #17
0
def Prj_pnt_to_face(axs, pnt, face):
    lin = gp_Lin(pnt, axs.Direction())
    sxy = GeomAPI_IntCS(Geom_Line(lin).GetHandle(),
                        BRep_Tool.Surface(face)).Point(1)
    return sxy
예제 #18
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)
예제 #19
0
from OCC.Core.gp import gp_Pln
from OCC.Core.BRep import BRep_Tool
from OCC.Core.GeomLProp import GeomLProp_SurfaceTool, GeomLProp_CurveTool
from OCC.Core.GeomAPI import GeomAPI_IntCS, GeomAPI_PointsToBSpline
from OCC.Core.TColgp import TColgp_Array1OfPnt
from OCCUtils.Construct import make_plane

from particle.base import spl_curv_pts

if __name__ == '__main__':
    p0 = gp_Pnt(10, 10, 50)
    p1 = gp_Pnt(-20, -20, -50)
    pts, crv = spl_curv_pts([p0, p1])
    pln = make_plane(vec_normal=gp_Vec(0, 1, 1))
    h_surf = BRep_Tool.Surface(pln)
    api = GeomAPI_IntCS(crv, h_surf)
    print(api.IsDone())
    print(api.NbSegments())

    uvw = api.Parameters(1)
    u, v, w = uvw
    pnt_crv = gp_Pnt()
    pnt_1st = gp_Pnt()
    pnt_2nd = gp_Pnt()
    pnt_srf = gp_Pnt()
    GeomLProp_CurveTool.Value(crv, w, pnt_crv)
    GeomLProp_CurveTool.Value(crv, 0, pnt_1st)
    GeomLProp_CurveTool.Value(crv, 1, pnt_2nd)
    GeomLProp_SurfaceTool.Value(h_surf, u, v, pnt_srf)
    print(uvw)
    print(pnt_crv)
예제 #20
0
 def check_ground(self):
     if len(self.pts) > 2:
         ray = make_edge(self.pts[-2], self.pts[-1])
         h_line = BRep_Tool.Curve(ray)
         h_surf = BRep_Tool.Surface(self.grd)
         print(GeomAPI_IntCS(h_line, h_surf))
예제 #21
0
points2 = []
points2.append(Point(-4, 0, 2))
points2.append(Point(-2, 2, 0))
points2.append(Point(2, 3, -1))
points2.append(Point(3, 7, -2))
points2.append(Point(4, 9, -1))
spline2 = BSplineCurve.from_points(points2)

surface = BSplineSurface.from_fill(spline1, spline2)
line = Geom_Line(gp_Pnt(0, 4, 0), gp_Dir(0, 0, 1))

# ==============================================================================
# Intersection
# ==============================================================================

intersection = GeomAPI_IntCS(line, surface.occ_surface)

pnt = intersection.Point(1)
point = Point.from_occ(pnt)

# ==============================================================================
# Viz
# ==============================================================================

mesh = surface.to_vizmesh()
boundary = Polyline(
    mesh.vertices_attributes('xyz', keys=mesh.vertices_on_boundary()))

view = App()
view.add(mesh)
view.add(boundary, linewidth=2)
예제 #22
0
    # obj.show_ball()

    axs = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 1, 1))
    elp = gen_ellipsoid(axs, [10, 20, 30])
    obj.display.DisplayShape(elp, transparency=0.7, color="BLUE")
    obj.show_axs_pln(axs, scale=20)

    axs = gp_Ax3(gp_Pnt(30, 0, 0), gp_Dir(1, 1, 0))
    elp = gen_ellipsoid(axs, [10, 20, 30])
    obj.display.DisplayShape(elp, transparency=0.7, color="BLUE")
    obj.show_axs_pln(axs, scale=20)

    #elp = gen_ellipsoid_geom(axs, [10, 20, 30])

    top_api = Topo(elp)
    print(top_api.number_of_faces())
    for face in top_api.faces():
        elp_face = face

    print(elp_face)
    elp_surf = BRep_Tool_Surface(elp_face)
    print(elp_surf)

    lin = Geom_Line(gp_Ax1(axs.Location(), gp_Dir(0, 1, 1)))
    api = GeomAPI_IntCS(lin, elp_surf)
    obj.display.DisplayShape(lin)
    print(api.Point(1))
    print(api.Point(2))

    obj.show()
예제 #23
0
    surf = BRep_Tool.Surface(face)
    surf.Rotate(gp_Ax1(ax0.Location(), ax0.Direction()), np.deg2rad(15))

    ax1 = gp_Ax3(gp_Pnt(150, 150, -20),
                 gp_Dir(0.5, 0.1, 1.0),
                 gp_Dir(0.0, 0.1, 1.0))
    pnt = ax1.Location()
    api = GeomAPI_ProjectPointOnSurf(pnt, surf)
    print(api.NbPoints(), api.NearestPoint())
    for i in range(api.NbPoints()):
        idx = i + 1
        u, v = api.Parameters(idx)
        obj.display.DisplayShape(api.Point(idx))
        print(idx, u, v)

    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()))