# trimesh.points module¶

## points.py¶

Functions dealing with (n, d) points.

Classes

 `PointCloud`(vertices[, colors, metadata]) Hold 3D points in an object which can be visualized in a scene.

Functions

 `k_means`(points, k, **kwargs) Find k centroids that attempt to minimize the k- means problem: `major_axis`(points) Returns an approximate vector representing the major axis of points `plane_fit`(points) Given a set of points, find an origin and normal using SVD. `plot_points`(points[, show]) Plot an (n,3) list of points using matplotlib `point_plane_distance`(points, plane_normal[, …]) The minimum perpendicular distance of a point to a plane. `project_to_plane`(points[, plane_normal, …]) Projects a set of (n,3) points onto a plane. `radial_sort`(points, origin, normal) Sorts a set of points radially (by angle) around an origin/normal. `remove_close`(points, radius) Given an (n, m) array of points return a subset of points where no point is closer than radius. `tsp`(points[, start]) Find an ordering of points where each is visited and the next point is the closest in euclidean distance, and if there are multiple points with equal distance go to an arbitrary one.
class `trimesh.points.``PointCloud`(vertices, colors=None, metadata=None, **kwargs)

Hold 3D points in an object which can be visualized in a scene.

Methods

 `apply_transform`(transform) Apply a homogeneous transformation to the PointCloud object in- place. Safely get a copy of the current point cloud. `export`([file_obj, file_type]) Export the current pointcloud to a file object. Get an MD5 hash of the current vertices. Merge vertices closer than tol.merge (default: 1e-8) A scene containing just the PointCloud `show`(**kwargs) Open a viewer window displaying the current PointCloud

Attributes

 `bounds` The axis aligned bounds of the PointCloud `centroid` The mean vertex position `colors` Stored per- point color `convex_hull` A convex hull of every point. `extents` The size of the axis aligned bounds `is_empty` Are there any vertices defined or not. `shape` Get the shape of the pointcloud `vertices` Vertices of the PointCloud
`apply_transform`(transform)

Apply a homogeneous transformation to the PointCloud object in- place.

Parameters

transform ((4, 4) float) – Homogeneous transformation to apply to PointCloud

property `bounds`

The axis aligned bounds of the PointCloud

Returns

bounds – Miniumum, Maximum verteex

Return type

(2, 3) float

property `centroid`

The mean vertex position

Returns

centroid – Mean vertex position

Return type

(3,) float

property `colors`

Stored per- point color

Returns

colors – Per- point RGBA color

Return type

(len(self.vertices), 4) np.uint8

property `convex_hull`

A convex hull of every point.

Returns

convex_hull – A watertight mesh of the hull of the points

Return type

trimesh.Trimesh

`copy`()

Safely get a copy of the current point cloud.

Copied objects will have emptied caches to avoid memory issues and so may be slow on initial operations until caches are regenerated.

Current object will not have its cache cleared.

Returns

copied – Copy of current point cloud

Return type

trimesh.PointCloud

`export`(file_obj=None, file_type=None, **kwargs)

Export the current pointcloud to a file object. If file_obj is a filename, file will be written there. Supported formats are xyz :param file_obj: str, file name where to save the pointcloud

None, if you would like this function to return the export blob

Parameters

file_type (str) – Which file type to export as. If file name is passed this is not required

property `extents`

The size of the axis aligned bounds

Returns

extents – Edge length of axis aligned bounding box

Return type

(3,) float

property `is_empty`

Are there any vertices defined or not.

Returns

empty – True if no vertices defined

Return type

bool

`md5`()

Get an MD5 hash of the current vertices.

Returns

md5 – Hash of self.vertices

Return type

str

`merge_vertices`()

Merge vertices closer than tol.merge (default: 1e-8)

`scene`()

A scene containing just the PointCloud

Returns

scene – Scene object containing this PointCloud

Return type

trimesh.Scene

property `shape`

Get the shape of the pointcloud

Returns

shape – Shape of vertex array

Return type

(2,) int

`show`(**kwargs)

Open a viewer window displaying the current PointCloud

property `vertices`

Vertices of the PointCloud

Returns

vertices – Points in the PointCloud

Return type

(n, 3) float

`trimesh.points.``k_means`(points, k, **kwargs)

Find k centroids that attempt to minimize the k- means problem: https://en.wikipedia.org/wiki/Metric_k-center

Parameters
• points ((n, d) float) – Points in a space

• k (int) – Number of centroids to compute

• **kwargs (dict) – Passed directly to scipy.cluster.vq.kmeans

Returns

• centroids ((k, d) float) – Points in some space

• labels ((n) int) – Indexes for which points belong to which centroid

`trimesh.points.``major_axis`(points)

Returns an approximate vector representing the major axis of points

Parameters

points ((n, dimension) float, points in space) –

Returns

axis

Return type

(dimension,) float, vector along approximate major axis

`trimesh.points.``plane_fit`(points)

Given a set of points, find an origin and normal using SVD.

Parameters

points ((n,3) float) – Points in 3D space

Returns

• C ((3,) float) – Point on the plane

• N ((3,) float) – Normal vector of plane

`trimesh.points.``plot_points`(points, show=True)

Plot an (n,3) list of points using matplotlib

Parameters
• points ((n, 3) float) – Points in space

• show (bool) – If False, will not show until plt.show() is called

`trimesh.points.``point_plane_distance`(points, plane_normal, plane_origin=[0.0, 0.0, 0.0])

The minimum perpendicular distance of a point to a plane.

Parameters
• points ((n, 3) float, points in space) –

• plane_normal ((3,) float, normal vector) –

• plane_origin ((3,) float, plane origin in space) –

Returns

distances

Return type

(n,) float, distance from point to plane

`trimesh.points.``project_to_plane`(points, plane_normal=[0, 0, 1], plane_origin=[0, 0, 0], transform=None, return_transform=False, return_planar=True)

Projects a set of (n,3) points onto a plane.

Parameters
• points ((n,3) array of points) –

• plane_normal

• plane_origin

• transform (None or (4,4) matrix. If specified, normal/origin are ignored) –

• return_transform (bool, if true returns the (4,4) matrix used to project points) – onto a plane

• return_planar (bool, if True, returns (n,2) points. If False, returns) – (n,3), where the Z column consists of zeros

`trimesh.points.``radial_sort`(points, origin, normal)

Sorts a set of points radially (by angle) around an origin/normal.

Parameters
• points ((n,3) float, points in space) –

• origin ((3,) float, origin to sort around) –

• normal ((3,) float, vector to sort around) –

Returns

ordered

Return type

(n,3) flot, re- ordered points in space

`trimesh.points.``remove_close`(points, radius)

Given an (n, m) array of points return a subset of points where no point is closer than radius.

Parameters
• points ((n, dimension) float) – Points in space

Returns

• culled ((m, dimension) float) – Points in space

• mask ((n,) bool) – Which points from the original points were returned

`trimesh.points.``tsp`(points, start=0)

Find an ordering of points where each is visited and the next point is the closest in euclidean distance, and if there are multiple points with equal distance go to an arbitrary one.

Assumes every point is visitable from every other point, i.e. the travelling salesman problem on a fully connected graph. It is not a MINIMUM traversal; rather it is a “not totally goofy traversal, quickly.” On random points this traversal is often ~20x shorter than random ordering.

Parameters
• points ((n, dimension) float) – ND points in space

• start (int) – The index of points we should start at

Returns

• traversal ((n,) int) – Ordered traversal visiting every point

• distances ((n - 1,) float) – The euclidean distance between points in traversal