pyoptools.raytrace.shape.triangular module¶
Module that defines the Triangular class
- class pyoptools.raytrace.shape.triangular.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¶