geometry_utils#

geometry_utils.py

This module contains utility functions for performing geometric calculations related to the ClearMap vasculature analysis. Generally 3D coordinates are represented as a 3-column array, with each row representing a different point. For example, a set of 3 points in 3D space would be represented as:

[[x1, y1, z1], [x2, y2, z2], [x3, y3, z3]]

Functions:#

angle_between_vectors(vectors_1, vectors_2, in_degrees=True):

Compute the angle between two sets of vectors. By default, the angle is returned in degrees.

cartesian_to_polar(x, y, ceval=numexpr.evaluate):

Transform from cartesian to polar coordinates. It takes in x and y coordinates and a backend to use for computation (either eval for pure Numpy or numexpr.evaluate for Numexpr).

f_min(X, p):

Calculate the minimum distance from a set of points X to a plane defined by p. The plane is defined by a vector (the first three elements of p) and a scalar p[3]. The vector represents the normal to the plane, and p[3] is the distance from the origin to the plane along this normal. The function calculates the distance from each point in X to the plane, and then normalizes these distances by the length of the normal vector.

angle_between_vectors(vectors_1, vectors_2, in_degrees=True)[source]#

Compute the angle between two sets of vectors. By default, the angle is returned in degrees.

Parameters:
  • vectors_1 (ndarray) – The first set of vectors

  • vectors_2 – The second set of vectors

  • in_degrees (bool) – Whether to return the angle in degrees or radians

Returns

cartesian_to_polar(x, y, ceval=<function evaluate>)[source]#

Transform from cartesian to polar x: ndarray coordinates y: ndarray coordinates ceval: backend to use: - eval : pure Numpy - numexpr.evaluate: Numexpr

Returns

compute_grid(coordinates, grid_n_pts=100)[source]#

Compute a grid of coordinates from the source coordinates to interpolate the vectors (e.g. flow vectors) onto

Parameters:
  • coordinates (np.array) – The coordinates of the edges

  • grid_n_pts (int) – The number of points to use for each axis of the grid This determine the granularity of the grid

Returns

f_min(X, p)[source]#

Calculate the minimum distance from a set of points X to a plane defined by p.

Parameters:
  • X (ndarray) – The coordinates of the points.

  • p (ndarray) – The parameters defining the plane. The first three elements are the normal to the plane, and the last element is the distance from the origin to the plane along this normal.

Returns

ndarray

The normalized distances from the points to the plane.

interpolate_vectors(vectors, source_coordinates, interpolated_coordinates)[source]#

Interpolate the vectors from source_coordinates to interpolated_coordinates

Parameters:
  • vectors (np.array) – The vectors to interpolate. The shape should be (n_points, 3)

  • source_coordinates (np.array) – The coordinates of the source points. The shape should be (n_points, 3)

  • interpolated_coordinates (np.array) – The coordinates of the points to interpolate the vectors onto. The shape should be (n_points, 3)

Returns