当前位置: 首页>>代码示例>>Python>>正文


Python gp.gp_Dir函数代码示例

本文整理汇总了Python中OCC.gp.gp_Dir函数的典型用法代码示例。如果您正苦于以下问题:Python gp_Dir函数的具体用法?Python gp_Dir怎么用?Python gp_Dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了gp_Dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

 def execute(self):
     ax = gp.gp_Ax2(gp.gp_Pnt(*self.position),
                     gp.gp_Dir(*self.z_axis),
                     gp.gp_Dir(*self.x_axis))
     m_box = BRepPrimAPI.BRepPrimAPI_MakeBox(ax, *self.dims)
     self.update_naming(m_box)
     return m_box.Shape()
开发者ID:mortbauer,项目名称:pythonocc,代码行数:7,代码来源:occ_model.py

示例2: get_transform

 def get_transform(self):
     d = self.declaration
     t = gp_Trsf()
     #: TODO: Order matters... how to configure it???
     if d.mirror:
         try:
             p,v = d.mirror
         except ValueError:
             raise ValueError("You must specify a tuple containing a (point,direction)")
         t.SetMirror(gp_Ax1(gp_Pnt(*p),
                            gp_Dir(*v)))
     if d.scale:
         try:
             p,s = d.scale
         except ValueError:
             raise ValueError("You must specify a tuple containing a (point,scale)")
         t.SetScale(gp_Pnt(*p),s)
     
     if d.translate:
         t.SetTranslation(gp_Vec(*d.translate))
     
     if d.rotate:
         try:
             p,v,a = d.rotate
         except ValueError:
             raise ValueError("You must specify a tuple containing a (point,direction,angle)")
         t.SetRotation(gp_Ax1(gp_Pnt(*p),
                            gp_Dir(*v)),a)
         
     return t
开发者ID:frmdstryr,项目名称:enamlx,代码行数:30,代码来源:occ_algo.py

示例3: tangent

 def tangent(self, u, v):
     dU, dV = gp_Dir(), gp_Dir()
     curv = self.curvature(u, v)
     if curv.IsTangentUDefined() and curv.IsTangentVDefined():
         curv.TangentU(dU), curv.TangentV(dV)
         return dU, dV
     else:
         return None, None
开发者ID:tpaviot,项目名称:pythonocc-utils,代码行数:8,代码来源:face.py

示例4: through_sections

def through_sections():
    #ruled
    circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)), 40.)
    wire_1 = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire()
    circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2 = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire()
    circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.)
    wire_3 = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire()
    circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.)
    wire_4 = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire()

    generatorA = BRepOffsetAPI_ThruSections(False, True)
    map(generatorA.AddWire, [wire_1, wire_2, wire_3, wire_4])
    generatorA.Build()
    display.DisplayShape(generatorA.Shape())

    #smooth
    circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)), 40.)
    wire_1b = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire()
    circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2b = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire()
    circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)), 40.)
    wire_3b = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire()
    circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)), 40.)
    wire_4b = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire()
    generatorB = BRepOffsetAPI_ThruSections(True, False)
    map(generatorB.AddWire, [wire_1b, wire_2b, wire_3b, wire_4b])
    generatorB.Build()
    display.DisplayShape(generatorB.Shape(), update=True)
开发者ID:anwar-hegazy,项目名称:pythonocc-core,代码行数:29,代码来源:core_topology_through_sections.py

示例5: edge

def edge(event=None):
    # The blud edge
    BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20),
                                       gp_Pnt(-30, -60, -60))
    V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30))
    V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25))
    YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex())

    #The white edge
    line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0)))
    WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10)

    #The red edge
    Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30)
    RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi/2)

    # The green edge and the both extreme vertex
    P1 = gp_Pnt(-15, 200, 10)
    P2 = gp_Pnt(5, 204, 0)
    P3 = gp_Pnt(15, 200, 0)
    P4 = gp_Pnt(-15, 20, 15)
    P5 = gp_Pnt(-5, 20, 0)
    P6 = gp_Pnt(15, 20, 0)
    P7 = gp_Pnt(24, 120, 0)
    P8 = gp_Pnt(-24, 120, 12.5)
    array = TColgp_Array1OfPnt(1, 8)
    array.SetValue(1, P1)
    array.SetValue(2, P2)
    array.SetValue(3, P3)
    array.SetValue(4, P4)
    array.SetValue(5, P5)
    array.SetValue(6, P6)
    array.SetValue(7, P7)
    array.SetValue(8, P8)
    curve = Geom_BezierCurve(array)
    ME = BRepBuilderAPI_MakeEdge(curve.GetHandle())
    GreenEdge = ME
    V3 = ME.Vertex1()
    V4 = ME.Vertex2()

    display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE')
    display.DisplayShape(V1.Vertex())
    display.DisplayShape(V2.Vertex())
    display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE')
    display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW')
    display.DisplayColoredShape(RedEdge.Edge(), 'RED')
    display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN')
    display.DisplayShape(V3)
    display.DisplayShape(V4, update=True)
