def init_transform(i): p0 = i.PointAtStart p1 = i.PointAtEnd # Calculate inital basis and scale factor t0 = p1 - p0 v0 = geom.Vector3d(t0) v2 = rs.CreateVector(0, 0, 1) v1 = geom.Vector3d.CrossProduct(v0, v2) v2 = geom.Vector3d.CrossProduct(v0, v1) scaleFactor = t0.Length / 5 # Normalize constructed basis v0.Unitize() v1.Unitize() v2.Unitize() # Standard basis e0 = geom.Vector3d.XAxis e1 = geom.Vector3d.YAxis e2 = geom.Vector3d.ZAxis # Get change of basis transform (standard --> curve) b = geom.Transform.ChangeBasis(e0, e1, e2, v0, v1, -v2) # Get scale transform matching scale factor set by curve length s = geom.Transform.Scale(geom.Point3d.Origin, scaleFactor) # Get translation transform to curve endpoint r = geom.Transform.Translation(t0) # Return geometry in new basis, scaled, and translated return b
def get_gradient(p): gx = x.get_distance(p.X + e, p.Y, p.Z) - x.get_distance(p.X - e, p.Y, p.Z) gy = x.get_distance(p.X, p.Y + e, p.Z) - x.get_distance(p.X, p.Y - e, p.Z) gz = x.get_distance(p.X, p.Y, p.Z + e) - x.get_distance(p.X, p.Y, p.Z - e) v = rs.CreateVector(gx, gy, gz) v.Unitize() return v
def addRail(obj): point1 = rs.EvaluateSurface(obj, 0, 0) vec = rs.CreateVector(0, 0, height) point2 = rs.CopyObject(point1, vec) line = rs.AddLine(point1, point2) if point2: rs.DeleteObjects(point2) return line
def makeBrep(srf): point1 = rs.EvaluateSurface(srf, 0, 0) vec = rs.CreateVector(0, 0, height) point2 = rs.CopyObject(point1, vec) line = rs.AddLine(point1, point2) brep = rs.ExtrudeSurface(srf, line) if point2: rs.DeleteObjects(point2) if line: rs.DeleteObjects(line) return brep
def rotate(input): result = [] for ii in [0, 90, 180, 270]: list = [] for i in input: v = rs.CreateVector(i) v.Rotate(math.radians(int(ii)), rotationAxis) list.append(v) result.append(list) return result
def displaychoicepointvec(rec,edge_index,length): #根据一个矩形,以及矩形上面的边号和长度,输出该点的向量 remove_index = [1,2,3,0] vec_list = [] for i in rec.vec_lst: i_temp = i.unit() temp_ve = rs.CreateVector(i_temp.x,i_temp.y,0) vec_list.append(temp_ve) if length == 0: return vec_list else: del vec_list[remove_index[edge_index]] return vec_list
def displaypolyveclength(polyline): #根据一个多段线,输出gh中点的列表和向量的列表,和需要表现得长度得txt与点 corner_list = [] #角点列表 vector_list = [] #向量列表 txt_length = [] #长度txt列表 median_point = [] #文字标记点得列表 for i in range(0,len(polyline.vec_lst)): temp_point = polyline.pt_lst[i] temp_vec = polyline.vec_lst[i] corner_list.append(rs.CreatePoint(temp_point.x,temp_point.y,0)) vector_list.append(rs.CreateVector(temp_vec.x,temp_vec.y,0)) txt_length.append(str(temp_vec.getLength())) median_point.append(rs.CreatePoint(temp_point.x+temp_vec.x/2,temp_point.y+temp_vec.y/2,0)) return corner_list,vector_list,txt_length,median_point
def initSlice(self, init_geo): result = [] plane = rs.PlaneFromPoints((-5000, -5000, 0), (0, -5000, 0), (-5000, 0, 0)) planeSrf = rs.AddPlaneSurface(plane, 10000, 10000) crv = rs.IntersectBreps(init_geo, planeSrf) result.append(crv) while True: vec = rs.CreateVector((0, 0, self.layer_height)) planeSrf = rs.MoveObject(planeSrf, vec) crv = rs.IntersectBreps(init_geo, planeSrf) if crv == None: break else: result.append(crv) result = rs.JoinCurves(result) for i in range(1, len(result)): if not rs.CurveDirectionsMatch(result[0], result[i]): rs.ReverseCurve(result[i]) return result
def xf_shear(ctr, vx=(1, 0, 0), vy=(0, 1, 0), vz=(0, 0, 1)): pln = rs.MovePlane(rs.WorldXYPlane(), ctr) xform = Rhino.Geometry.Transform.Shear(pln, rs.CreateVector(vx), rs.CreateVector(vy), rs.CreateVector(vz)) return xform
def sortPoints(listInput): listOutput = [] for input in listInput: dist = [] listOutput.append(sorted(input, key=dist_from_origin)) return listOutput def comparePoints(input1, input2): similar = True zeroPoint = rs.CreatePoint(0, 0, 0) rotationAxis = rs.CreateVector(0, 0, 1) import math def rotate(input): result = [] for ii in [0, 90, 180, 270]: list = [] for i in input: v = rs.CreateVector(i) v.Rotate(math.radians(int(ii)), rotationAxis) list.append(v) result.append(list) return result
def __sink__(self, modifier): height = -(self.coordinates[2] - 1.8) v = rs.CreateVector(0, 0, height / boxSIZE * 2 * BUILDINGS_Speed / modifier) self.coordinates = rs.PointAdd(self.coordinates, v)
PODS_Colors_inTIMES = [] PODS_Occupancy_inTIME = [] PATHS_inTIME = [] avrageCOMMUTEdistance_inTIME = [] avrageCOMMUTEtime_inTIME = [] users_ACTIVITIES_inTIME = [] TEXT_coordinate_inTIME = [] TEXT_inTIME = [] # to delete! PRINT_LOG_inTIME = [] PRINT_LOG = [str(), str(), str(), str(), str()] TIME = [] iNR = 0 Vzero = rs.CreateVector(0, 0, 0) Pzero = rs.CreatePoint(0, 0, 0) hbS = boxSIZE / 2 # half of box size pheryphery_border1 = squeezing_area * hbS pheryphery_border2 = boxSIZE - pheryphery_border1 squeezing_multiplier = squeezingPOWER / (pheryphery_border1)**2 maxHALOsize = BUILDINGS_Halo maxflow = 0 def IDcomponent(cooridante): id_component, distance = divmod(cooridante, module) id_component = int(id_component) id_component = min(id_component, partitions - 1) id_component = max(id_component, 0) return id_component
def xf_shear(vx=(1, 0, 0), vy=(0, 1, 0), vz=(0, 0, 1)): xform = Rhino.Geometry.Transform.Shear(rs.WorldXYPlane(), rs.CreateVector(vx), rs.CreateVector(vy), rs.CreateVector(vz)) return xform
def offset_z_curves(self, curves, z_offset_value): move_vec = rs.CreateVector(0, 0, z_offset_value) geos_off = rs.MoveObjects(curves, move_vec) return geos_off