예제 #1
0
    def setPts(self):
        #外周点
        pt0 = [0, 0, 0]
        pt1 = [self.l, 0, 0]
        pt1 = rs.VectorRotate(pt1, self.angle / 2.0, [0, 0, 1])
        pt3 = [self.l, 0, 0]
        pt3 = rs.VectorRotate(pt3, -self.angle / 2.0, [0, 0, 1])
        pt2 = rs.VectorAdd(pt1, pt3)
        self.pts.append(pt0)
        self.pts.append(pt1)
        self.pts.append(pt2)
        self.pts.append(pt3)

        #中点
        for i in range(len(self.pts)):
            if (i == len(self.pts) - 1):
                pt = rs.VectorAdd(self.pts[i], self.pts[0])
                pt = rs.VectorDivide(pt, 2)
            else:
                pt = rs.VectorAdd(self.pts[i], self.pts[i + 1])
                pt = rs.VectorDivide(pt, 2)
            self.midPts.append(pt)

        #楕円
        pt0 = rs.VectorDivide(self.pts[2], 2.0)
        l0 = self.l * math.sin(math.radians(90 / 2.0))
        l1 = self.l * math.cos(math.radians(self.angle / 2.0))
        l2 = self.l * math.sin(math.radians(self.angle / 2.0))
        pt1 = rs.VectorScale([self.l / 2.0, 0, 0], l1 / l0)
        pt1 = rs.VectorAdd(pt0, pt1)
        pt2 = rs.VectorScale([0, self.l / 2.0, 0], l2 / l0)
        pt2 = rs.VectorAdd(pt0, pt2)
        self.ellipsePts.append(pt0)
        self.ellipsePts.append(pt1)
        self.ellipsePts.append(pt2)
 def defineEnds(self):
     self.vec01 = rs.VectorRotate(self.vec, self.ang, self.axis)
     self.vec02 = rs.VectorRotate(self.vec, -self.ang, self.axis)
     self.end01 = rs.PointAdd(self.start, self.vec01)
     self.end02 = rs.PointAdd(self.start, self.vec02)
     self.defined = True
     return [self.end01, self.vec01, self.end02, self.vec02]
예제 #3
0
    def drawQuadTab(self, island):
        pntA, pntD = self.get_coordinates(island)
        vecA = geom.Vector3d(pntA)
        vecD = geom.Vector3d(pntD)

        alpha = self.tabAngles[0]
        beta = self.tabAngles[1]

        lenI = self.tabWidth / math.sin(alpha * math.pi / 180.0)
        lenJ = self.tabWidth / math.sin(beta * math.pi / 180.0)

        if not self.tabOnLeft:
            alpha = -1 * alpha
            beta = -1 * beta

        vec = vecD.Subtract(vecD, vecA)
        vecUnit = rs.VectorUnitize(vec)
        vecI = rs.VectorScale(vecUnit, lenI)
        vecJ = rs.VectorScale(vecUnit, -lenJ)

        vecI = rs.VectorRotate(vecI, alpha, [0, 0, 1])
        vecJ = rs.VectorRotate(vecJ, -beta, [0, 0, 1])
        vecB = vecA + vecI
        vecC = vecD + vecJ

        pntB = geom.Point3d(vecB)
        pntC = geom.Point3d(vecC)

        points = [pntA, pntB, pntC, pntD]
        polyGuid = rs.AddPolyline(points)

        self.geom.append(polyGuid)
        return polyGuid
예제 #4
0
def drawBranch(origin, dir, minDistance, maxDistance, maxAngle):
    vecTwig = rs.VectorUnitize(dir)
    vecTwig = rs.VectorScale(vecTwig, minDistance+random.random()*(maxDistance-minDistance))
    mutationPlane = rs.PlaneFromNormal((0, 0, 0), vecTwig)
    vecTwig = rs.VectorRotate(vecTwig, random.random()*maxAngle, mutationPlane[1])
    vecTwig = rs.VectorRotate(vecTwig, random.random()*360, dir)
    return rs.PointAdd(origin, vecTwig)