开发者ID:CrazyHeex,项目名称:pythonocc-core,代码行数:49,代码来源:core_topology_edge.py

示例6: rotate

def rotate(occtopology, rot_pypt, pyaxis, degree):
    """
    This function rotates an OCCtopology based on the rotation point, an axis and the rotation degree.
 
    Parameters
    ----------        
    occtopology : OCCtopology
        The OCCtopology to be rotated.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 
        
    rot_pypt : tuple of floats
        The OCCtopology will rotate in reference to this point.
        A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z)
        
    pyaxis : tuple of floats
        The OCCtopology will rotate along this axis.
        A pyaxis is a tuple that documents the xyz of a direction e.g. (x,y,z)
        
    degree : float
       The degree of rotation.
        
    Returns
    -------
    rotated topology : OCCtopology (OCCshape)
        The rotated OCCtopology.
    """
    
    from math import radians
    gp_ax3 = gp_Ax1(gp_Pnt(rot_pypt[0], rot_pypt[1], rot_pypt[2]), gp_Dir(pyaxis[0], pyaxis[1], pyaxis[2]))
    aTrsf = gp_Trsf()
    aTrsf.SetRotation(gp_ax3, radians(degree))
    rot_brep = BRepBuilderAPI_Transform(aTrsf)
    rot_brep.Perform(occtopology, True)
    rot_shape = rot_brep.Shape()
    return rot_shape
开发者ID:chenkianwee,项目名称:envuo,代码行数:35,代码来源:modify.py

示例7: AddCone

def AddCone(BasePoint, Radius, height, direction=gp_Dir(1, 0, 0)):
    """Generates a cone shape originating at BasePoint with base Radius
    and height (points in the direction of input 'direction)

    Parameters
    ----------
    BasePoint : OCC.gp.gp_Pnt or array length 3
        The centre base point

    Radius : scalar
        Cone base radius

    height : scalar
        Cone height

    direction : OCC.gp.gp_Dir  (default: positive x direction)
        the direction of the cones axis i.e. normal to the base:
        defaults to x axis

    Returns
    -------
    shape : TopoDS_Shape
        The generated Cone
    """
    try:
        BasePoint = gp_Pnt(*BasePoint)
    except:
        pass
    ax2 = gp_Ax2(BasePoint, direction)
    cone = BRepPrimAPI_MakeCone(ax2, Radius, 0, height)
    return cone.Shape()
开发者ID:p-chambers,项目名称:occ_airconics,代码行数:31,代码来源:AirCONICStools.py

示例8: test_project_curve_to_plane

def test_project_curve_to_plane():
    # Projects a line of length 1 from above the XOY plane, and tests points
    # on the resulting line
    from OCC.Geom import Geom_Plane, Geom_TrimmedCurve
    from OCC.GC import GC_MakeSegment
    from OCC.gp import gp_Ax3, gp_XOY, gp_Pnt, gp_Dir
    XOY = Geom_Plane(gp_Ax3(gp_XOY()))
    curve = GC_MakeSegment(gp_Pnt(0, 0, 5),
                           gp_Pnt(1, 0, 5)).Value()
    direction = gp_Dir(0, 0, 1)

    Hproj_curve = act.project_curve_to_plane(curve, XOY.GetHandle(),
                                            direction)

    proj_curve = Hproj_curve.GetObject()

    # The start and end points of the curve
    p1 = proj_curve.Value(0)
    p2 = proj_curve.Value(1)

    p1_array = np.array([p1.X(), p1.Y(), p1.Z()])
    p2_array = np.array([p2.X(), p2.Y(), p2.Z()])

    # The expected start and end points
    start = np.array([0, 0, 0])
    end = np.array([1, 0, 0])

    # Assert that neither points have a Y or Z component, and that
    assert((np.all(p1_array == start) and np.all(p2_array == end)) or
           (np.all(p1_array == end) and np.all(p2_array == start)))
开发者ID:p-chambers,项目名称:occ_airconics,代码行数:30,代码来源:test_AirCONICStools.py

示例9: pipe

