Ejemplo n.º 1
0
    def Moveobj(self, y_c_i):
        m_p = rs.CircleCenterPoint(self.circle_obj)
        y_p = rs.CircleCenterPoint(y_c_i.circle_obj)

        vector_m_y = rs.VectorCreate(y_p, m_p)
        vector_y_m = rs.VectorCreate(m_p, y_p)
        unit_vec_m_y = rs.VectorUnitize(vector_m_y)
        unit_vec_y_m = rs.VectorUnitize(vector_y_m)

        radius_1 = rs.CircleRadius(self.circle_obj)
        radius_2 = rs.CircleRadius(y_c_i.circle_obj)

        dis_1_2 = rs.Distance(m_p, y_p)
        dis = dis_1_2 - (radius_1 + radius_2)
        move_dis = (dis / 2) / 10
        move_vec_m_y = rs.VectorScale(unit_vec_m_y, move_dis)
        move_vec_y_m = rs.VectorScale(unit_vec_y_m, move_dis)

        #        status = self.getStatus(y_c_i)
        #
        #        if(status == 1):
        #            rs.MoveObject(self.circle_obj,move_vec_m_y)
        #            rs.MoveObject(y_c_i.circle_obj,move_vec_y_m)
        #
        #        if(status == 2):
        #            rs.MoveObject(self.circle_obj,move_vec_y_m)
        #            rs.MoveObject(y_c_i.circle_obj,move_vec_m_y)

        rs.MoveObject(self.circle_obj, move_vec_m_y)
        rs.MoveObject(y_c_i.circle_obj, move_vec_y_m)
Ejemplo n.º 2
0
def getStatus(c_1, c_2):
    # 0:ちょうどいい距離なのでそのまま
    # 1:遠すぎる
    # 2:近すぎる

    if rs.IsCircle(c_1) and rs.IsCircle(c_2):
        radius_1 = rs.CircleRadius(c_1)
        radius_2 = rs.CircleRadius(c_2)

        #print(radius_1)
        #print(radius_2)

        pt_1 = rs.CircleCenterPoint(c_1)
        pt_2 = rs.CircleCenterPoint(c_2)

        #print(pt_1)
        #print(pt_2)

    #追加スクリプト↓
    dis_1_2 = rs.Distance(pt_1, pt_2)
    #print(dis_1_2)
    #追加スクリプト↑

    if (dis_1_2 == radius_1 + radius_2):
        status = 0
    if (radius_1 + radius_2 < dis_1_2):
        status = 1
    if (dis_1_2 < radius_1 + radius_2):
        status = 2

    return status  #returnで「数値」を返している。
Ejemplo n.º 3
0
        def FromEdgetoPlane():
            PointPlane = []
            CurveIdList = []
            Brep = []
            edges = rs.GetEdgeCurves()
            if edges:
                for edgeinfo in edges:

                    Brep.append(edgeinfo[1])
                    CurveIdList.append(edgeinfo[0])

            for CurveId in CurveIdList:

                if rs.IsCircle(CurveId):

                    Pt = rs.CircleCenterPoint(CurveId)
                    Normal = rs.CurveNormal(CurveId)
                    LenghtNormal = rs.VectorLength(Normal)
                    LenghNormal = self.m_foronumero.Text
                    LenghNormal = int(LenghNormal)
                    Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1],
                              LenghNormal * Normal[2])
                    PtStill = rs.AddPoint(Pt)

                    Ptmoved = rs.MoveObject(Pt, Normal)
                    Ptmoved = rs.coerce3dpoint(Ptmoved)
                    PtStill = rs.coerce3dpoint(PtStill)

                    PointPlane.append([
                        PtStill[0], PtStill[1], PtStill[2], Normal[0],
                        Normal[1], Normal[2]
                    ])
                    #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]])
            return (PointPlane, Brep)
Ejemplo n.º 4
0
def shape_from_ref(r):
    with parameter(immediate_mode, False):
        obj = _geometry_from_id(r)
        ref = native_ref(r)
        if isinstance(obj, geo.Point):
            return point.new_ref(ref, fromPt(obj.Location))
        elif isinstance(obj, geo.Curve):
            if rh.IsLine(r) or rh.IsPolyline(r):
                if rh.IsCurveClosed(r):
                    return polygon.new_ref(
                        ref, [fromPt(p) for p in rh.CurvePoints(r)[:-1]])
                else:
                    return line.new_ref(ref,
                                        [fromPt(p) for p in rh.CurvePoints(r)])
            elif obj.IsCircle(Rhino.RhinoMath.ZeroTolerance):
                return circle.new_ref(ref, fromPt(rh.CircleCenterPoint(r)),
                                      rh.CircleRadius(r))
            elif rh.IsCurveClosed(r):
                return closed_spline.new_ref(
                    ref, [fromPt(p) for p in rh.CurvePoints(r)])
            else:
                return spline.new_ref(ref,
                                      [fromPt(p) for p in rh.CurvePoints(r)])
        elif rh.IsObject(r) and rh.IsObjectSolid(r):
            return solid(native_ref(r))
        elif rh.IsSurface(r) or rh.IsPolysurface(r):
            return surface(native_ref(r))
        else:
            raise RuntimeError("{0}: Unknown Rhino object {1}".format(
                'shape_from_ref', r))