예제 #5
0
def RandomPointInCone(origin, direction, minDistance, maxDistance, maxAngle):
    vecTwig = rs.VectorUnitize(direction)
    vecTwig = rs.VectorScale(vecTwig, minDistance + random.random()*(maxDistance-minDistance))
    MutationPlane = rs.PlaneFromNormal((0,0,0), vecTwig)
    vecTwig = rs.VectorRotate(vecTwig, random.random()*maxAngle, MutationPlane[1])
    vecTwig = rs.VectorRotate(vecTwig, random.random()*360, direction)
    return rs.PointAdd(origin, vecTwig)
def pointtocone(origin, direction, mindis, maxdis, maxangle):
    vectwig = rs.VectorUnitize(direction)
    vectwig = rs.VectorScale(vectwig, random.uniform(mindis, maxdis))
    mutationplane = rs.PlaneFromNormal((0, 0, 0), vectwig)
    vectwig = rs.VectorRotate(vectwig,
                              random.random() * maxangle, mutationplane[1])
    vectwig = rs.VectorRotate(vectwig, random.random() * 360, direction)
    return rs.PointAdd(origin, vectwig)
예제 #7
0
def quad_rotate_point(point, center_point=(0, 0, 0), axis=(0, 0, 1)):
    _vec = rss.PointSubtract(point, center_point)
    return [
        point,
        rss.PointAdd(center_point, rss.VectorRotate(_vec, 90.0, axis)),
        rss.PointAdd(center_point, rss.VectorRotate(_vec, 180.0, axis)),
        rss.PointAdd(center_point, rss.VectorRotate(_vec, -90.0, axis)),
    ]
예제 #8
0
    def RunScript(self, Listener_Location, Direction, Height):

        __author__ = "theomarchal"
        self.Params.Input[
            0].Description = "Location of the listener foots (as a point - Default is set to 0,0,0)"
        self.Params.Input[
            1].Description = "Direction of the listener (in degrees from 0 to 360)"
        self.Params.Input[
            2].Description = "How tall is the listener (default = 1.80)"
        self.Params.Output[
            0].Description = "Listener Geometry, size and direction"
        self.Params.Output[
            1].Description = "Listener Object (plug it into EsquisSons)"
        self.Name = "Listener Point"
        self.NickName = "Listener"
        self.Message = "EsquisSons V3"
        self.Category = "EsquisSons"
        self.SubCategory = "1/ Scene"

        import rhinoscriptsyntax as rs

        LL = Listener_Location
        LD = Direction
        LH = Height

        if LL is None:
            LL = rs.AddPoint(0, 0, 0)
        if LD is None:
            LD = 0
        if LH is None:
            LH = 1.8

        LV = rs.VectorRotate([0, (LH), 0], LD, [0, 0, 1])
        matrix = rs.XformTranslation((0, 0, LH))
        LHp = rs.PointTransform(LL, matrix)
        LV2 = rs.VectorScale((rs.VectorRotate(LV, 90, [0, 0, 1])), 0.5)
        LV3 = rs.VectorScale((rs.VectorRotate(LV, -90, [0, 0, 1])), 0.5)
        T1 = rs.PointTransform(LL, (rs.XformTranslation(LV)))
        Tl = rs.PointTransform(LL, (rs.XformTranslation(LV2)))
        Tr = rs.PointTransform(LL, (rs.XformTranslation(LV3)))
        ps = [T1, Tl, Tr]
        Geo = [
            rs.AddSphere(LHp, (LH / 10)),
            rs.AddLine(LL, LHp),
            rs.AddSrfPt(ps)
        ]
        Tl = rs.PointTransform(Tl, matrix)
        Tr = rs.PointTransform(Tr, matrix)
        LP = [LHp, Tl, Tr, LH]
        Listener = [LP]
        return (Geo, Listener)
예제 #9
0
def branch (line,ang):
    
    startPt = rs.CurveStartPoint(line)
    endPt   = rs.CurveEndPoint(line)
    vec     = rs.VectorCreate(endPt,startPt)
    vec1    = rs.VectorRotate (vec,ang,[0,0,1])
    vec2    = rs.VectorRotate (vec,-ang,[0,0,1]) 
    
    endPt1  = rs.PointAdd(endPt,vec1)
    endPt2  = rs.PointAdd(endPt,vec2)
    
    line1   = rs.AddLine(endPt,endPt1)
    line2   = rs.AddLine(endPt,endPt2)
    return (line1,line2)
