evaluate_segment Function

private pure elemental function evaluate_segment(this, pos) result(res)

Uses

    • utils

Evaluation function for Segment SDF.

Type Bound

segment

Arguments

Type IntentOptional Attributes Name
class(segment), intent(in) :: this
type(vector), intent(in) :: pos

vector position to evaluate SDF at

Return Value real(kind=wp)


Source Code

    pure elemental function evaluate_segment(this, pos) result(res)
        !! Evaluation function for Segment SDF.

        !p = pos
        !a = pt1
        !b = pt2
        !draws segment along the axis between 2 points a and b

        use utils, only : clamp

        class(segment), intent(in) :: this
        !> vector position to evaluate SDF at
        type(vector),   intent(IN) :: pos

        real(kind=wp) :: res

        type(vector)  :: pa, ba, p
        real(kind=wp) :: h
       
        p = pos .dot. this%transform

        pa = p - this%a
        ba = this%b - this%a
        h = clamp((pa .dot. ba) / (ba .dot. ba), 0.0_wp, 1.0_wp)

        res = length(pa - ba*h) - 0.1_wp

    end function evaluate_segment