Skip to content

class aicafe.Snake (PointSet)

This class represents a curve in a 3D space. The curve is constituted by a series of sequentially connected points, and is thus named a snake. A snake can have some additional attributes for the whole point set (e.g., snake type) or for each point (e.g., radius at each point).

Snake is a subclass of PointSet. While a point set consists of points on a regular grid, Snake forces the points to have a 1D shape, i.e., the point set representing a snake should have a shape of [P, 3], where [P] indicates the number of points in the snake.

To initialize a snake, see __new__() below.

__new__(cls, array, type=None, radii=None)

To initialize a snake, simply generate a point set or an ArrayLike data structure that can initialize a point set, then pass it to Snake().

Parameters:

Name Type Description Default
array ArrayLike

A point set to initialize the snake, or an array to initialize the point set that represents the snake.

required
type int

The snake type represented by an integer. If None, 0 will be the type. See TYPES_SNAKES for the correspondence between integers and the actual snake types.

None
radii Sequence[float]

The radii of points in the snake. If None, the radii are regarded as unknown.

None

Returns:

Type Description
Snake

Initialized snake.

Raises:

Type Description
ValueError

If array cannot be used to initialize a point set, or the initialized point set's shape is not [P, 3], or the number of values in radii does not match the number of points in self.

length(self)

Length of self.

Returns:

Type Description
float

The sum of distances between every two consecutive points on the curve.

Examples:

>>> ac.Snake([[0, 0, 1], [0, 1, 0], [1, 0, 1]]).length # 2 * np.sqrt(2)
3.1462643

lengths_cum(self)

Cumulative lengths of self.

Returns:

Type Description
NDArray

Shape of [P], where \(P\) is the number of points on self. The \(i\)-th element is the length of the curve consisting of the first \(i\) points on self. Particularly, the \(0\)-th element is \(0\).

resample(self, step=None)

Resample points on the curve so that the points are equidistant. The first and last points will be the same.

Parameters:

Name Type Description Default
step

the fixed distance between two consecutive points after resampling.

None

Return

(Snake): The resampled snake. The radius at each point will also be interpolated if not None.

Back to top