예제 #10
0
def Elt(refpt,dir,data):
    
    
    xform = Transform(dir,rs.VectorRotate(dir,90,[0,0,1]),refpt)
    
    L = []
    R = []
    
    
    for point in data[2]:
        
        trans = rs.VectorTransform(point,xform)
        trans = rs.VectorAdd(trans,refpt)
        L.append(trans)
        
    
    for point in data[3]:
        
        trans = rs.VectorTransform(point,xform)
        trans = rs.VectorAdd(trans,refpt)
        R.append(trans)
        
    
    trans = rs.VectorTransform(data[4],xform)
    
    return [trans,L,R]
예제 #11
0
 def grow(self, side):
     newBranches = []
     if len(self.branches) == 0:
         self.startBranch()
     for i in range(len(self.branches)):
         self.pullBranch(self.branches[i])
         axis01 = self.findAxis(self.branches[i].end01)
         axis02 = self.findAxis(self.branches[i].end02)
         if rs.VectorAngle(self.branches[i].axis,
                           axis01) < 60 and side == 1:
             param = rs.CurveClosestPoint(self.path, self.branches[i].end01)
             dist = rs.Distance(self.branches[i].end01,
                                rs.EvaluateCurve(self.path, param))
             tan = rs.CurveTangent(self.path, param)
             newBranches.append(
                 branch(self.branches[i].end01, self.branches[i].vec01,
                        self.ang, axis01))
         if rs.VectorAngle(self.branches[i].axis,
                           axis02) < 60 and side == 2:
             param = rs.CurveClosestPoint(self.path, self.branches[i].end02)
             dist = rs.Distance(self.branches[i].end02,
                                rs.EvaluateCurve(self.path, param))
             tan = rs.CurveTangent(self.path, param)
             vecAng = rs.VectorAngle(self.branches[i].vec02, tan)
             vec = rs.VectorRotate(self.branches[i].vec02, -vecAng / 5,
                                   axis02)
             newBranches.append(
                 branch(self.branches[i].end02, self.branches[i].vec02,
                        self.ang, axis02))
     self.branches = []
     self.branches.extend(newBranches)
     return self.branches
예제 #12
0
def get_reference_vector(b_obj):
	"""pick a reference vector for deciding surface category.
	note that we can't pick [0,1,0] because the brep might be on a 45deg angle."""
	base_ref_vect = rs.VectorCreate([0,1,0],[0,0,0])
	up = rs.coerce3dvector([0,0,1])
	down = rs.coerce3dvector([0,0,-1])
	epsilon = 0.5
	
	faces = b_obj.Faces
	print faces.Count
	
	ref_faces = []
	ref_angle_rotation = 90
	for k in faces:
		v = k.NormalAt(0.5,0.5) #top and botom of extrusion have IsSurface = False (why?)
		if not (v.EpsilonEquals(up,epsilon) or v.EpsilonEquals(down,epsilon)):
			ref_faces.append(k)
			angle = rs.VectorAngle(v,base_ref_vect)
			angle = angle%90
			print angle
			ref_angle_rotation = min(ref_angle_rotation,angle)
	
	new_ref_vector = rs.VectorRotate(base_ref_vect,ref_angle_rotation,[0,0,1])
	#debug: verify this angle is good
#	for k in faces:
#		v = k.NormalAt(0.5,0.5) #top and botom of extrusion have IsSurface = False (why?)
#		if not (v.EpsilonEquals(up,epsilon) or v.EpsilonEquals(down,epsilon)):
#			ref_faces.append(k)
#			angle = rs.VectorAngle(v,new_ref_vector)
#			angle = angle%180
#			print angle
	
	return new_ref_vector
예제 #13
0
    def deflect(self, deflectPoint):
        """
        Takes a Point as an input.
        Point creates a force field.
        The turtle deflects around the point
        """
        defPtPos = rs.PointCoordinates(deflectPoint)
        prevPos = rs.PointCoordinates(self.point)
        deflectVector1 = rs.VectorScale(rs.VectorCreate(prevPos, defPtPos),
                                        0.33)
        deflectVector2 = -deflectVector1
        deflectVector90_1 = rs.VectorScale(
            rs.VectorRotate(deflectVector1, 90, [0, 0, 1]), 0.33)
        deflectVector90_2 = -deflectVector90_1

        deflectVectorList = [
            deflectVector1, deflectVector2, deflectVector90_1,
            deflectVector90_2
        ]

        forcePts = []
        for i in deflectVectorList:
            newPt = rs.CopyObject(deflectPoint)
            rs.MoveObject(newPt, i)
            forcePts.append(newPt)

        gotoPt = rs.PointCoordinates(forcePts[0])

        self.goto(gotoPt[0], gotoPt[1])
        rs.AddArc3Pt(forcePts[0], forcePts[1], forcePts[2])
        rs.AddArc3Pt(forcePts[1], forcePts[0], forcePts[3])
        rs.DeleteObjects(forcePts)
