dense=False)

# build the system
system = eng.OpticalSystem2D()
system.optical_segments = [boundary]
system.sources = [source]
system.materials = [{"n": materials.vacuum}, {"n": materials.acrylic}]

trace_engine = eng.OpticalEngine(2, [op.StandardReaction()],
                                 compile_dead_rays=True,
                                 dead_ray_length=10,
                                 simple_ray_inheritance={"wavelength"})
trace_engine.optical_system = system
system.update()
trace_engine.validate_system()
trace_engine.ray_trace(max_iterations=50)

# set up drawers
segment_drawer = drawing.SegmentDrawer(ax,
                                       color="cyan",
                                       draw_norm_arrows=True,
                                       norm_arrow_visibility=True)
segment_drawer.segments = system.optical_segments
segment_drawer.draw()

ray_drawer = drawing.RayDrawer2D(ax)
ray_drawer.rays = trace_engine.all_rays
ray_drawer.draw()

plt.show()
        (1.0, -1.0), (1.0, 1.0), point_count
    )
    boundary = boundaries.ParametricMultiSegmentBoundary(
        zero_points,
        one_points,
        constraints=[
            boundaries.ThicknessConstraint(0.0, "min"),
            boundaries.ThicknessConstraint(0.5, "min"),
            boundaries.PointConstraint(0.0, 7, parent="zero")
            #boundaries.ThicknessConstraint(0.0, "min", parent="zero")
            #boundaries.PointConstraint(0.0, 0),
            #boundaries.PointConstraint(0.5, 7)
        ],
        flip_norm=[False, True, True]
    )
    system = engine.OpticalSystem2D()
    system.optical_segments = boundary.surfaces
    system.update()

    # set up drawer
    drawer = drawing.SegmentDrawer(ax, color="cyan", draw_norm_arrows=True)
    drawer.segments = system.optical_segments
    drawer.draw()

    # hand over to user
    fig.canvas.mpl_connect(
        "key_press_event",
        lambda event: on_key(event, drawer, boundary, system),
    )
    plt.show()
示例#3
0
        drawer.draw()

    drawing.redraw_current_figure()


if __name__ == "__main__":
    drawing.disable_figure_key_commands()

    # set up the figure and axes
    fig, ax = plt.subplots(1, 1, figsize=(15, 9))

    # configure axes
    ax.set_aspect("equal")
    ax.set_xbound(-2, 2)
    ax.set_ybound(-2, 2)

    # set up drawer
    drawer = drawing.SegmentDrawer(
        ax,
        segments=get_random_segments(),
        color=next(COLORS),
        style=next(STYLES),
        draw_norm_arrows=True,
    )
    drawer.draw()

    # hand over to user
    fig.canvas.mpl_connect("key_press_event",
                           lambda event: on_key(event, drawer))
    plt.show()
示例#4
0
    system.materials = [
        {"n": materials.vacuum},
        {"n": materials.acrylic}
    ]
    
    trace_engine = eng.OpticalEngine(
        2,
        [op.StandardReaction()],
        simple_ray_inheritance={"angle_ranks", "wavelength"}
    )
    trace_engine.optical_system = system
    system.update()
    trace_engine.validate_system()

    # set up drawers    
    target_drawer = drawing.SegmentDrawer(ax, color="black", draw_norm_arrows=False)
    target_drawer.segments = system.target_segments
    target_drawer.draw()
    
    ray_drawer = drawing.RayDrawer2D(ax)

    arc_drawer = drawing.ArcDrawer(ax, color="cyan", draw_norm_arrows=True)
    
    # configure axes
    ax.set_aspect("equal")
    ax.set_xbound(-2, 12)
    ax.set_ybound(-7, 7)

    # display the plot
    redraw(trace_engine, ray_drawer, arc_drawer)
    plt.show(block=False)
示例#5
0
# set up the drawing stuff
drawing.disable_figure_key_commands()
fig, ax = plt.subplots(1, 1, figsize=(12, 8))
if VISUALIZE:
    plt.show(block=False)

ax.set_aspect("equal")
#ax.set_xbound(-1.1*np.max(backward_section), 1.1*np.max(forward_section))
#ax.set_ybound(-1.1*height, .1*height)
ax.set_xbound(-1, 1)
ax.set_ybound(-1, .3)

ray_drawer = drawing.RayDrawer(ax)
segment_drawer = drawing.SegmentDrawer(ax,
                                       color=(0, 1, 1),
                                       draw_norm_arrows=False,
                                       norm_arrow_length=.1)

# build the ray targets
target_definition_dict = {
    slice_angle:
    np.array([(forward - backward) / 2.0 + offset, forward + offset, 1.0],
             dtype=np.float64)
    for slice_angle, forward, backward, offset in zip(
        slice_angles, forward_section, backward_section, slice_center_offset)
}
ray_target_placeholder = tf.placeholder(
    tf.float64,
    shape=(ray_count, ),
    name="ray_target_placeholder",
)
def plot_angle_test(session, ax, x, angle):
    # generate and draw the starting rays
    ray_count = 11
    angular_distribution = sources.StaticUniformAngularDistribution(
        -0.9 * PI / 2.0, 0.9 * PI / 2.0, ray_count
    )
    wavelengths = np.linspace(drawing.VISIBLE_MIN, drawing.VISIBLE_MAX, ray_count)

    external_rays = sources.PointSource(
        (x, 0.25),
        angle,
        angular_distribution,
        wavelengths,
        start_on_center=False,
        dense=False,
        ray_length=0.1,
    )
    external_drawer = drawing.RayDrawer(ax, rays=session.run(external_rays.rays))
    external_drawer.draw()

    internal_rays = sources.PointSource(
        (x, -0.25),
        angle + PI,
        angular_distribution,
        wavelengths,
        start_on_center=False,
        dense=False,
        ray_length=0.1,
    )
    internal_drawer = drawing.RayDrawer(ax, rays=session.run(internal_rays.rays))
    internal_drawer.draw()

    # generate and draw the boundary
    segment_length = 0.2
    segment_angle = angle + PI / 2.0
    segments = np.array(
        [
            [
                x + segment_length * math.cos(segment_angle),
                0.25 + segment_length * math.sin(segment_angle),
                x - segment_length * math.cos(segment_angle),
                0.25 - segment_length * math.sin(segment_angle),
            ],
            [
                x + segment_length * math.cos(segment_angle),
                -0.25 + segment_length * math.sin(segment_angle),
                x - segment_length * math.cos(segment_angle),
                -0.25 - segment_length * math.sin(segment_angle),
            ],
        ]
    )
    segment_drawer = drawing.SegmentDrawer(
        ax, segments=segments, color=(0, 1, 1), draw_norm_arrows=True
    )
    segment_drawer.draw()

    # react the rays and draw the reactions
    n_in = tf.cast(1.5, tf.float64)
    n_out = tf.cast(1.0, tf.float64)
    angle = tf.cast(angle, tf.float64)
    external_reacted = geometry.ray_reaction(
        external_rays.rays, angle, n_in, n_out, new_ray_length=0.2
    )
    ex_reacted_drawer = drawing.RayDrawer(
        ax, rays=session.run(external_reacted), style="--"
    )
    ex_reacted_drawer.draw()

    internal_reacted = geometry.ray_reaction(
        internal_rays.rays, angle, n_in, n_out, new_ray_length=0.2
    )
    in_reacted_drawer = drawing.RayDrawer(
        ax, rays=session.run(internal_reacted), style="--"
    )
    in_reacted_drawer.draw()