xicsrt_math
xicsrt.tools.xicsrt_math
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.
- toarray_1d(a)[source]
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_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.
- normalize(vector)[source]
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
- 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.
Note
The crystal_spacing here is the true spacing, not the 2d spacing that is sometimes used in the literature.
- tor_from_car(point_car, major_radius)[source]
Convert from cartesian to toroidal coordinates.
- Parameters:
point_car (array [meters]) – Cartesian coordinates [x,y,z]
major_radius (float [meters]) – Torus Major Radius
- Returns:
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.
- Parameters:
point_tor (array [meters]) – Toroidal coordinates [r_min, theta_poloidal, theta_toroidal]
major_radius (float [meters]) – Torus Major Radius
- Returns:
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).