예제 #14
0
파일: util.py 프로젝트: BeyondGu/p4r-demo
def drawBox( side, location, angle_degrees1, angle_degrees2):
    """画一个2D方块
    参数:
      side(double): 方块的长度, double 
      locaiton(tuple(double, double,double)): 方块中心的位置
      angle_degrees1(double): xy平面旋转角度degree1
      angle_degrees2(double): 到达位置后继续朝z轴方向旋转角度degree2
    Returns:
      guid
    """
    corners = []
    corners.append((-side/2,-side/2,0))
    corners.append(( side/2,-side/2,0))
    corners.append((side/2,side/2,0))
    corners.append((-side/2,side/2,0)) 
    corners.append((-side/2,-side/2,side))
    corners.append((side/2,-side/2,side))
    corners.append((side/2,side/2,side))
    corners.append((-side/2,side/2,side))
    obj = rs.AddBox(corners)

    xform = rs.XformRotation2(angle_degrees1, (0,0,1), (0,0,0))
    obj = rs.TransformObject( obj, xform, False )
    vectorR1 = rs.VectorRotate( (1,0,0), angle_degrees1, (0,0,0))
    vectorR2 = rs.VectorCrossProduct(vectorR1, (0,0,1))
    xform = rs.XformRotation2(angle_degrees1, vectorR2, (0,0,0))
    obj = rs.TransformObject( obj, xform, False )
    xform = rs.XformTranslation( location)
    obj = rs.TransformObject( obj, xform, False )

    return obj 
예제 #15
0
def offsetLine(line, dist):
    norm = rs.VectorRotate(rs.CurveTangent(line, rs.CurveParameter(line, 0)),
                           90, [0, 0, 1])
    norm = rs.VectorScale(rs.VectorUnitize(norm), dist)
    sideStPt = rs.VectorAdd(rs.CurveStartPoint(line), norm)
    sideEndPt = rs.VectorAdd(rs.CurveEndPoint(line), norm)
    newLine = rs.AddLine(sideStPt, sideEndPt)
    return newLine
예제 #16
0
    def respond(self):
        i = random.uniform(1, 100)

        #ROTATE VECTORS HEADING LEFT TO THE RIGHT - IE TURN RIGHT
        if self.x_difference < 0:
            if self.z_difference < 0:
                self.vel = rs.VectorRotate(self.vel, -i, (0, 0, 1))

        #ROTATE VECTORS HEADING RIGHT TO THE LEFT - IE TURN LEFT
        elif self.x_difference > 0:
            if self.z_difference < 0:
                self.vel = rs.VectorRotate(self.vel, i, (0, 0, 1))

        # ROTATE VECTORS GOING STRAIGHT
        else:
            if self.z_difference < 0:
                self.vel = rs.VectorRotate(self.vel, -45, (0, 0, 1))
예제 #17
0
def getTwoParallelLineSelectionRegion(p0, p1, pi, width):
    lineDirect = rs.VectorUnitize(rs.VectorCreate(p1, p0))
    lineCross = rs.VectorRotate(lineDirect, 90, (0, 0, 1))
    piUp = rs.VectorAdd(pi, rs.VectorScale(lineCross, width))
    piDown = rs.VectorAdd(pi, rs.VectorScale(rs.VectorReverse(lineCross),
                                             width))
    piDownRight = rs.VectorAdd(piDown, lineDirect * width)
    return (geo.Point3d(piUp), geo.Point3d(piDown), geo.Point3d(piDownRight))
