How to use the raytracing.graphicComponents.Component function in raytracing

To help you get started, we’ve selected a few raytracing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DCC-Lab / RayTracing / raytracing / graphicComponents.py View on Github external
""" A list of linear bezier curves that go through all points.

        Arguments
        ---------
        controlPoints: List
            The coordinates in (x, y) tuples that define all required linear bezier curves.
        """

        bezierCurves = []
        for i, cpA in enumerate(controlPoints[:-1]):
            cpB = controlPoints[i+1]
            bezierCurves.append(BezierCurve([cpA, cpB]))
        return bezierCurves


class Arrow(Component):
    """ A standard arrow graphic component.

    Arguments
    ---------
    dy: float
        Total height of the arrow from 'y'.

    Other parameters
    ----------------
    y: float
        Starting point in y-axis where the base of the arrow sits. Defaults to 0.
    """
    def __init__(self, dy: float, y=0.0, color='k', width=0.002, headLengthRatio=0.1):
        super(Arrow, self).__init__(color=color, hasFixedWidth=False)
        self.dy = dy
        self.y = y
github DCC-Lab / RayTracing / raytracing / graphicComponents.py View on Github external
v1 = self.x

        if self.surface.R == float("+inf"):
            return [BezierCurve([(v1, -h), (v1, h)])]

        R1 = self.surface.R
        phi1 = math.asin(h / abs(R1))
        delta1 = R1 * (1.0 - math.cos(phi1))
        ctl1 = abs((1.0 - math.cos(phi1)) / math.sin(phi1) * R1)
        corner1 = v1 + delta1

        return [BezierCurve([(corner1, -h), (v1, -ctl1), (v1, 0)]),
                BezierCurve([(v1, 0), (v1, ctl1), (corner1, h)])]


class SurfacePair(Component):
    def __init__(self, surfaceA, surfaceB, halfHeight, x=0.0):
        colorValue = 1.0 - np.min([(surfaceA.n - 1)**2 / 2, 0.5])
        color = (colorValue - 0.1, colorValue, 0.95)
        super(SurfacePair, self).__init__(color=color)

        self.surfaceA = surfaceA
        self.surfaceB = surfaceB
        self.halfHeight = halfHeight
        self.x = x
        self.corners = None

        self.pathSurfaceA = self.getPathA()
        self.pathSurfaceB = self.getPathB()

    @property
    def bezierCurves(self) -> List[BezierCurve]:
github DCC-Lab / RayTracing / raytracing / graphicComponents.py View on Github external
def bezierCurves(self):
        """ The thin arrow is defined by a list of straight lines without the notion of contours. """
        dx1 = self.headWidth / 2
        dy1 = self.dy - self.headLength

        topHead = self.linearBezierCurvesFrom([(-dx1, dy1), (0, self.dy), (dx1, dy1)])
        bottomHead = self.linearBezierCurvesFrom([(-dx1, -dy1), (0, -self.dy), (dx1, -dy1)])

        bezierCurves = [BezierCurve([(0, -self.dy), (0, self.dy)])]
        bezierCurves.extend(topHead)
        bezierCurves.extend(bottomHead)

        return bezierCurves


class ApertureBars(Component):
    """Define an aperture graphic component with default RayTracing style used to draw the apertures. """
    def __init__(self, y: float, x=0.0, width=0.0, color='0.7'):
        super().__init__(color=color, fill=False, lineWidth=3)
        if width == 0.0:
            width = 0.01
            self.hasFixedWidth = False

        self.width = width
        self.y = y
        self.x = x

    @property
    def bezierCurves(self) -> List[BezierCurve]:
        """ An aperture component is defined as a straight line at 'y' and '-y'. """
        if self.width <= 0.01:
            coordsTop = [(self.x - 0.005, self.y), (self.x + 0.005, self.y)]
github DCC-Lab / RayTracing / raytracing / graphicComponents.py View on Github external
BezierCurve([(v2, -h), (self.corners[0], -h)])]

        R2 = self.surfaceB.R
        phi2 = math.asin(h / abs(R2))
        delta2 = R2 * (1.0 - math.cos(phi2))
        ctl2 = abs((1.0 - math.cos(phi2)) / math.sin(phi2) * R2)
        corner2 = v2 + delta2
        self.corners.append(corner2)

        return [BezierCurve([(self.corners[0], h), (corner2, h)]),
                BezierCurve([(corner2, h), (v2, ctl2), (v2, 0)]),
                BezierCurve([(v2, 0), (v2, -ctl2), (corner2, -h)]),
                BezierCurve([(corner2, -h), (self.corners[0], -h)])]


