ray_plane Function

public function ray_plane(origin, dir, point, normal, distance, hit_point) result(hit)

Where the ray (origin, unit dir) meets the plane through point with normal normal: the distance along the ray and the point. False if the ray is parallel to the plane (within 1e-6 of it, as a cosine) or the plane is behind.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: origin(3)

the ray (dir: a unit vector)

real(kind=wp), intent(in) :: dir(3)

the ray (dir: a unit vector)

real(kind=wp), intent(in) :: point(3)

the plane (normal: any length but 0)

real(kind=wp), intent(in) :: normal(3)

the plane (normal: any length but 0)

real(kind=wp), intent(out) :: distance

along the ray (huge() if missed)

real(kind=wp), intent(out) :: hit_point(3)

the point met

Return Value logical


Called by

proc~~ray_plane~~CalledByGraph proc~ray_plane ray_plane proc~constrained constrained proc~constrained->proc~ray_plane proc~drag DragHandle%drag proc~drag->proc~constrained proc~grab DragHandle%grab proc~grab->proc~constrained proc~drag_handle drag_handle proc~drag_handle->proc~drag proc~grab_handle grab_handle proc~grab_handle->proc~grab proc~dispatch_event dispatch_event proc~dispatch_event->proc~drag_handle proc~dispatch_event->proc~grab_handle proc~dispatch_events dispatch_events proc~dispatch_events->proc~dispatch_event proc~frame WindowProxy%frame proc~frame->proc~dispatch_events proc~resize WindowProxy%resize proc~resize->proc~frame proc~run WindowProxy%run proc~run->proc~frame

Source Code

    logical function ray_plane(origin, dir, point, normal, distance, hit_point) result(hit)
        real(wp), intent(in) :: origin(3), dir(3)           !! the ray (dir: a unit vector)
        real(wp), intent(in) :: point(3), normal(3)         !! the plane (normal: any length but 0)
        real(wp), intent(out) :: distance                   !! along the ray (huge() if missed)
        real(wp), intent(out) :: hit_point(3)               !! the point met
        real(wp) :: n(3), d
        hit = .false.
        distance = huge(1.0_wp)
        hit_point = 0.0_wp
        if (norm2(normal) <= 0.0_wp) return
        n = normal / norm2(normal)
        d = dot_product(dir, n)
        if (abs(d) < 1.0e-6_wp) return
        distance = dot_product(point - origin, n) / d
        if (distance < 0.0_wp) then
            distance = huge(1.0_wp)
            return
        end if
        hit_point = origin + distance * dir
        hit = .true.
    end function ray_plane