예제 #18
0
def drawOpening(distance, length, block=0):
    if block == 1 and rs.IsBlock("window") == False:
        util.initWindowBlock()
    if block == 2 and rs.IsBlock("door") == False:
        util.initDoorBlock()
    if not rs.IsLayer("Axis"):
        util.initCaadLayer("Axis")

    twoLines = findTwoParallelLines()
    if not twoLines:
        return 0
    pi, linei, linej = twoLines
    if not linej:
        return 0
    pj = linej.CurveGeometry.Line.ClosestPoint(pi, False)

    oldLockMode = rs.LayerLocked("Axis", True)
    # side=0 start from startPoint , side=1 start from endPoint
    if rs.Distance(linei.CurveGeometry.Line.From, pi) <= rs.Distance(
            pi, linei.CurveGeometry.Line.To):
        side = 0
    else:
        side = 1

    # direct:
    #  0 | 1
    # -------
    #  2 | 3
    vji = rs.VectorCreate(pj, pi)
    vi = linei.CurveGeometry.Line.Direction
    angle = rs.Angle((0, 0, 0),
                     rs.VectorRotate(vji, -rs.Angle((0, 0, 0), vi)[0],
                                     (0, 0, 1)))
    if abs(angle[0] - 90) < sc.doc.ModelAbsoluteTolerance:
        line0 = linei
        line1 = linej
        if side == 0:
            direct = 2
        else:
            direct = 3
    elif abs(angle[0] + 90) < sc.doc.ModelAbsoluteTolerance:
        line0 = linej
        line1 = linei
        if side == 0:
            direct = 0
        else:
            direct = 1

    dl = DoubleLine(line0.CurveGeometry.Line, line1.CurveGeometry.Line)
    newLayer = rs.ObjectLayer(line0.Id)
    oldLayer = rs.CurrentLayer(newLayer)
    dl.drawOpening(distance, length, side, block, direct)
    rs.DeleteObject(line0.Id)
    rs.DeleteObject(line1.Id)
    rs.CurrentLayer(oldLayer)
    rs.LayerLocked("Axis", oldLockMode)
예제 #19
0
def RunCommand(is_interactive):
    global params

    pitch_line = rs.GetObject(message="Select pitch line",
                              filter=rs.filter.curve,
                              preselect=True)
    if pitch_line is None:
        return 1  # Cancel

    if not rs.IsLine(pitch_line):
        print "Selected curve is not a line!"
        return 1  # Cancel

    rs.SelectObjects(pitch_line)

    m = rs.GetReal(message="Rack module", number=params["m"])
    pa = rs.GetReal(message="Pressure angle",
                    number=params["pa"],
                    minimum=0,
                    maximum=45)

    if m is None or pa is None:
        return 1  # Cancel

    params["m"] = m
    params["pa"] = pa

    pitch_line_center = rs.CurveMidPoint(pitch_line)
    pitch_line_start = rs.CurveStartPoint(pitch_line)
    pitch_line_end = rs.CurveEndPoint(pitch_line)
    angle, reflex_angle = rs.Angle2(line1=((0, 0, 0), (1, 0, 0)),
                                    line2=(pitch_line_start, pitch_line_end))

    x_vector = rs.VectorCreate(pitch_line_end, pitch_line_start)
    y_vector = rs.VectorRotate(x_vector, 90.0, [0, 0, 1])
    cplane = rs.PlaneFromFrame(origin=pitch_line_center,
                               x_axis=x_vector,
                               y_axis=y_vector)

    xform = rs.XformChangeBasis(cplane, rs.WorldXYPlane())

    rs.EnableRedraw(False)
    old_plane = rs.ViewCPlane(plane=rs.WorldXYPlane())

    rack = draw_rack(length=rs.CurveLength(pitch_line),
                     module=params["m"],
                     pressure_angle=params["pa"])

    rs.ViewCPlane(plane=old_plane)
    rs.TransformObjects(rack, xform)

    rs.EnableRedraw(True)
    rs.UnselectAllObjects()
    rs.SelectObjects(rack)

    return 0  # Success
