Calculate the surface normal of a SDF at the point p numerically.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(vector), | intent(in) | :: | p |
Position to evaluate at |
||
class(sdf_base) | :: | obj |
SDF to calcuate surface normal of. |
type(vector) function calcNormal(p, obj) !! Calculate the surface normal of a SDF at the point p numerically. !> Position to evaluate at type(vector), intent(IN) :: p !> SDF to calcuate surface normal of. class(sdf_base) :: obj real(kind=wp) :: h type(vector) :: xyy, yyx, yxy, xxx h = 1e-6_wp xyy = vector(1._wp, -1._wp, -1._wp) yyx = vector(-1._wp, -1._wp, 1._wp) yxy = vector(-1._wp, 1._wp, -1._wp) xxx = vector(1._wp, 1._wp, 1._wp) calcNormal = xyy*obj%evaluate(p + xyy*h) + & yyx*obj%evaluate(p + yyx*h) + & yxy*obj%evaluate(p + yxy*h) + & xxx*obj%evaluate(p + xxx*h) calcNormal = calcNormal%magnitude() end function calcNormal