示例#1
0
def delaunay(vertices, src='compas', cls=None):
    """Group the Delaunay functions from compas, numpy.

	Parameters
	----------
	vertices : list
		List of vertex coordinates.
	src : string
		Specify Delaunay algorithm to use: compas or numpy.
	cls
		Mesh class.

	Returns
	-------
	cls
		The Delaunay mesh.

	"""

    if cls is None:
        cls = Mesh

    if src == 'compas':
        faces = delaunay_from_points(vertices)

    elif src == 'numpy_rpc':
        faces = delaunay_numpy_rpc(vertices)
    elif src == 'numpy_xfunc':
        faces = XFunc(
            'compas_pattern.algorithms.decomposition.triangulation.delaunay_numpy_xfunc'
        )(vertices)
    else:
        return None

    return cls.from_vertices_and_faces(vertices, faces)
def delaunay_compas(vertices):
    """Delaunay triangulation from compas.

	Parameters
	----------
	vertices : list
		List of vertex coordinates.

	Returns
	-------
	list
		List of face vertices.

	"""

    return delaunay_from_points(vertices)
示例#3
0
    def from_points(cls, points, boundary=None, holes=None):
        """Construct a mesh from a delaunay triangulation of a set of points.

        Parameters
        ----------
        points : list[list[float]]
            XYZ coordinates of the points.
            Z coordinates should be zero.

        Returns
        -------
        :class:`compas.datastructures.Mesh`
            A mesh object.

        """
        from compas.geometry import delaunay_from_points
        faces = delaunay_from_points(points, boundary=boundary, holes=holes)
        return cls.from_vertices_and_faces(points, faces)
from compas.datastructures import Mesh
from compas.geometry import delaunay_from_points

from compas_rhino.artists import MeshArtist

# select the points
# select the boundary
# select the hole(s)

guids = compas_rhino.select_points("Select points.")
points = compas_rhino.get_point_coordinates(guids)

guid = compas_rhino.select_polyline("Select boundary.")
boundary = compas_rhino.get_polyline_coordinates(guid)

guids = compas_rhino.select_polylines("Select holes.")
holes = [compas_rhino.get_polyline_coordinates(guid) for guid in guids]

# make a delaunay triangulation
# within the boundary
# and around the holes

faces = delaunay_from_points(points, boundary=boundary, holes=holes)
mesh = Mesh.from_vertices_and_faces(points, faces)

# draw the result

artist = MeshArtist(mesh)
artist.draw_mesh()
artist.redraw()
                   allow_boundary_split=True,
                   allow_boundary_swap=True,
                   callback=callback)
    st[running_key] = False


if running_key not in st:
    st[running_key] = False

if mesh_key not in st or start:

    # divide the boundary curve into segments of a specific length
    points = rs.DivideCurve(boundary, rs.CurveLength(boundary) / length)

    # generate a delaunay triangulation from the points on the boundary
    faces = delaunay_from_points(points, boundary=points)

    # save mesh into sticky dictionary
    st[mesh_key] = Mesh.from_vertices_and_faces(points, faces)

# start or restart

if start and st[running_key] is False:
    thread = Thread(target=threaded_function)
    thread.start()
    st[running_key] = True

# make the result visible in the outlet 'mesh'

if rmesh_key in st:
    mesh = st[rmesh_key]
示例#6
0
#         a, b, c = delaunay.face_coordinates(key)
#         center, radius, normal = circle_from_points_xy(a, b, c)
#         voronoi.vertex[key]['x'] = center[0]
#         voronoi.vertex[key]['y'] = center[1]
#         voronoi.vertex[key]['z'] = center[2]

#     return voronoi

# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    from compas.datastructures import Mesh
    from compas.geometry import pointcloud_xy
    from compas.geometry import delaunay_from_points
    from compas.plotters import MeshPlotter

    points = pointcloud_xy(20, (0, 50))
    faces = delaunay_from_points(points)

    delaunay = Mesh.from_vertices_and_faces(points, faces)

    plotter = MeshPlotter(delaunay, figsize=(12, 8))

    plotter.draw_vertices(radius=0.1)
    plotter.draw_faces()

    plotter.show()