예제 #20
0
def baseBranch(mesh,start,vec,ang,length,gen):
    end=rs.PointAdd(start,vec*length)
    end=rs.MeshClosestPoint(mesh,end)[0]
    branch1=rs.AddLine(start,end)
    projBranch1=rs.PullCurveToMesh(mesh,branch1)
    branches=[projBranch1]
    stored=branches
    newBranches=[]
    i=0
    count=0
    while i < gen:
        i=i+1
        for branch in branches:
            end=rs.CurveEndPoint(branch)
            param=rs.CurveClosestPoint(branch,end)
            vec=rs.CurveTangent(branch,param)
            vec=rs.VectorUnitize(vec)
            index=rs.MeshClosestPoint(mesh,end)[1]
            norm=rs.MeshFaceNormals(mesh)[index]
            vec=rs.VectorRotate(vec,ang,norm)
            start=rs.PointAdd(end,vec*length)
            start=rs.MeshClosestPoint(mesh,start)[0]
            newBranch=rs.AddLine(end,start)
            pulledBranch=rs.PullCurveToMesh(mesh,newBranch)
            rs.DeleteObject(newBranch)
            newBranches.append(pulledBranch)
            vec=rs.VectorRotate(vec,-2*ang,norm)
            start=rs.PointAdd(end,vec*length)
            start=rs.MeshClosestPoint(mesh,start)[0]
            newBranch=rs.AddLine(end,start)
            pulledBranch=rs.PullCurveToMesh(mesh,newBranch)
            rs.DeleteObject(newBranch)
            if rs.Distance(start,rs.CurveEndPoint(pulledBranch))<length/2:
                newBranches.append(pulledBranch)
        branches=newBranches
        stored.extend(branches)
        newBranches=[]
        count=count+1
    #for i in range(len(stored)):
    #    squareSect(stored[i],1,1)
    print count
    return stored
예제 #21
0
def draw(p0, p1, n=1):
    if n == 0:
        rs.AddLine(p0, p1)
    elif n >= 1:
        p01 = rs.PointAdd(p0, (p1-p0)/3)
        p10 = rs.PointAdd(p0, (p1-p0)*2/3)
        p2 = rs.PointAdd(p01, rs.VectorRotate(p10 - p01, 60, (0, 0, 1)))
        draw(p0, p01, n-1)
        draw(p01, p2, n-1)
        draw(p2, p10, n-1)
        draw(p10, p1, n-1)
예제 #22
0
 def appendEdgeDirection(self):
     """
     Calculate the unit vector of offset directions for self.edges and append in list: self.offsetDirection.
     :rtype: None (result in self.offsetDirection)
     """
     for edge in self.edges:
         # make vertical vector
         curveVector = rs.VectorCreate(rs.CurveStartPoint(edge), rs.CurveEndPoint(edge))
         midPoint = rs.CurveMidPoint(edge)
         vec1 = rs.VectorRotate(curveVector, 90.0, [0, 0, 1])
         vec2 = rs.VectorRotate(curveVector, -90.0, [0, 0, 1])
         midToCenterVec = rs.VectorCreate(midPoint, self.center)
         offsetVec = ""
         if rs.VectorDotProduct(vec1, midToCenterVec) > 0:
             offsetVec = vec1
         else:
             offsetVec = vec2
         offsetVec = rs.VectorUnitize(offsetVec)
         # result
         self.offsetDirection.append(offsetVec)
예제 #23
0
def draw(p0, p1, n=4):
    if n == 0:
        rs.AddLine(p0, p1)
    elif n >= 1:
        p01 = rs.PointAdd(p0, rs.PointScale(rs.PointSubtract(p1, p0), 1 / 3))
        p10 = rs.PointAdd(p0, rs.PointScale(rs.PointSubtract(p1, p0), 2 / 3))
        p2 = rs.PointAdd(
            p01, rs.VectorRotate(rs.PointSubtract(p10, p01), 60, (0, 0, 1)))
        draw(p0, p01, n - 1)
        draw(p01, p2, n - 1)
        draw(p2, p10, n - 1)
        draw(p10, p1, n - 1)
예제 #24
0
def main():

  diameter = rs.GetReal("enter cutter diameter", number=0.25)
  diameter = diameter*1.1
  # first, select objects in three orthogonal planes
  obj = rs.GetObject("select object", filter=4) # curve
  curve_points = rs.CurvePoints(obj)[:-1]

  circles = []
  while True:
    point = rs.GetPoint("select point")
    if point is None:
      break
    try:
      idx = curve_points.index(point)
      print "clicked index", idx
    except ValueError:
      print "invalid point"
      continue

    points = [
      curve_points[(idx+1)%len(curve_points)],
      curve_points[idx                      ],
      curve_points[(idx-1)%len(curve_points)],
    ]
    print points

    angle = rs.Angle2(
        (points[1], points[0]),
        (points[1], points[2]),
    )
    angle = angle[0]

    point = rs.VectorAdd(
      points[1], 
      rs.VectorRotate(0.5*diameter*rs.VectorUnitize(rs.VectorSubtract(points[2], points[1])), angle/2, (0,0,1))
    )

    #p0 = (point.X, point.Y, point.Z + 1000)
    #p1 = (point.X, point.Y, point.Z - 1000)

    circle = rs.AddCircle(point, diameter/2.0)
    circles.append(circle)

    #extrusion = rs.ExtrudeCurveStraight(circle, p0, p1)

  for circle in circles:
    before_obj = obj
    obj = rs.CurveBooleanDifference(obj, circle)
    rs.DeleteObject(before_obj)

  rs.DeleteObjects(circles)
