RayTracable

public protocol RayTracable : Intersectable

A shape that can interact with a Ray

  • Return the intersection of a ray

    Declaration

    Swift

    func rayIntersection(_ ray: Ray) -> Vector?

    Parameters

    ray

    The Ray to intersect

  • modifyRay(_:) Default implementation

    Modify the path of a ray.

    The default implementation of this method terminates the Ray.

    Default Implementation

    Modify the path of a ray.

    The default implementation of this method terminates the Ray.

    Declaration

    Swift

    func modifyRay(_ ray: Ray)

    Parameters

    ray

    The ray to modify

Available where Self: Polygon

  • interface(of:) Extension method

    The interface of the intersection of a ray

    Declaration

    Swift

    func interface(of intersection: Vector) -> Line

    Parameters

    intersection

    The point of intersection

    Return Value

    A line representing the normal

  • Calculate the angle of deflection using Snell’s Law of Reflection

    Declaration

    Swift

    func deflectionAngle(for dir: Vector, at interface: Line, refraction: Double = 1.46, extIndex: Double = 1.0) -> Vector

    Parameters

    dir

    The angle of intersection

    interface

    The interface

    refraction

    The refraction index of the material

    extIndex

    The refraction index of the exterior material

    Return Value

    A Vector rotated by the abgle of reflection

  • deflectRay(_:) Extension method

    Deflect a ray according to Snell’s Law

    Declaration

    Swift

    func deflectRay(_ ray: Ray)

    Parameters

    ray

    The ray to deflect

  • Calculate the critical angle of a material

    Declaration

    Swift

    func criticalAngle(refraction: Double, extIndex: Double) -> Radians

    Parameters

    refraction

    The refraction index of the material

    extIndex

    The refraction index of the exterior material

    Return Value

    The critical angle

  • modifyRay(_:) Default implementation

    Default Implementation

    Modify the path of a ray by deflecting the ray through the object.

    Declaration

    Swift

    func modifyRay(_ ray: Ray)

    Parameters

    ray

    The ray to modify