Ejemplo n.º 5
0
    def getStatus(self, y_c_i):
        #TODO:getDistanse関数を使う
        if rs.IsCircle(self.circle_obj) and rs.IsCircle(y_c_i.circle_obj):
            radius_1 = rs.CircleRadius(self.circle_obj)
            radius_2 = rs.CircleRadius(y_c_i.circle_obj)

        m_p = rs.CircleCenterPoint(self.circle_obj)
        y_p = rs.CircleCenterPoint(y_c_i.circle_obj)
        dis_1_2 = rs.Distance(m_p, y_p)

        if (dis_1_2 == radius_1 + radius_2):
            status = 0
        if (radius_1 + radius_2 < dis_1_2):
            status = 1
        if (dis_1_2 < radius_1 + radius_2):
            status = 2
        return status
Ejemplo n.º 6
0
def GetFracture ():
    dx = rs.GetReal("Enter x-axis direction:")
    if not dx:
        dx = 0.0
    print "x-axis direction: ", dx
    objs = rs.ObjectsByType(8,False)
    cir_objs = rs.ObjectsByType(4)
    
    #delete all circles
    for cur_obj in cir_objs:
        if rs.IsCircle(cur_obj):
            rs.DeleteObject(cur_obj)
    occor = []
    radius = []
    center = []
    
    #for all surface
    for obj in objs:
        rs.UnselectAllObjects()
        rs.SelectObject(obj)
        rs.Command ("_Silhouette")
        created_objs = rs.LastCreatedObjects()
        #not a circle
        if len(created_objs) !=1:
            rs.DeleteObjects(created_objs)
            print "unvailded surface"
            continue
        created_objs = created_objs[0]
        #not a circle
        if not rs.IsCircle(created_objs):
            rs.DeleteObject(created_objs)
            print "unvailded surface, not circle"
            continue
        point = rs.CircleCenterPoint(created_objs)
        center.append(point)
        r = rs.CircleRadius(created_objs)
        radius.append(r)
        normal = rs.SurfaceNormal(obj,[0,0])
        occor.append(GetDirDip(normal,dx))
        rs.DeleteObject(created_objs)
    print center
    print occor
    print radius
    path = rs.DocumentPath()
    path_l = path.split("\\")
    path_l[len(path_l)-1] = "fracture.dat"
    file = open("\\".join(path_l),"w")
    file.write(str(len(occor)))
    file.write('\n')
    for i in range (len(occor)):
        file.write("%.15f " % center[i][0])
        file.write("%.15f " % center[i][1])
        file.write("%.15f " % center[i][2])
        file.write ("%.15f " % occor[i][0])
        file.write ("%.15f " % occor[i][1])
        file.write ("%.15f " % radius[i])
        file.write ("0.0001 0.1 30\n")
    file.close ()
Ejemplo n.º 7
0
def ExportLighthouseSensorsToJSON(filename):
    print "Writing", filename

    #objectIds = rs.GetObjects("Select Sensors",rs.filter.curves,True,True)
    #if( objectIds==None ): return3

    # Find all circle and all lines in scene
    circles = []
    lines = []
    for obj in rs.AllObjects():
        # Skip hidden objects, and invisible layers
        # TODO: Recuse up layet hierarchy?
        if rs.IsObjectHidden(obj):
            continue
        layer = rs.ObjectLayer(obj)
        if layer and not rs.IsLayerVisible(layer):
            continue

        if rs.IsCurve(obj):
            if rs.IsCircle(obj):
                circles.append((obj, rs.CircleCenterPoint(obj)))
            elif rs.IsLine(obj):
                verts = rs.PolylineVertices(obj)
                if len(verts) == 2:
                    lines.append((obj, verts))

    print 'found', len(circles), 'sensor candidates (circles) in scene'
    print 'found', len(lines), 'sensor candidates (normals) in scene'

    modelJSON = {'modelNormals': [], 'modelPoints': []}

    # TODO: Better sort order? Perhaps based on winding around origin?
    for circleObj, circleCenter in reversed(circles):
        for line, lineVerts in lines:
            pos, normal = GetSensorPosAndNormal(circleCenter, lineVerts)
            if pos is None:
                continue
            else:
                modelJSON['modelNormals'].append([float(x) for x in normal])
                modelJSON['modelPoints'].append(
                    [float(x) / 1000.0 for x in pos])
                break
    modelJSON['channelMap'] = range(len(modelJSON['modelNormals']))

    print "Extracted", len(modelJSON['channelMap']), "sensors"

    if len(modelJSON['modelNormals']) > 0:
        outputFile = file(filename, 'w')
        jsonText = json.dumps(modelJSON, indent=4, sort_keys=True)
        outputFile.write(jsonText)
        outputFile.close()

        print "Wrote", filename
    else:
        print "Error: No sensors found in scene"