def pipe(event=None):
  CurvePoles = TColgp_Array1OfPnt(1,6)
  pt1 = gp_Pnt(0.,0.,0.);
  pt2 = gp_Pnt(20.,50.,0.);
  pt3 = gp_Pnt(60.,100.,0.);
  pt4 = gp_Pnt(150.,0.,0.);
  CurvePoles.SetValue(1, pt1)
  CurvePoles.SetValue(2, pt2)
  CurvePoles.SetValue(3, pt3)
  CurvePoles.SetValue(4, pt4)

  curve = Geom_BezierCurve(CurvePoles)
  print type(curve)
  E = BRepBuilderAPI_MakeEdge(curve.GetHandle()).Edge()
  W = BRepBuilderAPI_MakeWire(E).Wire()
   
  #ais1 = AIS_Shape(W)
  #self.interactive_context.Display(ais1,1)
   
  c = gp_Circ(gp_Ax2(gp_Pnt(0.,0.,0.),gp_Dir(0.,1.,0.)),10.)
  Ec = BRepBuilderAPI_MakeEdge(c).Edge()
  Wc = BRepBuilderAPI_MakeWire(Ec).Wire()

  #ais3 = AIS_Shape(Wc)
  #self.interactive_context.Display(ais3,1)
   
  F = BRepBuilderAPI_MakeFace(gp_Pln(gp_Ax3(gp.gp().ZOX())),Wc,1).Face()
  MKPipe = BRepOffsetAPI_MakePipe(W,F)
  MKPipe.Build()
  display.DisplayShape(MKPipe.Shape())
开发者ID:davad,项目名称:cntsim,代码行数:30,代码来源:test-make-pipe.py

示例10: slicer

def slicer(event=None):
    # Param
    Zmin, Zmax, deltaZ = -100, 100, 5
    # Note: the shape can also come from a shape selected from InteractiveViewer
    if 'display' in dir():
        shape = display.GetSelectedShape()
    else:
        # Create the shape to slice
        shape = BRepPrimAPI_MakeSphere(60.).Shape()
    # Define the direction
    D = gp_Dir(0., 0., 1.)  # the z direction
    # Perform slice
    sections = []
    init_time = time.time()  # for total time computation
    for z in range(Zmin, Zmax, deltaZ):
        # Create Plane defined by a point and the perpendicular direction
        P = gp_Pnt(0, 0, z)
        Pln = gp_Pln(P, D)
        face = BRepBuilderAPI_MakeFace(Pln).Shape()
        # Computes Shape/Plane intersection
        section = BRepAlgoAPI_Section(shape, face)
        if section.IsDone():
            sections.append(section)
    total_time = time.time() - init_time
    print("%.3fs necessary to perform slice." % total_time)

    display.EraseAll()
    display.DisplayShape(shape)
    for section in sections:
        display.DisplayShape(section.Shape())
    display.FitAll()
开发者ID:CrazyHeex,项目名称:pythonocc-core,代码行数:31,代码来源:core_topology_boolean.py

示例11: occ

def occ(display):

 	'''
	display, start_display, add_menu, add_function_to_menu = init_display()
	my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
 
	display.DisplayShape(my_box, update=True)
	#start_display()
	'''
	

	display.EraseAll()
	ais_boxshp = build_shape(display)
	ax1 = gp_Ax1(gp_Pnt(25., 25., 25.), gp_Dir(0., 0., 1.))
	aCubeTrsf = gp_Trsf() 
	angle = 0.0
	tA = time.time()
	n_rotations = 200
	for i in range(n_rotations):
		aCubeTrsf.SetRotation(ax1, angle)
		aCubeToploc = TopLoc_Location(aCubeTrsf)
		display.Context.SetLocation(ais_boxshp, aCubeToploc)
		display.Context.UpdateCurrentViewer()
		angle += 2*pi / n_rotations
	print("%i rotations took %f" % (n_rotations, time.time() - tA))
	
	
	
	
	
开发者ID:small-yellow-duck,项目名称:timelordart,代码行数:25,代码来源:facedetect_render3d_v2.py

示例12: mirror

