# The "angle_refract" Function

## Syntax#

angle_refract(deg, mirror, outer_index, inner_index);
ArgumentTypeDescription
`deg`realThe angle to refract, in degrees
`mirror`realThe mirror angle to refract from, in degrees
`outer_index`realThe refraction index of the input angle
`inner_index`realThe refraction index of the mirror

## Description#

Refractions are sided, meaning the resulting refraction angle depends on which direction the input angle is coming from (relative to the orientation of the mirror "line"). Angles between 0-180 degrees are considered to be inside the refractive surface, whereas angles between 180-360 degrees are considered to be outside. A mirror angle of 0 degrees is considered horizontal.

How much an angle refracts depends on the difference between the substance it is coming from and the substance it is going into. The refractivity of a substance is called the "refraction index". Indices are given for both the area outside and inside the mirror "line", where, for example, an index of 1.0 is a vacuum, 1.0003 is air, 1.333 is water, and 2.42 is diamond. Mathematically, refraction index typically ranges from 1.0-3.0, no less or greater.

In addition to controlling the amount of refractivity, these indices also determine the refraction "critical angle", at which point internal refractions will become reflections instead. Higher index equals lower critical angle, refracting sharp angles only and merely reflecting the rest (which is responsible for that diamond glitter!).

##### tip

See the included interactive demo for a visual example of this function!

## Example#

var angle_in = point_direction(mouse_x, mouse_y, mirror_x, mirror_y);
var angle_out = angle_refract(angle_in, mirror_rot, 1, 3);
var dist = point_distance(mouse_x, mouse_y, mirror_x, mirror_y);
// Draw mirror
draw_line(
mirror_x - rot_dist_x(64, mirror_rot), mirror_y - rot_dist_y(64, mirror_rot),
mirror_x + rot_dist_x(64, mirror_rot), mirror_y + rot_dist_y(64, mirror_rot)
);
// Draw angle in
draw_arrow(mouse_x, mouse_y, mirror_x, mirror_y, 16);
// Draw angle out
draw_arrow(
mirror_x, mirror_y,
mirror_x + rot_dist_x(dist, angle_out), mirror_y + rot_dist_y(dist, angle_out),
16
);