The class component is a representation of elements used in the simulation.
Most of its methods are abstract (throw a NotImplementedError) because the really useful classes are its derivatives:
However, this class exists to stipulate a common interface for all elements in simulation, allowing a tree-like nesting of them.
Some attributes (x, y, z, origin, id) are not directly changeable (for obvious reasons), only with geometrical transforms, etc, so no setter is implemented, and if you try to change them, you will get an error.
There is also a implementation of the visitor pattern using the acceptVisitor method
Methods
This method allows the alignment of the part to a specific direction (this is very useful in optical systems definition).
The implementation assumes that at least two orthogonal vectors are given. There is an assertion to guarantee that.
With the new vector base, a rotation matrix M is calculated, and the formulation to convert rotation matrix to axis-angle is used for convenience (as then the method rotate can be directly called).
Obs: No concerns about code efficiency are made, as this method will probably not be used all the time.
Parameters : | x_new, [y_new, z_new] : numpy.ndarray \((1,3)\)
pivotPoint : numpy.ndarray \((1,3)\)
tol : 1e-8
|
---|---|
Raises : | AssertionError :
LinAlgError :
|
Returns the extremities of the aligned to axis bounding box of the component in the format:
[[xmin, ymin, zmin],
[xmax, ymax, zmax]]
If the component is not visible by ray tracing rays, the function shall return None
This method must be implemented by each inheriting class. Its function is to avoid classes having inconsistent data after a geometric transform.
For example: a camera has a mapnp.ping funcion calculated from raytracing, then the user moves this camera, making the mapnp.ping invalid.
When a rotation or translation is called the clearData method is also called, and the class is in charge of cleaning all data that is now not valid anymore.
This is a method used specifically for ray tracing. The method returns data about the first intersection between line segments and the polygons defined in the Component. The implementation of the intersection is given by the inheriting classes.
Parameters : | p0, p1 - numpy.ndarray :math:`(N, 3)` :
tol - double :
|
---|---|
Returns : | None :
Otherwise returns a list with:: : lineParameter :
intersectionCoordinates :
triangleIndexes :
normals :
part :
|
Reference to the component parent. Ideally this should be a weak reference to avoid memory leaks. As python does not provide a clean implementation of weakref, one must use always the remove method of Assembly to clear this field and avoid leaks
This method should be used when there is a change in the component position. This method operates only with the origin and the x, y and z vectors. It delegates the responsibility to the inheriting class by means of the rotateImplementation method.
Parameters : | angle :
axis : numpy.ndarray \((1, 3)\)
pivotPoint : numpy.ndarray \((1, 3)\)
|
---|
This method must be implemented by the interested inheriting class in case a rotation affects its internals.
For example: a class with a vector of points P will probably need to update them accordingly using the following code:
P = Utils.rotatePoints(P,angle,axis,pivotPoint)
This is a way of implementing the Chain of Responsibility pattern, so that these geometrical operations are executed recursively.
This is a protected method, do not use it unless you are inheriting from this class!
Parameters : | angle :
axis : numpy.ndarray \((1,3)\)
pivotPoint : numpy.ndarray \((1,3)\)
|
---|---|
Raises : | NotImplementedError : |
This method should be used when there is a change in the component position. This method operates only with the origin position, and delegates the responsibility to the inheriting class by means of the translateImplementation method.
Parameters : | vector : numpy.ndarray \((1, 3)\)
|
---|
This method must be implemented by the interested inheriting class in case a translation affects its internals.
For example: a class with a vector of points P will probably need to update that to P+vector
This is a way of implementing the Chain of Responsibility pattern, so that these geometrical operations are executed recursively.
This is a protected method, do not use it unless you are inheriting from this class!
Parameters : | vector : numpy.ndarray \((1, 3)\)
|
---|---|
Raises : | NotImplementedError : |