irfpy.util.vectortools
¶
Vector (numpy array) related functions
Vector tools for numpy array. Most of the funcitons (are intended to) support the 2-D (or >2-D) array, namely, (N, 3) (or (N0, N1, …, 3)) array.
Related modules:
Code author: Yoshifumi Futaana
|
Calculate the distance to the center axis of the cylinder. |
|
Return cone angle in radians. |
- irfpy.util.vectortools.distance_to_cylinder_center(vector, center_axis, cylinder_center=(0, 0, 0))[source]¶
Calculate the distance to the center axis of the cylinder.
Calculate the distance between a given vector, v, and the center of the given cylinder. The cylinder is defined by a vector, cylinder_center p, together with the axis vector, center_axis n.
- Parameters:
vector – Vector(s) for which the distance(s) are calculated. (3,) or (…, 3) array.
cylinder_center – Specifies the center of the cylinder. A single point on the axis. (3,) array
cylinder_axis – Specifies the axis vector of the cylinder. A single vector. (3,) array.
Examples follow.
>>> p = (2, 1, 0) >>> n = (0, 0.5, 0) >>> v = (0, 0, 0) >>> distance_to_cylinder_center(v, n, cylinder_center=p) 2.0
>>> v = (2, 0, 0) >>> distance_to_cylinder_center(v, n, cylinder_center=p) 0.0
>>> v = [(0, 0, 0), (0, 1, 0), (1, 0, 0), (0, 0, 1)] >>> distance_to_cylinder_center(v, n, cylinder_center=p) array([2. , 2. , 1. , 2.23606798])
The implementaion is as follows.
First, the cylinder_center is translated to the origin (0, 0, 0). The transformation does not change the center axis, n, but the given vector v is converted to \(\vec{v}' = \vec{v} - \vec{p}\).
The distance d is now calculated by \(d = |v'| \sin\alpha\) where \(\alpha\) is the angle between the v’ and n vectors. Thus, \(\cos\alpha = \vec{v'}\cdot{n} / |v'||n|\), and therefore, the distance is
\[\begin{split}d = |v'| \sin\alpha = |v'| \sqrt{1 - \cos^2\alpha} \\ = \sqrt{|v'|^2 - \frac{\vec{n}\cdot\vec{v'}}{|n|^2}}\end{split}\]
- irfpy.util.vectortools.cone_angle(vector, cone_axis, cone_center=(0, 0, 0))[source]¶
Return cone angle in radians.
- Parameters:
vector – Vector for input. (3, ) or (…, 3) array
cone_axis – Vector of the axis, along the line.
cone_center – The top of the cone.
- Returns:
The cone angle in radians. Scalar or (…) shaped.
>>> p = (1, 3, 0) >>> a = (0, 2, 0)
>>> v = (1, 0, 0) >>> print(np.rad2deg(cone_angle(v, a, cone_center=p))) 180.0
>>> v = (1, 4, 0) >>> print(np.rad2deg(cone_angle(v, a, cone_center=p))) 0.0
>>> v = [(1, 0, 0), (1, 1, 0), (1, 2, 0), (1, 4, 0), (2, 3, 0)] >>> print(np.rad2deg(cone_angle(v, a, cone_center=p))) [180. 180. 180. 0. 90.]
>>> v = [2, 3, 0]