C **********************************************************************
C                 Subroutine GEOM2D by Stephen Kirkup                  *
C **********************************************************************
C ######################################################################
C #                                                                    #
C # Copyright Stephen Kirkup 1998-2007                                 #
C #                                                                    #
C # This file may be used as freeware, but should not be redistributed #
C #  as part of another package without the prior permission of        #
C #  Stephen Kirkup.                                                   #
C # The principal source of this file is the website                   #
C #  http://www.boundary-element-method.com                            #
C # This program is used in the author's the BEMLAP, ABEM  packages.   #
C #                                                                    #
C # The author may be contacted by email on                            #
C #  smk@boundary-element-method.com                                   #
C #                                                                    #
C ######################################################################

C real function SIZE2: Returns the modulus of a 2-vector.
C Requires the external module SSIZE2 (supplied).
      REAL*8 FUNCTION SIZE2(VEC)
      REAL*8 VEC(2),SSIZE2
      SIZE2=SQRT(SSIZE2(VEC))
      END

C real function SSIZE2: Returns the square of the modulus of a 
C 2-vector. Requires the external module DOT2 (supplied).
      REAL*8 FUNCTION SSIZE2(VEC)
      REAL*8 VEC(2),DOT2
      SSIZE2=DOT2(VEC,VEC)
      END

C real function DOT2: Returns the dot product of two 2-vectors.
      REAL*8 FUNCTION DOT2(VECA,VECB)
      REAL*8 VECA(2),VECB(2)
      DOT2=VECA(1)*VECB(1)+VECA(2)*VECB(2)
      END

C Subroutine SUBV2: Gives the result in VEC of the subtraction
C  of 2-vectors VECB from VECA.
      SUBROUTINE SUBV2(VECA,VECB,VEC)
      REAL*8 VECA(2),VECB(2),VEC(2)
      VEC(1)=VECA(1)-VECB(1)
      VEC(2)=VECA(2)-VECB(2)
      END 

C real function DIST2: Returns the distance between two points
C  VECA and VECB.
      REAL*8 FUNCTION DIST2(VECA,VECB)
      REAL*8 VECA(2),VECB(2)
      REAL*8 SIZE2
      REAL*8 VEC(2)
      CALL SUBV2(VECA,VECB,VEC)
      DIST2=SIZE2(VEC)
      END

C real function NORM2: Finds the unit normal to the line between
C  VECA and VECB.
      SUBROUTINE NORM2(VECA,VECB,VECNOR)
      REAL*8 VECA(2),VECB(2),VECNOR(2)
      REAL*8 SIZE2
      REAL*8 VAMB(2),S
      CALL SUBV2(VECA,VECB,VAMB)
      S=SIZE2(VAMB)
      VECNOR(1)=VAMB(2)/S
      VECNOR(2)=-VAMB(1)/S
      END



                                                   
