*********************************************************************sdk ************************************************************************ * Subroutine pnt2pln * * Function: get plane equation from three points * * Arguments: * Points (i) Coordinates of three points * Plane (o) Plane equation * Errcod (o) Error code * errcod = 0 - no error * errcod = 1 - problem is ill conditioned * * * Result: * Return normal vector (PLANE(1-3)) and distance from origin * (PLANE(4)) * * History: * Written february 1996 sdk ************************************************************************ subroutine pnt2pln ( points , plane , errcod ) implicit none * Arguments integer errcod real points( 3,3 ) real plane( 4 ) * Local integer i real r1( 3 ) , r2( 3 ) , d real mind parameter ( mind = 0.000001 ) *=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= * Init error code errcod = 0 * Form difference vectors do i = 1 , 3 r1( i ) = points( i,2 ) - points( i,1 ) r2( i ) = points( i,3 ) - points( i,1 ) end do * Normal vector plane( 1 ) = r1( 2 ) * r2( 3 ) - r1( 3 ) * r2( 2 ) plane( 2 ) = r1( 3 ) * r2( 1 ) - r1( 1 ) * r2( 3 ) plane( 3 ) = r1( 1 ) * r2( 2 ) - r1( 2 ) * r2( 1 ) d = sqrt ( plane( 1 )**2 + plane( 2 )**2 + plane( 3 )**2 ) * Check that vectors aren't co-linear if ( d .lt. mind ) then * Ooops, problem is ill conditioned errcod = 1 return endif plane( 1 ) = plane( 1 ) / d plane( 2 ) = plane( 2 ) / d plane( 3 ) = plane( 3 ) / d * Distance from origin plane( 4 ) = plane( 1 )*points( 1,1 ) + & plane( 2 )*points( 2,1 ) + & plane( 3 )*points( 3,1 ) return end