def kinks(self, threshold=1e-3): """Return the XYZ coordinates of kinks, i.e. tangency discontinuities, along the surface's boundaries. Returns ------- list The list of XYZ coordinates of surface boundary kinks. """ kinks = [] borders = self.borders(type=0) for border in borders: border = RhinoCurve(border) extremities = map( lambda x: rs.EvaluateCurve(border.guid, rs.CurveParameter(border.guid, x)), [0., 1.]) if border.is_closed(): start_tgt, end_tgt = border.tangents(extremities) if angle_vectors(start_tgt, end_tgt) > threshold: kinks += extremities else: kinks += extremities return list(set(kinks))
def identify_vertices_on_curve(diagram, guid): gkey_key = diagram.gkey_key() keys = [] curve = RhinoCurve(guid) for key in diagram.vertices(): xyz = diagram.vertex_coordinates(key) closest = curve.closest_point(xyz) gkey = geometric_key(closest) if gkey in gkey_key: if key == gkey_key[gkey]: keys.append(key) return keys
def from_guid(guid): """Create a ``RhinoGeometry`` instance of the correct type based on a given guid. Parameters ---------- guid : str or System.Guid The *guid* of the Rhino object. Returns ------- RhinoPoint If the type of the Rhino object is ``rs.filter.point``. RhinoCurve If the type of the Rhino object is ``rs.filter.curve``. RhinoMesh If the type of the Rhino object is ``rs.filter.mesh``. RhinoSurface If the type of the Rhino object is ``rs.filter.surface``. Examples -------- >>> """ from compas_rhino.geometry import RhinoPoint from compas_rhino.geometry import RhinoCurve from compas_rhino.geometry import RhinoMesh from compas_rhino.geometry import RhinoSurface otype = rs.ObjectType(guid) if otype == rs.filter.point: return RhinoPoint(guid) if otype == rs.filter.curve: return RhinoCurve(guid) if otype == rs.filter.mesh: return RhinoMesh(guid) if otype == rs.filter.surface: return RhinoSurface(guid)
def closest_point_on_boundaries(self, xyz): """Return the XYZ coordinates of the closest point on the boundaries of the surface from input XYZ-coordinates. Parameters ---------- xyz : list XYZ coordinates. Returns ------- list The XYZ coordinates of the closest point on the boundaries of the surface. """ borders = self.borders(type=0) proj_dist = { tuple(proj_xyz): distance_point_point(xyz, proj_xyz) for proj_xyz in [RhinoCurve(border).closest_point(xyz) for border in borders] } delete_objects(borders) return min(proj_dist, key=proj_dist.get)
kmax = 300 # select the original mesh # select the border # select the fixed points guid_target = compas_rhino.select_mesh() guid_border = compas_rhino.select_polyline() guid_points = compas_rhino.select_points() # wrap the Rhino mesh object for convenience # wrap the Rhino curve object for convenience # get the point coordinates target = RhinoMesh(guid_target) border = RhinoCurve(guid_border) points = compas_rhino.get_point_coordinates(guid_points) # make a mesh datastructure from the Rhino mesh # triangulate the mesh mesh = mesh_from_guid(Mesh, guid_target) mesh_quads_to_triangles(mesh) # identify the fixed vertices # by matching the coordinates of the selected points # up to a precision keys = mesh_identify_vertices(mesh, points, '1f') fixed = set(keys)
from compas_rhino.geometry import RhinoCurve from compas_rhino.artists import MeshArtist # ============================================================================== # RPC # ============================================================================== igl = Proxy("compas_libigl") # ============================================================================== # Input # ============================================================================== # boundary guids = compas_rhino.select_curves() curve = RhinoCurve.from_guid(guids[0]) points = [list(point) for point in curve.points] boundary = points # segments guids = compas_rhino.select_curves() curve = RhinoCurve.from_guid(guids[0]) points = curve.divide(10, over_space=True) segments = points # hole guids = compas_rhino.select_curves() curve = RhinoCurve.from_guid(guids[0]) points = curve.divide(10, over_space=True) hole = points
def RunCommand(is_interactive): scene = get_scene() if not scene: return proxy = get_proxy() if not proxy: return conforming_delaunay_triangulation = proxy.function( 'compas.geometry.conforming_delaunay_triangulation') boundary_guids = compas_rhino.select_curves('Select outer boundary.') if not boundary_guids: return hole_guids = compas_rhino.select_curves('Select inner boundaries.') segments_guids = compas_rhino.select_curves('Select constraint curves.') target_length = rs.GetReal('Specifiy target edge length.', 1.0) if not target_length: return gkey_constraints = {} # outer boundary boundary = [] for guid in boundary_guids: compas_rhino.rs.EnableRedraw(False) segments = compas_rhino.rs.ExplodeCurves(guid) for segment in segments: curve = RhinoCurve.from_guid(segment) N = max(int(curve.length() / target_length), 1) points = map(list, curve.divide(N, over_space=True)) for point in points: gkey = geometric_key(point) if gkey not in gkey_constraints: gkey_constraints[gkey] = [] gkey_constraints[gkey].append(segment) boundary.extend(points) compas_rhino.delete_objects(segments, purge=True) compas_rhino.rs.EnableRedraw(True) # constraint polylines polylines = [] if segments_guids: for guid in segments_guids: curve = RhinoCurve.from_guid(guid) N = int(curve.length() / target_length) or 1 points = map(list, curve.divide(N, over_space=True)) for point in points: gkey = geometric_key(point) if gkey not in gkey_constraints: gkey_constraints[gkey] = [] gkey_constraints[gkey].append(guid) polylines.append(points) # hole polygons polygons = [] if hole_guids: for guid in hole_guids: curve = RhinoCurve.from_guid(guid) N = int(curve.length() / target_length) or 1 points = map(list, curve.divide(N, over_space=True)) for point in points[:-1]: gkey = geometric_key(point) if gkey not in gkey_constraints: gkey_constraints[gkey] = [] gkey_constraints[gkey].append(guid) polygons.append(points) area = target_length**2 * 0.5 * 0.5 * 1.732 vertices, faces = conforming_delaunay_triangulation(boundary, polylines=polylines, polygons=polygons, angle=30, area=area) # vertices, faces = constrained_delaunay_triangulation(boundary, polylines=polylines, polygons=polygons) vertices[:] = [[float(x), float(y), float(z)] for x, y, z in vertices] pattern = Pattern.from_vertices_and_faces(vertices, faces) gkey_key = { geometric_key(pattern.vertex_coordinates(key)): key for key in pattern.vertices() } for gkey in gkey_constraints: guids = gkey_constraints[gkey] if gkey in gkey_key: key = gkey_key[gkey] if len(guids) > 1: pattern.vertex_attribute(key, 'is_fixed', True) pattern.vertex_attribute(key, 'constraints', [str(guid) for guid in guids]) compas_rhino.rs.HideObject(boundary_guids + hole_guids + segments_guids) scene.clear() scene.add(pattern, name='pattern') scene.update() print( "Pattern object successfully created. Input geometry have been hidden." )