class DoubleThinArrow(Component):
    """ A thin arrow centered on y-axis with an arrow head on both ends. """
    def __init__(self, height: float, color='k', headWidth=0.01, headLengthRatio=0.12):
        super(DoubleThinArrow, self).__init__(color=color, lineWidth=1.5, fill=False, hasFixedWidth=False)

        self.dy = height / 2
        self.headWidth = headWidth
        self.headLength = self.dy * headLengthRatio

    @property
    def bezierCurves(self):
        """ The thin arrow is defined by a list of straight lines without the notion of contours. """
        dx1 = self.headWidth / 2
        dy1 = self.dy - self.headLength

        topHead = self.linearBezierCurvesFrom([(-dx1, dy1), (0, self.dy), (dx1, dy1)])
        bottomHead = self.linearBezierCurvesFrom([(-dx1, -dy1), (0, -self.dy), (dx1, -dy1)])
github DCC-Lab / RayTracing / raytracing / graphicComponents.py View on Github external
self.x = x

    @property
    def bezierCurves(self) -> List[BezierCurve]:
        """ An aperture component is defined as a straight line at 'y' and '-y'. """
        if self.width <= 0.01:
            coordsTop = [(self.x - 0.005, self.y), (self.x + 0.005, self.y)]
            coordsBottom = [(self.x - 0.005, -self.y), (self.x + 0.005, -self.y)]
        else:
            coordsTop = [(self.x, self.y), (self.x + self.width, self.y)]
            coordsBottom = [(self.x, -self.y), (self.x + self.width, -self.y)]

        return [BezierCurve(coordsTop), BezierCurve(coordsBottom)]


class Polygon(Component):
    def __init__(self, points: List[tuple], lineWidth=1.0, color='k', fill=False, lineStyle='-'):
        super(Polygon, self).__init__(color=color, fill=fill, lineWidth=lineWidth, lineStyle=lineStyle)
        self.points = points

    @property
    def bezierCurves(self) -> List[BezierCurve]:
        return self.linearBezierCurvesFrom(self.points)


class Label:
    """ Label base class. Promoted to MplLabel by the Figure Manager if using a matplotlib backend.
    A label can have a text and a point, independently, but the point will always sit on the optical axis at y=0.
    """
    def __init__(self, text: str = None, x=0.0, y=0.0, fontsize=10, hasPointMarker=False, color='k',
                 useDataUnits=True, alignment='center'):
        self.text = text
github DCC-Lab / RayTracing / raytracing / graphicComponents.py View on Github external
p0 = (-dx0, self.y)
        p1 = (-dx0, dy1)
        p2 = (-dx1, dy1)
        p3 = (0, dy)
        p4 = (dx1, dy1)
        p5 = (dx0, dy1)
        p6 = (dx0, self.y)

        return self.linearBezierCurvesFrom([p0, p1, p2, p3, p4, p5, p6, p0])

    @property
    def length(self):
        return 0


class Rectangle(Component):
    def __init__(self, xy: tuple, width: float, height: float, color='k', fill=False, lineWidth=1, lineStyle='-'):
        super(Rectangle, self).__init__(color=color, fill=fill, lineWidth=lineWidth, lineStyle=lineStyle)

        self.x, self.y = xy
        self.width = width
        self.height = height

    @property
    def bezierCurves(self):
        p0 = (self.x, self.y)
        p1 = (self.x, self.y + self.height)
        p2 = (self.x + self.width, self.y + self.height)
        p3 = (self.x + self.width, self.y)

        return self.linearBezierCurvesFrom([p0, p1, p2, p3, p0])
github DCC-Lab / RayTracing / raytracing / graphicComponents.py View on Github external
self.x, self.y = xy
        self.width = width
        self.height = height

    @property
    def bezierCurves(self):
        p0 = (self.x, self.y)
        p1 = (self.x, self.y + self.height)
        p2 = (self.x + self.width, self.y + self.height)
        p3 = (self.x + self.width, self.y)

        return self.linearBezierCurvesFrom([p0, p1, p2, p3, p0])


class Surface(Component):
    def __init__(self, surface, halfHeight, x=0.0, color='k'):
        super(Surface, self).__init__(color=color, fill=False)
        self.surface = surface
        self.halfHeight = halfHeight
        self.x = x

    @property
    def bezierCurves(self) -> List[BezierCurve]:
        h = self.halfHeight
        v1 = self.x

        if self.surface.R == float("+inf"):
            return [BezierCurve([(v1, -h), (v1, h)])]

        R1 = self.surface.R
        phi1 = math.asin(h / abs(R1))

raytracing

Simple optical ray tracing library to validate the design of an optical system (lenses positions and sizes, focal lengths, aperture and field stops). Support for Monte Carlo raytracing to estimate transmission efficiency and powers, limited but functional Zemax file loader for lenses, several material dispersion curves included for chromatic aberrations all coming from http://refractiveindex.info

MIT
Latest version published 3 months ago

Package Health Score

64 / 100
Full package analysis