A ray of light. Has the physical attributes of position, direction and wavelength. Attributes ---------- position : tuple of float The (x, y, z) position. direction : tuple of floats Direction unit vector (n_i, n_j, n_k). wavelength : float The
| 10 | |
| 11 | @dataclass(frozen=True) |
| 12 | class Ray: |
| 13 | """ A ray of light. Has the physical attributes of position, direction and |
| 14 | wavelength. |
| 15 | |
| 16 | Attributes |
| 17 | ---------- |
| 18 | position : tuple of float |
| 19 | The (x, y, z) position. |
| 20 | direction : tuple of floats |
| 21 | Direction unit vector (n_i, n_j, n_k). |
| 22 | wavelength : float |
| 23 | The wavelength in nanometers. |
| 24 | is_alive : bool |
| 25 | Indicates if the ray is not dead |
| 26 | travelled : float |
| 27 | Total propagation distance. This gets updated when when calling `propagate`. |
| 28 | source: float |
| 29 | Identifier of the light source of luminophore that emitted the ray. |
| 30 | """ |
| 31 | |
| 32 | position: tuple |
| 33 | direction: tuple |
| 34 | wavelength: Optional[float] |
| 35 | is_alive: bool = True |
| 36 | travelled: float = 0.0 |
| 37 | source: Optional[str] = None |
| 38 | |
| 39 | def __repr__(self): |
| 40 | position = "(" + ", ".join(["{:.2f}".format(x) for x in self.position]) + ")" |
| 41 | direction = "(" + ", ".join(["{:.2f}".format(x) for x in self.direction]) + ")" |
| 42 | wavelength = "{:.2f}".format(self.wavelength) |
| 43 | is_alive = "True" if self.is_alive else "False" |
| 44 | args = (position, direction, wavelength, is_alive) |
| 45 | return "Ray(pos={}, dir={}, nm={}, alive={})".format(*args) |
| 46 | |
| 47 | def propagate(self, distance: float) -> Ray: |
| 48 | """ Returns a new ray which has been moved the specified distance along |
| 49 | its direction. |
| 50 | |
| 51 | Parameters |
| 52 | ---------- |
| 53 | distance : float |
| 54 | The distance to move the ray. Can be negative in which case the new |
| 55 | ray will be moved backwards. |
| 56 | """ |
| 57 | if not self.is_alive: |
| 58 | raise ValueError("Ray is not alive.") |
| 59 | new_position = np.array(self.position) + np.array(self.direction) * distance |
| 60 | new_position = tuple(new_position.tolist()) |
| 61 | new_ray = replace( |
| 62 | self, position=new_position, travelled=self.travelled + distance |
| 63 | ) |
| 64 | return new_ray |
| 65 | |
| 66 | def representation(self, from_node: Node, to_node: Node) -> Ray: |
| 67 | """ Representation of the ray in another coordinate system. |
| 68 | |
| 69 | Parameters |
no outgoing calls