Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(vector), | intent(in) | :: | center | |||
type(vector), | intent(in) | :: | axis | |||
real(kind=psb_dpk_), | intent(in) | :: | radius | |||
type(vertex), | intent(in) | :: | vertices(:) |
FUNCTION calc_error(center,axis,radius,vertices)
USE class_vector
IMPLICIT NONE
REAL(psb_dpk_) :: calc_error
TYPE(vector),INTENT(IN) :: center
TYPE(vector),INTENT(IN) :: axis
REAL(psb_dpk_),INTENT(IN) :: radius
TYPE(vertex),INTENT(IN) :: vertices(:)
! Local variables
INTEGER :: nverts ! number of vertices
INTEGER :: i
REAL(psb_dpk_) :: err ! cumulative error
TYPE(vector) :: x,xrad,xrel
nverts = SIZE(vertices)
err = 0
! calculate cumulative error
DO i = 1,nverts
x = vertices(i)%position_()
! calculate position relative to the cylinder's center
xrel = x - center
! get radial vector
xrad = xrel - ( xrel .dot. axis) * axis
! because our ideal cylinder is infinitely long, the error is only
! the vector difference in the radial direction
err = err + ( xrad%mag() - radius)**2
ENDDO
calc_error = err/float(nverts)
END FUNCTION calc_error