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.
| Type | Intent | Optional | 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 |
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