예제 #25
0
    def drawIntersectionWithDoubleLine(self, doubleLine):
        """draw two doubleLines:  selfDoubleLine and antherDoubleLine
        a=selfDoubleLine Type: System.Double
        Parameter on self.line0 that is closest to doubeLine.line0. 
        ab > 1 : means outside of self.line0.To
        ab < 0 : means outside of self.line0.From
        0 <=ab<= 1 : means inside of self.line0

        b=anotherDoubleLine Type: System.Double
        Parameter on doubleLine.line0 that is closest to self.line0. 
        ba > 1 : means outside of doubleLine.line0.To
        ba < 0 : means outside of doubleLine.line0.From
        0<= ba <= 1 : means inside of doubleLine.line0

        angle Type: System.Double
        counterclockwise angle between self and another
        """
        #get intersection infomation between two doubleLines
        rc, a0b0, b0a0 = geo.Intersect.Intersection.LineLine(
            self.line0, doubleLine.line0)
        if not rc:
            print "Parallel doubleLine found."
            return (False, None, None)
        rc, a0b1, b1a0 = geo.Intersect.Intersection.LineLine(
            self.line0, doubleLine.line1)
        rc, a1b0, b0a1 = geo.Intersect.Intersection.LineLine(
            self.line1, doubleLine.line0)
        rc, a1b1, b1a1 = geo.Intersect.Intersection.LineLine(
            self.line1, doubleLine.line1)

        # self.direction, doubleLine.direction
        angle = rs.Angle(
            (0, 0, 0),
            rs.VectorRotate(doubleLine.direction, -rs.Angle(
                (0, 0, 0), self.direction)[0], (0, 0, 1)))
        selfRawParameter = ((a0b0, a0b1, a1b0, a1b1, b0a0, b1a0, b0a1, b1a1),
                            -angle[0])
        anotherRawParameter = ((b0a0, b0a1, b1a0, b1a1, a0b0, a1b0, a0b1,
                                a1b1), angle[0])

        # ----self-doubleLine-a----
        selfParam = self._getDoubleLineParameterByIntersection(
            selfRawParameter)
        # ----another-doubleLine-b---
        anotherParam = doubleLine._getDoubleLineParameterByIntersection(
            anotherRawParameter)

        # ----draw self-doubleLine-a----
        self.drawDoubleLineByparameterList(selfParam[0], selfParam[1])
        # ----draw another-doubleLine-b---
        doubleLine.drawDoubleLineByparameterList(anotherParam[0],
                                                 anotherParam[1])
예제 #26
0
    def setLine(self):
        for i in range(int(self.lineNum)):
            # sPt=[-self.len/2.0, -self.dis*(self.lineNum-1)/2.0+self.dis*i+self.offset, 0]
            # ePt=[ self.len/2.0, -self.dis*(self.lineNum-1)/2.0+self.dis*i+self.offset, 0]
            sPt = [
                -self.len / 2.0, -self.dis * (self.lineNum - 1) / 2.0 +
                self.dis * i + self.offset, 0
            ]
            ePt = [
                self.len / 2.0, -self.dis * (self.lineNum - 1) / 2.0 +
                self.dis * i + self.offset, 0
            ]

            sPt = rs.VectorRotate(sPt, self.angle, [0, 0, 1])
            ePt = rs.VectorRotate(ePt, self.angle, [0, 0, 1])
            line = Line(
                self.no,  #int lineの種類番号 1<=no<=6
                i,  #int 同じ種類の中で何番目か
                sPt,  #[x,y,z] 始点(描画には使わない。ベクトル用)
                ePt,  #[x,y,z] 終点(描画には使わない。ベクトル用)
                self.angle)  #float 0<=angle<180
            self.lines.append(line)
