A set of mathematical utilities and vector convenience functions for XICSRT.

distance_point_to_line(origin, normal, point)[source]

Find the closest distnace between a point and a line in 3D.

intersect_ray_plane(ray, plane)[source]

Find the intersection between a ray and a plane in 3D.


Convert the input to a ndarray with at least 1 dimension. This is similar to the numpy function atleast_1d, but has less overhead and is jax compatible.

vector_angle(a, b)[source]

Find the angle between two vectors.

vector_rotate(a, b, theta)[source]

Rotate vector a around vector b by an angle theta (radians)

Programming Notes

u: parallel projection of a on b_hat. v: perpendicular projection of a on b_hat. w: a vector perpendicular to both a and b.


Calculate magnitude of a vector or array of vectors.


Normalize a vector or an array of vectors. If an array of vectors is given it should have the shape (N,M) where | N: Number of vectors | M: Vector length

sinusoidal_spiral(phi, b, r0, theta0)[source]
rotation_matrix(axis, theta)[source]

Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.

bragg_angle(wavelength, crystal_spacing)[source]

The Bragg angle calculation is used so often that it deserves its own function.


The crystal_spacing here is the true spacing, not the 2d spacing that is sometimes used in the literature.


Convert from cartesian to cylindrical coordinates.


Convert from cylindrical to cartesian coordinates.

tor_from_car(point_car, major_radius)[source]

Convert from cartesian to toroidal coordinates.

  • point_car (array [meters]) – Cartesian coordinates [x,y,z]
  • major_radius (float [meters]) – Torus Major Radius

point_tor – Toroidal coordinates [r_min, theta_poloidal, theta_toroidal]

Return type:

array [meters]

car_from_tor(point_tor, major_radius)[source]

Convert from toroidal to cartesian coordinates.

  • point_tor (array [meters]) – Toroidal coordinates [r_min, theta_poloidal, theta_toroidal]
  • major_radius (float [meters]) – Torus Major Radius

point_car – Cartesian coordinates [x,y,z]

Return type:

array [meters]

point_in_triangle_2d(pt, p0, p1, p2)[source]

Determine if a point (or set of points) fall within a triangle as specified by three vertices. Calculation is performed in two dimensions (2D).

Private Members