pyoptools.raytrace.shape package¶
Submodules¶
Module contents¶
- class pyoptools.raytrace.shape.Circular¶
Bases:
ShapeClass defining a circular shape.
The Circular class represents a circular aperture or surface shape, defined by a given radius. It inherits from the Shape class and implements methods specific to circular shapes.
- Parameters:
radius (float, optional) – The radius of the circular shape. Defaults to 1.0.
samples (tuple of int, optional) – A tuple (radial_samples, angular_samples) that determines the number of samples used to discretize the circle. radial_samples defines the number of divisions along the radius, and angular_samples defines the number of divisions around the circle. Defaults to (10, 36).
*args (tuple, optional) – Additional positional arguments passed to the Shape superclass.
**kwargs (dict, optional) – Additional keyword arguments passed to the Shape superclass.
- radius¶
The radius of the circular shape.
- Type:
float
- samples¶
A tuple (radial_samples, angular_samples) representing the sampling resolution of the circle.
- Type:
tuple of int
- limits()¶
Return the minimum and maximum limits of the circular aperture.
This method returns the minimum and maximum X and Y coordinates that define the bounding box of the circular aperture. These limits are determined by the radius of the circle.
- Returns:
A tuple (xmin, xmax, ymin, ymax) where: - xmin is the minimum X-coordinate (-self.radius). - xmax is the maximum X-coordinate (self.radius). - ymin is the minimum Y-coordinate (-self.radius). - ymax is the maximum Y-coordinate (self.radius).
- Return type:
tuple of float
Notes
These limits define a square bounding box that fully contains the circular aperture.
- pointlist()¶
Generate a list of points that adequately sample the circular shape.
This method returns two lists, X and Y, representing the X and Y coordinates of points that sample the circular shape. The sampling is based on the number of radial (nr) and angular (na) divisions specified in the samples attribute. The center point (0, 0) is always included in the list.
- Returns:
A tuple (X, Y) where X is a list of X coordinates and Y is a list of Y coordinates for the sampled points on the circular shape.
- Return type:
tuple of lists
Notes
- The samples attribute defines the resolution of the sampling:
nr (number of radial samples) determines the number of points
along the radius of the circle. - na (number of angular samples) determines the number of points around the circle’s circumference.
The point (0, 0) is always included at the start of the lists.
- radius¶
- samples¶
- class pyoptools.raytrace.shape.Polygon¶
Bases:
Shapeclass defining a polygonal shape
- Args:
- coords (tuple): Tuple containing the coordinates of the 3 corners
of a triangle. Each coordinate is a(float, float) tuple.
- samples (int): Number of subdivitions per side used to sample the
triangle.
Todo
This class is a copy of the Triangular class. Need to be implemented correctly.
- limits()¶
Returns the minimum limits for the aperture
- pointlist()¶
Generate a list of points that adequately sample the shape.
This method should return a tuple (X, Y) where X contains the X coordinates of the points and Y contains the Y coordinates. The points must be sampled adequately to be used as vertices for generating the triangles required to plot the surface defined by (X, Y, self.topo(X, Y)).
The method must be implemented in each subclass to ensure that the sampling is appropriate for the specific shape.
- Returns:
A tuple (X, Y) where X is a list of X coordinates and Y is a list of Y coordinates, sampled adequately for surface plotting.
- Return type:
tuple of lists
- Raises:
NotImplementedError – If this method is not implemented in a subclass, an error is raised indicating that the method must be overloaded.
- samples¶
- class pyoptools.raytrace.shape.Rectangular¶
Bases:
ShapeClass defining a rectangular shape.
The Rectangular class represents a rectangular aperture or surface shape, defined by its size. It inherits from the Shape class and implements methods specific to rectangular shapes.
- Parameters:
size (tuple of float, optional) – A tuple (width, height) that defines the size of the rectangle. Defaults to (1.0, 1.0).
samples (tuple of int, optional) – A tuple (nx, ny) that determines the number of samples used to discretize the rectangle along its width and height, respectively. Defaults to (30, 30).
offset (tuple of float, optional) – A tuple (x_offset, y_offset) that specifies the offset of the rectangle from the origin. Defaults to (0.0, 0.0).
- size¶
A tuple (width, height) representing the dimensions of the rectangle.
- Type:
tuple of float
- samples¶
A tuple (nx, ny) representing the number of samples along the width and height of the rectangle.
- Type:
tuple of int
- offset¶
A tuple (x_offset, y_offset) representing the offset of the rectangle from the origin.
- Type:
tuple of float
- limits()¶
Return the minimum and maximum limits of the rectangular aperture.
This method returns the minimum and maximum X and Y coordinates that define the bounding box of the rectangular aperture. These limits are calculated based on the size of the rectangle and its offset from the origin.
- Returns:
A tuple (xmin, xmax, ymin, ymax) where: - xmin is the minimum X-coordinate, calculated as -dx/2 + ox. - xmax is the maximum X-coordinate, calculated as dx/2 + ox. - ymin is the minimum Y-coordinate, calculated as -dy/2 + oy. - ymax is the maximum Y-coordinate, calculated as dy/2 + oy.
- Return type:
tuple of float
Notes
dx and dy represent the width and height of the rectangle,
respectively. - ox and oy represent the X and Y offsets of the rectangle from the origin. - These limits define a rectangular bounding box that fully contains the aperture.
- offset¶
- pointlist()¶
Generate a list of points that adequately sample the rectangular shape.
This method returns two lists, X and Y, representing the X and Y coordinates of points that sample the rectangular shape. The sampling resolution is determined by the number of divisions along the width and height of the rectangle, specified by the samples attribute.
The method explicitly calculates the grid points, taking into account the size of the rectangle and its offset from the origin.
- Returns:
A tuple (X, Y) where X is a list of X coordinates and Y is a list of Y coordinates for the sampled points on the rectangular shape.
- Return type:
tuple of lists
Notes
- The samples attribute defines the resolution of the sampling:
nx (number of samples along the width) determines the number of
points along the X-axis. - ny (number of samples along the height) determines the number of points along the Y-axis.
The points are calculated such that the grid spans from -dx/2 + ox
to dx/2 + ox in the X direction and from -dy/2 + oy to dy/2 + oy in the Y direction, where dx and dy are the width and height of the rectangle, and ox and oy are the offsets.
- samples¶
- size¶
- class pyoptools.raytrace.shape.Shape¶
Bases:
PicklableAbstract superclass for all optical surface shapes.
Shape is an abstract superclass that defines the interface for different surface shapes (e.g., circular, rectangular). This class provides an API that all subclasses must implement to define specific shapes and behaviors.
Subclasses are required to implement methods for checking whether a point is inside the shape, defining the shape’s limits, and generating lists of points that sample the shape adequately.
- topo¶
A function Z(x, y) that describes the topography of the surface. This attribute should be initialized as needed.
- Type:
callable
- hit(point)¶
Determine if a point is within the surface aperture.
This method checks whether a given point (x, y, z) lies inside the surface aperture. It returns True if the point is within the aperture and False otherwise.
The method relies on the hit_cy method, which must be implemented in all subclasses of Shape.
- Parameters:
point (tuple of float) – A tuple representing the coordinates (x, y, z) of the point to check.
- Returns:
True if the point is within the surface aperture, False otherwise.
- Return type:
bool
- limits()¶
Return the minimum and maximum limits for the aperture.
This method should be overridden in each subclass to return the specific limits of the shape.
- Returns:
The minimum and maximum limits (xi, xf, yi, yf) of the aperture.
- Return type:
tuple of float
- pointlist()¶
Generate a list of points that adequately sample the shape.
This method should return a tuple (X, Y) where X contains the X coordinates of the points and Y contains the Y coordinates. The points must be sampled adequately to be used as vertices for generating the triangles required to plot the surface defined by (X, Y, self.topo(X, Y)).
The method must be implemented in each subclass to ensure that the sampling is appropriate for the specific shape.
- Returns:
A tuple (X, Y) where X is a list of X coordinates and Y is a list of Y coordinates, sampled adequately for surface plotting.
- Return type:
tuple of lists
- Raises:
NotImplementedError – If this method is not implemented in a subclass, an error is raised indicating that the method must be overloaded.
- class pyoptools.raytrace.shape.Triangular¶
Bases:
ShapeClass defining a triangular polygonal shape.
This class represents a triangular shape defined by the coordinates of its three corners. It inherits from the Shape class and implements methods specific to triangular shapes.
- Parameters:
coord (tuple of tuple of float, optional) – A tuple containing the coordinates of the three corners of the triangle. Each corner is represented by a (x, y) tuple. Defaults to ((0, 0), (0, 100), (100, 0)).
samples (int, optional) – The number of subdivisions per side used to sample the triangle. This determines the resolution of the grid points within the triangle. Defaults to 10.
- point_a¶
A Vector2d object representing the first corner of the triangle.
- Type:
Vector2d
- point_b¶
A Vector2d object representing the second corner of the triangle.
- Type:
Vector2d
- point_c¶
A Vector2d object representing the third corner of the triangle.
- Type:
Vector2d
- samples¶
The number of subdivisions per side used to sample the triangle.
- Type:
int
- limits()¶
Return the minimum and maximum limits of the triangular aperture.
This method returns the minimum and maximum X and Y coordinates that define the bounding box of the triangular aperture. These limits are calculated based on the coordinates of the three vertices of the triangle.
- Returns:
A tuple (xmin, xmax, ymin, ymax) where: - xmin is the minimum X-coordinate among the three vertices. - xmax is the maximum X-coordinate among the three vertices. - ymin is the minimum Y-coordinate among the three vertices. - ymax is the maximum Y-coordinate among the three vertices.
- Return type:
tuple of float
Notes
The limits are calculated directly from the coordinates of the triangle’s
vertices (point_a, point_b, and point_c). - The returned limits define a rectangular bounding box that fully contains the triangular shape.
- pointlist()¶
Generate a list of points that adequately sample the triangular shape.
This method returns two lists, X and Y, representing the X and Y coordinates of points that sample the triangular shape defined by the vertices point_a, point_b, and point_c. The sampling resolution is determined by the samples attribute, which specifies the number of subdivisions per side of the triangle.
- Returns:
A tuple (X, Y) where X is a list of X coordinates and Y is a list of Y coordinates for the sampled points within the triangular shape.
- Return type:
tuple of lists
Notes
The method generates a triangular grid of points by linearly interpolating
between the vertices point_a, point_b, and point_c. - The samples attribute determines the number of subdivisions along each side of the triangle. - The outer loop iterates over the number of samples, creating points along the edges of the triangle. - The inner loop interpolates between the points on the two sides of the triangle to fill in the interior points. - The method handles the edge case when i == 0 to ensure that the starting vertex is correctly included.
- samples¶