def draw_circles(circles, **kwargs): guids = [] for data in iter(circles): point, normal = data['plane'] radius = data['radius'] name = data.get('name', '') color = data.get('color') layer = data.get('layer') circle = Circle(Plane(Point3d(*point), Vector3d(*normal)), radius) guid = add_circle(circle) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids
def draw_circles(circles): """Draw circles in Grasshopper. Parameters ---------- circles : list of dict The circle definitions. Returns ------- list of :class:`Rhino.Geometry.Circle` Notes ----- .. code-block:: python Schema({ 'plane': lambda x: len(x[0]) == 3 and len(x[1]) == 3, 'radius': And(Or(int, float), lambda x: x > 0) }) """ rg_circles = [] for c in iter(circles): point, normal = c['plane'] radius = c['radius'] rg_circles.append( Circle(Plane(Point3d(*point), Vector3d(*normal)), radius)) return rg_circles
def xdraw_frame(frame): """Draw frame. """ pt = Point3d(*iter(frame.point)) xaxis = Vector3d(*iter(frame.xaxis)) yaxis = Vector3d(*iter(frame.yaxis)) return Plane(pt, xaxis, yaxis)
def draw_circles(circles, **kwargs): """Draw circles and optionally set individual name, color, and layer properties. Parameters ---------- circles : list[dict] A list of circle dictionaries. See Notes, for more information about the structure of the dict. Returns ------- list[System.Guid] Notes ----- A circle dict has the following schema: .. code-block:: python Schema({ 'plane': lambda x: len(x[0]) == 3 and len(x[1]) == 3, 'radius': And(Or(int, float), lambda x: x > 0), Optional('name', default=''): str, Optional('color', default=None): And(lambda x: len(x) == 3, all(0 <= y <= 255 for y in x)), Optional('layer', default=None): str }) """ guids = [] for data in iter(circles): point, normal = data['plane'] radius = data['radius'] name = data.get('name', '') color = data.get('color') layer = data.get('layer') circle = Circle(Plane(Point3d(*point), Vector3d(*normal)), radius) guid = add_circle(circle) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids
def __init__(self, slider): super(Pipe, self).__init__() self.slider = slider self.base = Point3d(0, 0, 0) self.normal = Point3d(0, 0, 1) - self.base self.height = 30 self.plane = Plane(self.base, self.normal) self.color = Color.FromArgb(255, 0, 0) self.material = DisplayMaterial(self.color)
def draw_circles(circles): """Draw circles in Grasshopper. """ rg_circles = [] for c in iter(circles): point, normal = c['plane'] radius = c['radius'] rg_circles.append(Circle(Plane(Point3d(*point), Vector3d(*normal)), radius)) return rg_circles
def copy(self): ''' Returns a copy of the Connection Returns: conn_copy (Connection): Connection copy ''' pln_copy = Plane(self.pln.Origin, self.pln.XAxis, self.pln.YAxis) conn_copy = Connection(pln_copy, self.type, self.part, self.id) return conn_copy
def transform(self, trans): if self.transformable == True: values_trans = [] for val in self.values: val_trans = None ## !!!! add try..except.. block for other geometry types (?) if type(val) == Point3d: val_trans = Point3d(val) elif type(val) == Plane: val_trans = Plane(val) elif type(val) == Line: val_trans = Line(val.From, val.To) else: val_trans = val.Duplicate() val_trans.Transform(trans) values_trans.append(val_trans) attr_trans = Attribute(self.name, values_trans, self.transformable) else: attr_trans = Attribute(self.name, self.values, self.transformable) return attr_trans
def trimesh_slice(mesh, planes): """Slice a mesh by a list of planes. Parameters ---------- mesh : tuple of vertices and faces The mesh to slice. planes : list of (point, normal) tuples or compas.geometry.Plane The slicing planes. Returns ------- list of arrays The points defining the slice polylines. Examples -------- >>> from compas.geometry import Sphere, Plane, Point, Vector >>> sphere = Sphere([1, 1, 1], 1) >>> sphere = sphere.to_vertices_and_faces(u=30, v=30) >>> P1 = Plane(Point(0, 0, 0), Vector(0, -1, 0)) >>> P2 = Plane(Point(0, 0, 0), Vector(0.87, -0.5, 0)) >>> planes = [P1, P2] >>> points = trimesh_slice(sphere, planes) """ # (0) see if input is already Rhino.Geometry.Mesh M = Rhino.Geometry.Mesh() if not isinstance(mesh, Rhino.Geometry.Mesh): for x, y, z in mesh[0]: M.Vertices.Add(x, y, z) for face in mesh[1]: M.Faces.AddFace(*face) else: M = mesh # (1) parse to Rhino.Geometry.Plane P = [] for plane in planes: point = Point3d(plane[0][0], plane[0][1], plane[0][2]) normal = Vector3d(plane[1][0], plane[1][1], plane[1][2]) P.append(Plane(point, normal)) # (2) Slice polylines = MeshPlane(M, P) # (3) Return points in a list of arrays polyline_pts = [] for polyline in polylines: pts = [] for i in range(polyline.Count): pts.append([polyline.X[i], polyline.Y[i], polyline.Z[i]]) polyline_pts.append(pts) return polyline_pts
def contourBrepInZ(brep, stepSize): # get the upper and lower limits bbox = brep.GetBoundingBox(True) zMin, zMax = bbox.Min.Z, bbox.Max.Z zRange = zMax-zMin vect = Vector3d(0.0,0.0,1.0) # the next line is dense planes = [Plane(Point3d(0.0, 0.0, z), vect) for z in RangeTools.drange(zMin,zMax, 0.5)] resultList = [] for plane in planes: curves = brep.CreateContourCurves(brep, plane) resultList.append(curves) return resultList
def __init__(self, _plane, _type, _part, _id): self.pln = _plane flip_pln_Y = Vector3d(self.pln.YAxis) flip_pln_Y.Reverse() self.flip_pln = Plane(self.pln.Origin, self.pln.XAxis, flip_pln_Y) self.type = _type self.part = _part self.id = _id self.rules_table = [] self.active_rules = []
def transform(self, trans): ''' Returns a transformed connection Args: trans (Transformation): Transformation to apply to the Connection Returns: conn_trans (Connection): Transformed copy of the Connection ''' pln_trans = Plane(self.pln.Origin, self.pln.XAxis, self.pln.YAxis) conn_trans = Connection(pln_trans, self.type, self.part, self.id) conn_trans.pln.Transform(trans) conn_trans.flip_pln.Transform(trans) return conn_trans
def draw_cylinders(cylinders, cap=False): """Draw cylinders. Parameters ---------- cylinders : list of dict The cylinder definitions. Other Parameters ---------------- cap : bool, optional Default is ``False``. Returns ------- list of :class:`Rhino.Geometry.Cylinder` Notes ----- .. code-block:: python Schema({ 'start': lambda x: len(x) == 3, 'end': lambda x: len(x) == 3, 'radius': And(Or(int, float), lambda x: x > 0) }) """ rg_cylinders = [] for c in iter(cylinders): start = c['start'] end = c['end'] radius = c['radius'] if radius < TOL: continue base = Point3d(*start) normal = Point3d(*end) - base height = normal.Length if height < TOL: continue plane = Plane(base, normal) circle = Circle(plane, radius) cylinder = Cylinder(circle, height) brep = cylinder.ToBrep(cap, cap) if not brep: continue rg_cylinders.append(brep) return rg_cylinders
def _egi_sort_v_nbrs(egi): """ By default, the sorting should be ccw, since the circle is typically drawn ccw around the local plane's z-axis... """ xyz = dict((key, [attr[_] for _ in 'xyz']) for key, attr in egi.vertices(True)) for vkey in egi.vertex: nbrs = egi.vertex[vkey]['nbrs'] plane = Plane(Point3d(*xyz[vkey]), Vector3d(*[axis for axis in egi.vertex[vkey]['normal']])) circle = Circle(plane, 1) p_list = [] for nbr_vkey in nbrs: boolean, parameter = ArcCurve(circle).ClosestPoint(Point3d(*xyz[nbr_vkey])) p_list.append(parameter) sorted_nbrs = [key for (param, key) in sorted(zip(p_list, nbrs))] egi.vertex[vkey]['sorted_nbrs'] = sorted_nbrs
def copy(self): if self.transformable == True: values_copy = [] for val in self.values: val_copy = None if type(val) == Point3d: val_copy = Point3d(val) elif type(val) == Plane: val_copy = Plane(val) elif type(val) == Line: val_copy = Line(val.From, val.To) else: val_copy = val.Duplicate() values_copy.append(val_copy) attr_copy = Attribute(self.name, values_copy, self.transformable) else: attr_copy = Attribute(self.name, self.values, self.transformable) return attr_copy
def xdraw_cylinders(cylinders, cap=False, **kwargs): guids = [] for c in iter(cylinders): start = c['start'] end = c['end'] radius = c['radius'] name = c.get('name', '') color = c.get('color') layer = c.get('layer') if radius < TOL: continue base = Point3d(*start) normal = Point3d(*end) - base height = normal.Length if height < TOL: continue plane = Plane(base, normal) circle = Circle(plane, radius) cylinder = Cylinder(circle, height) brep = cylinder.ToBrep(cap, cap) if not brep: continue guid = add_brep(brep) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids
def xdraw_cylinders(cylinders, cap=False): rg_cylinders = [] for c in iter(cylinders): start = c['start'] end = c['end'] radius = c['radius'] if radius < TOL: continue base = Point3d(*start) normal = Point3d(*end) - base height = normal.Length if height < TOL: continue plane = Plane(base, normal) circle = Circle(plane, radius) cylinder = Cylinder(circle, height) brep = cylinder.ToBrep(cap, cap) if not brep: continue rg_cylinders.append(brep) return rg_cylinders
from __future__ import absolute_import
def copy(self): pln_copy = Plane(self.pln.Origin, self.pln.XAxis, self.pln.YAxis) conn_copy = Connection(pln_copy, self.type, self.part, self.id) return conn_copy
def run_hunter(threat): threat.move() threat.limit() threats.append(Cone(Plane(threat.position, -1 * (threat.velocity)), 6, 2))
def run_boids(agents): agents.move() agents.limit() points.append(Cone(Plane(agents.position, -1 * (agents.velocity)), 2, 0.5))
def draw_cylinders(cylinders, cap=False, **kwargs): """Draw cylinders and optionally set individual name, color, and layer properties. Parameters ---------- cylinders : list of dict A list of cylinder dictionaries. cap : bool, optional Returns ------- list of GUID Notes ----- A cylinder dict has the following schema: .. code-block:: python Schema({ 'start': And(list, lambda x: len(x) == 3), 'end': And(list, lambda x: len(x) == 3), 'radius': And(Or(int, float), lambda x: x > 0.0), Optional('name', default=''): str, Optional('color', default=None): (lambda x: len(x) == 3 and all(0 <= y <= 255 for y in x)), Optional('layer', default=None): str, }) """ guids = [] for c in iter(cylinders): start = c['start'] end = c['end'] radius = c['radius'] name = c.get('name', '') color = c.get('color') layer = c.get('layer') if radius < TOL: continue base = Point3d(*start) normal = Point3d(*end) - base height = normal.Length if height < TOL: continue plane = Plane(base, normal) circle = Circle(plane, radius) cylinder = Cylinder(circle, height) brep = cylinder.ToBrep(cap, cap) if not brep: continue guid = add_brep(brep) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids
def transform(self, trans): pln_trans = Plane(self.pln.Origin, self.pln.XAxis, self.pln.YAxis) conn_trans = Connection(pln_trans, self.type, self.part, self.id) conn_trans.pln.Transform(trans) conn_trans.flip_pln.Transform(trans) return conn_trans