t4_geom_convert.Kernel package

Subpackages

Submodules

t4_geom_convert.Kernel.Progress module

Implementation of a simple progress meter.

class t4_geom_convert.Kernel.Progress.Progress(message, n_items, longest_item)

Bases: object

A simple progress Meter.

update(iteration, item)

Update the object that we have reached iteration and that we are treating item.

The Progress object will print to stdout if we have gained at least one percentage point.

t4_geom_convert.Kernel.VectUtils module

t4_geom_convert.Kernel.VectUtils.isPointOnPlane(point, plane, *, tol=1e-10)

Returns True if the point lies on the plane within the specified tolerance.

>>> point = (1.0, 1.0, 1.0)
>>> plane = ((3.0, 0.0, 0.0), (1.0, 1.0, 1.0))
>>> isPointOnPlane(point, plane)
True
t4_geom_convert.Kernel.VectUtils.isVectorParallelToPlane(vector, plane, *, tol=1e-10)

Returns True if the vector is parallel to the plane within the specified tolerance.

>>> vector = (1.0, 1.0, -2.0)
>>> plane = ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0))
>>> isVectorParallelToPlane(vector, plane)
True
>>> isVectorParallelToPlane(rescale(2.0, vector), plane)
True
>>> isVectorParallelToPlane(plane[1], plane)
False
t4_geom_convert.Kernel.VectUtils.mag(vec)

Return the magnitude of vec.

t4_geom_convert.Kernel.VectUtils.mag2(vec)

Return the square of the magnitude of vec.

t4_geom_convert.Kernel.VectUtils.matrix_rows(matrix)

Transform a 3x3 matrix into the list of its rows.

>>> mat = [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> matrix_rows(mat)
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
t4_geom_convert.Kernel.VectUtils.mixed(v1, v2, v3)

Yields the mixed product of v1, v2 and v3.

The mixed product is defined as v1 · (v2 × v3) and is equal to the determinant of the matrix having the components of v1, v2 and v3 as rows.

t4_geom_convert.Kernel.VectUtils.planeParamsFromNormalAndPoint(normal, point)

Return the MCNP-style parameters of the plane having the given normal and passing through the given points.

t4_geom_convert.Kernel.VectUtils.planeParamsFromPoints(pt1, pt2, pt3)

Compute the parameters (a ,b, c, d) of the plane passing through the three given points pt1, pt2, pt3.

The equation of the plane is written in the MCNP form as

\[a x + b y + c z - d = 0\]

Furthermore, the normal to the plane is oriented in such as way that the origin has negative sense (this is the MCNP convention).

t4_geom_convert.Kernel.VectUtils.planeSide(point, plane)

Returns 1 if point lies on the positive side of the plane, -1 if it lies on the negative side and 0 if it lies on the plane (no numerical tolerance).

t4_geom_convert.Kernel.VectUtils.pointInPlaneIntersection(plane1, plane2)

Construct a point in the intersection of two planes. The planes must be given as a (point, normal) pair.

>>> from math import isclose
>>> def is_in_plane(point, plane):
...     pt, norm = plane
...     return isclose(scal(vdiff(point, pt), norm), 0., abs_tol=1e-10)
>>> plane1 = ((0, 0, 0), (1, 0, 0))
>>> plane2 = ((0, 0, 0), (0, 1, 0))
>>> pointInPlaneIntersection(plane1, plane2)
((0.0, 0.0, 0.0), (0.0, 0.0, 1.0))
>>> plane1 = ((0, 0, 0), (1, 0, 0))
>>> plane2 = ((0, 5, 0), (0, 1, 0))
>>> int_p, line_vec = pointInPlaneIntersection(plane1, plane2)
>>> is_in_plane(int_p, plane1) and is_in_plane(int_p, plane2)
True
>>> isclose(scal(line_vec, (1, 0, 0)), 0., abs_tol=1e-10)
True
>>> isclose(scal(line_vec, (0, 1, 0)), 0., abs_tol=1e-10)
True
t4_geom_convert.Kernel.VectUtils.projectPointOnPlane(point, plane, direction)

Project a point on a plane along the given direction.

>>> from math import isclose, sqrt
>>> point = (0, 0, 3)
>>> plane = ((0, 0, 0), (0, 0, 1))
>>> direction = (1, 0, 1)
>>> proj = projectPointOnPlane(point, plane, direction)
>>> expected = (-3, 0, 0)
>>> all(isclose(p, e, abs_tol=1e-10) for p, e in zip(proj, expected))
True
>>> point = (0, 0, 3)
>>> plane = ((0, 0, 1), (0, 0, 1))
>>> direction = (2, 0, 1)
>>> proj = projectPointOnPlane(point, plane, direction)
>>> expected = (-4, 0, 1)
>>> all(isclose(p, e, abs_tol=1e-10) for p, e in zip(proj, expected))
True
t4_geom_convert.Kernel.VectUtils.renorm(vec, norm=1.0)

Return a new vector parallel to vec whose norm is equal to norm.

t4_geom_convert.Kernel.VectUtils.rescale(a, v1)

Return v1 multiplied by a scalar a, as a new vector.

t4_geom_convert.Kernel.VectUtils.rotate(vec, axis, angle)

Rotate vector vec around the axis axis by angle angle, according to the right-hand rule.

This function uses Rodrigues’ rotation formula. If we denote vec as v, the angle as θ and the axis as k, the formula reads:

\[v' = v \cos(\theta) + (k ^ v) \sin(\theta) + k (k\cdot v) (1 - \cos(\theta))\]

Examples:

>>> from math import pi
>>> vec = (1, 1, 0)
>>> axis = (0, 0, 1)
>>> rot_vec = rotate(vec, axis, 0.5*pi)
>>> print('({:.5f}, {:.5f}, {:.5f})'.format(*rot_vec))
(-1.00000, 1.00000, 0.00000)
>>> rot_vec = rotate(vec, axis, 0.25*pi)
>>> print('({:.5f}, {:.5f}, {:.5f})'.format(*rot_vec))
(0.00000, 1.41421, 0.00000)
Parameters:
  • vec – the vector to rotate

  • axis – the rotation axis (must be a unit vector)

  • angle – the rotation angle, in radians

t4_geom_convert.Kernel.VectUtils.rotation_from_vectors(vector_from, vector_to)

Return a rotation matrix transforming vector_from into a vector parallel to vector_to.

>>> rotation_from_vectors((0.0, 0.0, 1.0), (0.0, 0.0, 1.0))
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])
>>> rotation_from_vectors((0.0, 0.0, 3.0), (0.0, 0.0, 5.0))
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])
>>> rotation_from_vectors((0.0, 0.0, 1.0), (0.0, 1.0, 0.0))
array([[ 1.,  0.,  0.],
       [ 0.,  0.,  1.],
       [ 0., -1.,  0.]])
t4_geom_convert.Kernel.VectUtils.scal(v1, v2)

Yields the scalar product of v1 and v2.

t4_geom_convert.Kernel.VectUtils.transpose(matrix)

Transpose a 3x3 matrix.

>>> mat = [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> transpose(mat)
[1, 4, 7, 2, 5, 8, 3, 6, 9]
t4_geom_convert.Kernel.VectUtils.vdiff(v1, v2)

Return the vector difference of v1 and v2 (v1-v2).

t4_geom_convert.Kernel.VectUtils.vect(v1, v2)

Yields the vector product of v1 and v2.

t4_geom_convert.Kernel.VectUtils.vsum(*args)

Return the vector sum of its arguments.

Module contents