intersectCircle Function

public function intersectCircle(n, p0, radius, l0, l, t)

ref

Arguments

Type IntentOptional Attributes Name
type(vector), intent(in) :: n

Normal to the circle

type(vector), intent(in) :: p0

a centre of the circle

real(kind=wp), intent(in) :: radius

Radius of the circle

type(vector), intent(in) :: l0

origin of the ray

type(vector), intent(in) :: l

direction vector of the ray

real(kind=wp), intent(inout) :: t

Distance from l0 to the intersection point

Return Value logical


Source Code

    logical function intersectCircle(n, p0, radius, l0, l, t)
    !![ref](https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection)
        !> Normal to the circle
        type(vector),  intent(in) :: n
        !> a centre of the circle
        type(vector),  intent(in) :: p0
        !> direction vector of the ray
        type(vector),  intent(in) :: l
        !> origin of the ray
        type(vector),  intent(in) :: l0
        !> Radius of the circle
        real(kind=wp), intent(in) :: radius
        !> Distance from l0 to the intersection point
        real(kind=wp), intent(inout) :: t

        real(kind=wp) :: d2
        type(vector) :: v, p

        intersectCircle = .false.
        t = 0._wp
        if(intersectPlane(n, p0, l0, l, t))then
            p = l0 + l * t
            v = p - p0
            d2 = v .dot. v
            if(sqrt(d2) <= radius)intersectCircle=.true.
        end if
    end function intersectCircle