irfpy.util.cone

Cone is a cone, a geometry.

Code author: Yoshifumi Futaana

irfpy.util.cone.get_surface_vectors(axis_vector, cone_angle_deg, ndiv=180)[source]

Make vectors of cone surfaces.

Parameters
  • axis_vector (np.array) – A 3-D vector.

  • cone_angle_deg (float) – Cone angle in degrees

Returns

Vectors in (3, 180) shaped ndarray. Normalized.

Return type

np.array

The cone vectors, with its center acis vextor of (1, 1, -1) and the angle 60 degrees can be calculated as follows.

>>> vectors = get_surface_vectors((1., 1., -1.), 60.0)
>>> print(vectors.shape)
(3, 180)
>>> import numpy as np
>>> cos_angles = np.array((1., 1., -1)).dot(vectors) / np.sqrt(3)
>>> np.allclose(cos_angles, 0.5)   # All the values are 0.5, i.e. 60 deg
True
class irfpy.util.cone.Cone(apex, axis, cone_angle)[source]

Bases: object

A cone. Single direction.

Parameters
  • apex – The location of the apex. (3,) shaped numpy array

  • axis – The direction. (3,) shaped numpy array

  • cone_angle – Cone angle in degrees

apex

The coordinate of the apex

axis

“Normal vector of the cone central axis

cone_angle

Cone angle in degrees

get_surface_vectors(length=1.0, ndiv=180)[source]
Parameters

ndiv

Returns

(ndiv, 3) shaped vector

Note

The returned dimension is different (transposed) from get_surface_vectors()!! It is because the (N, 3) shape is more intuitive for specifying multiple 3-D vectors.

>>> cone = Cone([-1, 0, 0], [1, 0, 0], 45)
>>> surf = cone.get_surface_vectors(ndiv=4)
>>> print(surf)
[[-2.92893219e-01  0.00000000e+00 -7.07106781e-01]
 [-2.92893219e-01  6.12372436e-01  3.53553391e-01]
 [-2.92893219e-01 -6.12372436e-01  3.53553391e-01]
 [-2.92893219e-01 -1.73191211e-16 -7.07106781e-01]]
get_surface_vectors_from_apex(length=1.0, ndiv=180)[source]
within(points)[source]

Return a list of in-out.

Multipoint-version of in-out determinator. For a single point, you can use

>>> cone = Cone([0, 0, 0], [1, 0, 0], 45)    # Apex at origin, axis in a-direction, 45 deg cone-angle
>>> (3, 0, 0) in cone     # Return if (3, 0, 0) is in the cone.
True

This within() method get multiple point.

>>> points = [[0, 0, 0], [1, 0, 0], [2, 0, 0], [-1, 0, 0]]
>>> cone.within(points)
array([ True,  True,  True, False])

It is equivalent to

>>> [p in cone for p in points]
[True, True, True, False]
Parameters

points – (N, 3) shaped array representing 3-D points

Returns

(N,) shpaed boolean array