def mirror(brep, plane='xz', axe2=None, copy=False):
    """Originally from pythonocc-utils : might add dependency on this?
    Mirrors object

    Parameters
    ----------
    brep : OCC.TopoDS.TopoDS_Shape
        The shape to mirror

    plane : string (default = 'xz')
        The name of the plane in which to mirror objects. Acceptable inputs are
        any of 'xy', 'yx' , 'zy', 'yz', 'yz', 'zy'. Overwritten if axe2 is
        defined.

    axe2 : OCC.gp.gp_Ax2
        The axes through which to mirror (overwrites input 'plane')

    copy : bool
        
    Returns
    -------
    BRepBuilderAPI_Transform.Shape : TopoDS_Shape
        The reflected shape
    
    Notes
    -----
    Pchambers: Added a functionality here to specify a plane using a string so
    that users could avoid interacting with core occ objects"""
    if axe2:
        plane = None
    else:
        Orig = gp_Pnt(0., 0., 0.)        
        if plane in ['xz', 'zx']:
            ydir = gp_Dir(0, 1, 0)
            axe2 = gp_Ax2(Orig, ydir)
        elif plane in ['yz', 'zy']:
            xdir = gp_Dir(1, 0, 0)
            axe2 = gp_Ax2(Orig, xdir)
        elif plane in ['xy', 'yx']:
            zdir = gp_Dir(0, 0, 1)
            axe2 = gp_Ax2(Orig, zdir)
        else:
            raise(ValueError, "Unknown mirror plane string,", plane)
    trns = gp_Trsf()
    trns.SetMirror(axe2)
    brep_trns = BRepBuilderAPI_Transform(brep, trns, copy)
    return brep_trns.Shape()
开发者ID:p-chambers,项目名称:occ_airconics,代码行数:47,代码来源:AirCONICStools.py

示例13: rotate

 def rotate(self, angle, axis):
     ax = gp_Ax1(gp_Pnt(*axis[:3]), gp_Dir(*axis[3:]))
     tr = gp_Trsf()
     tr.SetRotation(ax, angle)
     loc = TopLoc_Location(tr)
     self.shape =  BRepBuilderAPI_Transform(self.shape, tr).Shape()
     self.__extract_curves()
     return self
开发者ID:wgryglas,项目名称:wgpy,代码行数:8,代码来源:curve2D.py

示例14: generate_shape

def generate_shape():
    """Create a sphere with faces top and bottom"""
    sphere_radius = 1.0
    sphere_angle = atan(0.5)
    sphere_origin = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    sphere = BRepPrimAPI_MakeSphere(sphere_origin, sphere_radius,
                                    -sphere_angle, sphere_angle).Shape()
    return sphere
开发者ID:gideonmay,项目名称:pythonocc-core,代码行数:8,代码来源:core_modeling_bool_demo.py

示例15: CutSect

def CutSect(Shape, SpanStation):
    """
    Parameters
    ----------
    Shape : TopoDS_Shape
        The Shape to find planar cut section (parallel to xz plane)

    SpanStation : scalar in range (0, 1)
        y-direction location at which to cut Shape

    Returns
    -------
    Section : result of OCC.BRepAlgoAPI.BRepAlgoAPI_Section (TopoDS_Shape)
        The cut section of shape given a cut plane parallel to xz at input
        Spanstation.

    Chord : result of OCC.GC.GC_MakeSegment.Value (Geom_TrimmedCurve)
        The Chord line between x direction extremeties
    """
    (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = ObjectsExtents([Shape])

    YStation = Ymin + (Ymax - Ymin) * SpanStation
    OriginX = Xmin - 1
    OriginZ = Zmin - 1

    P = gp_Pln(gp_Pnt(OriginX, YStation, OriginZ), gp_Dir(gp_Vec(0, 1, 0)))
    # Note: using 2*extents here as previous +1 trimmed plane too short
    CutPlaneSrf = make_face(P, 0, Zmax + 2, 0, Xmax +2)

    I = BRepAlgoAPI_Section(Shape, CutPlaneSrf)
    I.ComputePCurveOn1(True)
    I.Approximation(True)
    I.Build()
    Section = I.Shape()

    (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = ObjectsExtents([Section])

#     Currently assume only one edge exists in the intersection:
    exp = TopExp_Explorer(Section, TopAbs_EDGE)
    edge = topods_Edge(exp.Current())

#    Find the apparent chord of the section (that is, the line connecting the
#    fore most and aftmost points on the curve
    DivPoints = Uniform_Points_on_Curve(edge, 200)

    Xs = np.array([pt.X() for pt in DivPoints])

    min_idx = np.argmin(Xs)
    LeadingPoint = gp_Pnt(Xs[min_idx], DivPoints[min_idx].Y(),
                          DivPoints[min_idx].Z())

    max_idx = np.argmax(Xs)
    TrailingPoint = gp_Pnt(Xs[max_idx], DivPoints[max_idx].Y(),
                           DivPoints[max_idx].Z())

    HChord = GC_MakeSegment(TrailingPoint, LeadingPoint).Value()
#    Chord = HChord.GetObject()
    return Section, HChord
开发者ID:p-chambers,项目名称:occ_airconics,代码行数:58,代码来源:AirCONICStools.py


注:本文中的OCC.gp.gp_Dir函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。