km3pipe.math
¶
Maths, Geometry, coordinates.
Module Contents¶
Classes¶
A polygon, to implement containment conditions. |
|
Like a cylinder, but the top is an irregular Polygon. |
|
A Cone, represented by sparse samples. |
Functions¶
|
Flip the direction. |
|
Flip the direction. |
|
Neutrino direction in polar coordinates. |
|
|
|
Neutrino direction in polar coordinates. |
|
|
|
Return the zenith angle in radians. |
|
Return the azimuth angle in radians. |
|
|
|
Compute the unsigned angle between two vectors. For a stacked input, the |
|
Calculates the magnitude of a vector or array of vectors. |
|
Returns the angle in radians between vectors 'v1' and 'v2'. |
|
Returns the unit vector of the vector. |
|
Calculate the point-line-distance for given point and line. |
|
|
|
Return the distance between two points. |
|
Calculate center of mass for given points. |
|
Calculate the circular permutation for a given list of items. |
|
haversine |
|
Also called Great-circle-distance -- |
|
The Euler–Rodrigues formula. |
|
Returns a mask to select items, within a certain radius around a given center. |
|
Select items within a certain radius around a given center. |
|
Inertia tensor, stolen of thomas |
|
stolen from thomas |
|
stolen from thomas |
|
Logarithm to any base |
|
Rotate a 3D vector using quaternion algebra. |
|
Convert Euler angle to quaternion. |
|
Rotate vectors using quaternion algebra. |
|
Find the closes point for a given set of lines in 3D. |
Attributes¶
- km3pipe.math.neutrino_to_source_direction(phi, theta, radian=True)[source]¶
Flip the direction.
- Parameters:
- phi, theta: neutrino direction
- radian: bool [default=True]
receive + return angles in radian? (if false, use degree)
- km3pipe.math.source_to_neutrino_direction(azimuth, zenith, radian=True)[source]¶
Flip the direction.
- Parameters:
- zenithfloat
neutrino origin
- azimuth: float
neutrino origin
- radian: bool [default=True]
receive + return angles in radian? (if false, use degree)
- km3pipe.math.theta(v)[source]¶
Neutrino direction in polar coordinates.
- Parameters:
- varray (x, y, z)
Notes
Downgoing event: theta = 180deg Horizont: 90deg Upgoing: theta = 0
Angles in radians.
- km3pipe.math.phi(v)[source]¶
Neutrino direction in polar coordinates.
- Parameters:
- varray (x, y, z)
Notes
phi
,theta
is the opposite ofzenith
,azimuth
.Angles in radians.
- km3pipe.math.zenith(v)[source]¶
Return the zenith angle in radians.
- Parameters:
- varray (x, y, z)
Notes
Defined as ‘Angle respective to downgoing’. Downgoing event: zenith = 0 Horizont: 90deg Upgoing: zenith = 180deg
- km3pipe.math.azimuth(v)[source]¶
Return the azimuth angle in radians.
- Parameters:
- varray (x, y, z)
Notes
phi
,theta
is the opposite ofzenith
,azimuth
.This is the ‘normal’ azimuth definition – beware of how you define your coordinates. KM3NeT defines azimuth differently than e.g. SLALIB, astropy, the AAS.org
- km3pipe.math.angle(v1, v2, normalized=False)[source]¶
Compute the unsigned angle between two vectors. For a stacked input, the angle is computed pairwise. Inspired by the “vg” Python package.
- Parameters:
- v1np.array
With shape (3,) or a kx3 stack of vectors.
- v2np.array
A vector or stack of vectors with the same shape as v1.
- normalizedbool
By default, the vectors will be normalised unless normalized is True.
- Returns:
- A float or a vector of floats with the angle in radians.
- km3pipe.math.magnitude(v)[source]¶
Calculates the magnitude of a vector or array of vectors.
- Parameters:
- vnp.array
With shape (3,) or kx3 stack of vectors.
- Returns:
- A float or a vector of floats with the magnitudes.
- km3pipe.math.angle_between(v1, v2, axis=0)[source]¶
Returns the angle in radians between vectors ‘v1’ and ‘v2’.
If axis=1 it evaluates the angle between arrays of vectors.
Examples
>>> angle_between((1, 0, 0), (0, 1, 0)) 1.5707963267948966 >>> angle_between((1, 0, 0), (1, 0, 0)) 0.0 >>> angle_between((1, 0, 0), (-1, 0, 0)) 3.141592653589793 >>> v1 = np.array([[1, 0, 0], [1, 0, 0]]) >>> v2 = np.array([[0, 1, 0], [-1, 0, 0]]) >>> angle_between(v1, v2, axis=1) array([1.57079633, 3.14159265])
- km3pipe.math.pld3(pos, line_vertex, line_dir)[source]¶
Calculate the point-line-distance for given point and line.
- km3pipe.math.dist(x1, x2, axis=0)[source]¶
Return the distance between two points.
Set axis=1 if x1 is a vector and x2 a matrix to get a vector of distances.
- km3pipe.math.com(points, masses=None)[source]¶
Calculate center of mass for given points. If masses is not set, assume equal masses.
- km3pipe.math.circ_permutation(items)[source]¶
Calculate the circular permutation for a given list of items.
- km3pipe.math.space_angle(phi1, theta1, phi2, theta2)[source]¶
Also called Great-circle-distance –
use long-ass formula from wikipedia (last in section): https://en.wikipedia.org/wiki/Great-circle_distance#Computational_formulas
Space angle only makes sense in lon-lat, so convert zenith -> latitude.
- km3pipe.math.rotation_matrix(axis, theta)[source]¶
The Euler–Rodrigues formula.
Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.
- Parameters:
- axis: vector to rotate around
- theta: rotation angle [rad]
- km3pipe.math.spherecutmask(center, rmin, rmax, items)[source]¶
Returns a mask to select items, within a certain radius around a given center.
- Parameters:
- center: array of shape(3,)
central point of the sphere
- rmin: float
minimum radius of the sphere selection
- rmax: float
maximum radius of the sphere selection
- items: array of shape (n, 3) or iterable with pos_[xyz]-attributed items
the items to cut on
- Returns:
- mask of the array of shape (n, 3) or iterable with pos_[xyz]-attributed items.
- km3pipe.math.spherecut(center, rmin, rmax, items)[source]¶
Select items within a certain radius around a given center. This function calls spherecutmask() to create the selection mask and returns the selected items.
- Parameters:
- center: array of shape(3,)
central point of the sphere
- rmin: float
minimum radius of the sphere selection
- rmax: float
maximum radius of the sphere selection
- items: array of shape (n, 3) or iterable with pos_[xyz]-attributed items
the items to cut on
- Returns:
- array of shape (k, 3) or iterable with pos_[xyz]-attributed items
items which survived the cut.
- class km3pipe.math.IrregularPrism(xy_vertices, z_min, z_max)[source]¶
Like a cylinder, but the top is an irregular Polygon.
- class km3pipe.math.SparseCone(spike_pos, bottom_center_pos, opening_angle)[source]¶
A Cone, represented by sparse samples.
This samples evenly spaced points from the base circle.
- Parameters:
- spike_poscoordinates of the top
- bottom_center_poscenter of the bottom circle
- opening_anglecone opening angle, in rad
theta, axis to mantle, not mantle-mantle. So this is the angle to the axis, and mantle-to-mantle (aperture) is 2 theta.
- km3pipe.math.qrot(vector, quaternion)[source]¶
Rotate a 3D vector using quaternion algebra.
Implemented by Vladimir Kulikovskiy.
- Parameters:
- vectornp.array
- quaternionnp.array
- Returns:
- np.array
- km3pipe.math.qeuler(yaw, pitch, roll)[source]¶
Convert Euler angle to quaternion.
- Parameters:
- yawnumber
- pitchnumber
- rollnumber
- Returns:
- np.array
- km3pipe.math.qrot_yaw(vector, heading)[source]¶
Rotate vectors using quaternion algebra.
- Parameters:
- vectornp.array or list-like (3 elements)
- headingthe heading to rotate to [deg]
- Returns:
- np.array
- km3pipe.math.intersect_3d(p1, p2)[source]¶
Find the closes point for a given set of lines in 3D.
- Parameters:
- p1(M, N) array_like
Starting points
- p2(M, N) array_like
End points.
- Returns:
- x(N,) ndarray
Least-squares solution - the closest point of the intersections.
- Raises:
- numpy.linalg.LinAlgError
If computation does not converge.