def RecursiveLine(line, generation):
    if generation > 0:
        vector = rs.VectorCreate(rs.CurveStartPoint(line),
                                 rs.CurveEndPoint(line))
        vector = rs.VectorRotate(vector, 90, (0, 0, 1))
        hight = rs.VectorCreate((0, 0, 0), (0, 0, generation * 5))
        points = rs.DivideCurve(line, random.uniform(5, 10))
        for p in points:
            start = rg.Point3d.Add(p, hight)
            if random.uniform(0, 1):
                vector = -vector
            vector = vector * 0.8
            #            ends=rs.MoveObject(p,vector)
            vectorh = rs.VectorRotate(
                vector, 90,
                rs.VectorCreate(rs.CurveStartPoint(line),
                                rs.CurveEndPoint(line)))
            highpoints = rg.Point3d.Add(start, vectorh)
            AddLine(start, highpoints, generation * 5, generation)
            start = highpoints
            ends = rg.Point3d.Add(start, vector)
            newline = AddLine(start, ends, generation * 5, generation)
            RecursiveLine(newline, generation - 1)
예제 #28
0
 def getConfig1(self,p,q,r):
     pr=rs.VectorUnitize(rs.VectorCreate(r,p))
     prN=rs.VectorScale(rs.VectorRotate(pr,90,[0,0,1]),self.b0)
     prA=rs.VectorScale(pr,self.b1)
     a=rs.PointAdd(q,prA)  # goes from q to a along pr
     b=rs.PointAdd(q,prN)  # goes from q to b perpendicular to pr
     c=rs.PointAdd(b,prA)
     t=self.checkContainment(a,b,c)
     if(t==True):
         #poly=rs.AddPolyline([q,a,c,b,q])
         poly=[q,a,c,b,q]
         return poly
     else:
         return None
예제 #29
0
def get_perpendicular_vector_to_points(pntI, pntJ, left=True):
    '''
    returns a unitized vector perpendicular to the vector formed 
    from pntI to pntJ
    ^
    |
    I-------> J
    '''
    normal = [0, 0, 1]
    angle = 90.0
    if not left:
        angle = -1.0 * angle
    vec = rs.VectorSubtract(pntJ, pntI)
    vec = rs.VectorRotate(vec, angle, normal)
    return rs.VectorUnitize(vec)
예제 #30
0
def drawDivisionLine(emblem, color=True):
    objs = []
    # line
    r = 24
    for i in range(int(emblem.division)):
        p = [r, 0, 0]
        if (emblem.division % 4 == 0):
            angle = i * 360.0 / emblem.division + 360.0 / emblem.division / 2.0
        else:
            angle = i * 360.0 / emblem.division
        p = rs.VectorRotate(p, angle, [0, 0, 1])
        obj = rs.AddLine([0, 0, 0], p)
        if (color):
            layer = "line%s" % (i % int(emblem.division / 2.0))
        else:
            layer = "lineGray"
        rs.ObjectLayer(obj, layer)
        objs.append(obj)
    # circle
    obj = rs.AddCircle([0, 0, 0], r)
    if (color):
        layer = "lineBlack"
    else:
        layer = "lineGray"
    rs.ObjectLayer(obj, layer)
    objs.append(obj)
    # text
    planeOri = rs.ViewCPlane()
    for i in range(int(emblem.division / 2.0)):
        if (emblem.division % 4 == 0):
            angle = i * 360.0 / emblem.division + 360.0 / emblem.division / 2.0
        else:
            angle = i * 360.0 / emblem.division
        p = [r, 0, 0]
        txt = "%d" % (angle)
        height = 1.2
        pt = [0, height / 2.0, 0]
        font_style = 0
        justification = 2 + 65536
        obj = rs.AddText(txt, pt, height, font, font_style, justification)
        rs.RotateObject(obj, [0, 0, 0], -90.0, [0, 0, 1], False)
        rs.MoveObject(obj, [r, 0, 0])
        rs.RotateObject(obj, [0, 0, 0], angle, [0, 0, 1], False)
        rs.ObjectLayer(obj, "textLine")
        objs.append(obj)
        rs.ViewCPlane(None, planeOri)
    #return
    return objs