Ejemplo n.º 8
0
def Moveobj(c_1, c_2):

    #追加スクリプト↓
    pt_1 = rs.CircleCenterPoint(c_1)
    pt_2 = rs.CircleCenterPoint(c_2)
    #追加スクリプト↑

    if (status == 1):
        vector_1 = rs.VectorCreate(pt_2, pt_1)

        #追加スクリプト↓
        vector_2 = rs.VectorCreate(pt_1, pt_2)
        unit_vec_1 = rs.VectorUnitize(vector_1)
        unit_vec_2 = rs.VectorUnitize(vector_2)

        radius_1 = rs.CircleRadius(c_1)
        radius_2 = rs.CircleRadius(c_2)

        dis_1_2 = rs.Distance(pt_1, pt_2)
        dis = dis_1_2 - (radius_1 + radius_2)
        move_dis = (dis / 2)  #/10 ←移動係数で割る?
        #追加スクリプト↑

        # vector_1をUnit Vector unit_vec にする
        # 円の差分距離 dis を計算
        # dis = 円中心点間の距離-(半径1+半径2)
        # 動かす距離 move_dis を計算
        # お互いに動かすので /2
        # 移動係数で割る /10

        #追加スクリプト↓
        move_vec_1 = rs.VectorScale(unit_vec_1, move_dis)
        move_vec_2 = rs.VectorScale(unit_vec_2, move_dis)

        move_obj_1 = rs.MoveObject(c_1, move_vec_1)
        move_obj_2 = rs.MoveObject(c_2, move_vec_2)
        #追加スクリプト↑

    return move_obj_1
    return move_obj_2
Ejemplo n.º 9
0
    def SetPlanarCurve(self, type="Any", guid=None):
        if (type == "Any"): prompt = "Select a planar pitch curve"
        elif (type == "Circle"): prompt = "Select the pitch circle"

        newCurve = rs.GetCurveObject(prompt, True,
                                     True) if guid is None else [guid]
        if (newCurve is None):
            Rhino.RhinoApp.WriteLine("Exit: No curve was selected")
            return False
        isPlanar = rs.IsCurvePlanar(newCurve[0])
        if (isPlanar == False):
            newCurve = None
            Rhino.RhinoApp.WriteLine("Exit: Selected curve was not planar")
            return False

        self.curve = newCurve  #Accept the curve into the object because the curve exists and it is planar
        self.isClosed = rs.IsCurveClosed(self.curve[0])
        self.normal = rs.CurveNormal(
            self.curve[0])  #For non planar curves the script already exited.

        self.isCircle = rs.IsCircle(self.curve[0])
        if (type == "Circle" and self.isCircle != True):
            Rhino.RhinoApp.WriteLine("Exit: Selected curve was not a circle")
            return False

        self.crvLen = rs.CurveLength(self.curve[0])
        if (self.isCircle == True):
            Rhino.RhinoApp.WriteLine("Selected: Circle")
            self.origin = rs.CircleCenterPoint(self.curve[0])
            self.plane = rs.PlaneFromNormal(
                self.origin, self.normal,
                rs.CurveStartPoint(self.curve[0]) -
                self.origin)  #PlaneFromNormal(origin, normal, xaxis=None)
            self.SetPD()  #Propagate the value updates
            self.SetBC()  #Propagate the value updates
            return
        if (self.isClosed == True):
            Rhino.RhinoApp.WriteLine(
                "Selected: Closed non-circular planar curve")
            return
        else:
            Rhino.RhinoApp.WriteLine("Selected: Open planar curve")
Ejemplo n.º 10
0
def FromEdgetoPlane():
    PointPlane = []
    CurveIdList = []
    Brep = []
    edges = rs.GetEdgeCurves()
    if edges:
        for edgeinfo in edges:
            Brep.append(edgeinfo[1])
            CurveIdList.append(edgeinfo[0])


#    print CurveIdList
    for CurveId in CurveIdList:

        if rs.IsCircle(CurveId):
            #            print "Sono un cerchio"
            Pt = rs.CircleCenterPoint(CurveId)
            Normal = rs.CurveNormal(CurveId)
            LenghtNormal = rs.VectorLength(Normal)
            LenghNormal = rs.GetString("give me the lengh of the hole", "100")
            LenghNormal = int(LenghNormal)
            Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1],
                      LenghNormal * Normal[2])
            print Normal
            PtStill = rs.AddPoint(Pt)
            Ptmoved = rs.MoveObject(Pt, Normal)
            Ptmoved = rs.coerce3dpoint(Ptmoved)
            PtStill = rs.coerce3dpoint(PtStill)
            #            print Ptmoved
            #            print PtStill

            PointPlane.append([
                PtStill[0], PtStill[1], PtStill[2], Normal[0], Normal[1],
                Normal[2]
            ])
            #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]])
    return (PointPlane, Brep)
Ejemplo n.º 11
0
 def getDistance(self, y_c_i):
     m_p = rs.CircleCenterPoint(self.circle_obj)
     y_p = rs.CircleCenterPoint(y_c_i.circle_obj)
     dis = rs.Distance(m_p, y_p)
     return dis
Ejemplo n.º 12
0
 def check_center(self):
     self.center = rs.CircleCenterPoint(self.circle)
     print "The count is centered {}".format(self.center)