scalarfield_contours_numpy

compas.numerical.scalarfield_contours_numpy(xy, s, levels=50, density=100)[source]

Compute the contour lines of a scalarfield.

Parameters
  • xy (array-like) – The xy-coordinates at which the scalar field is defined.

  • s (array-like) – The values of the scalar field.

  • levels (int, optional) – The number of contour lines to compute. Default is 50.

Returns

tuple – A tuple of a list of levels and a list of contour geometry.

The list of levels contains the values of the scalarfield at each of the contours. The second item in the tuple is a list of contour lines. Each contour line is a list of paths, and each path is a list polygons.

Notes

The computation of the contour lines is based on the contours function available through matplotlib.

Examples

import compas
from compas.datastructures import Mesh
from compas.geometry import centroid_points
from compas.geometry import distance_point_point
from compas.geometry import scalarfield_contours_numpy

mesh = Mesh.from_obj(compas.get('faces.obj'))

points = [mesh.vertex_coordinates(key) for key in mesh.vertices()]
centroid = centroid_points(points)
distances = [distance_point_point(point, centroid) for point in points]

xy = [point[0:2] for point in points]

levels, contours = scalarfield_contours_numpy(xy, distances)

for i in range(len(contours)):
    level = levels[i]
    contour = contours[i]
    print(level)
    for path in contour:
        for polygon in path:
            print(polygon)