| 1 |
C Copyright(C) 1999-2020 National Technology & Engineering Solutions |
| 2 |
C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
C NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
C |
| 5 |
C See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
C======================================================================= |
| 8 |
SUBROUTINE PTSNRM( PLAPTS, INPT, CUTPT, CUTNRM , IERR) |
| 9 |
C======================================================================= |
| 10 |
|
| 11 |
C --*** PTRNRM *** (MESH) Turns three point plane to point-normal form |
| 12 |
C -- Written by Ray J. Meyers 29 May, 1990 |
| 13 |
C -- |
| 14 |
C -- Given three non-colinear points, returns a description of the plane |
| 15 |
C -- consisting of a point on the plane and a normal vector to the plane. |
| 16 |
C -- |
| 17 |
C --Parameters: |
| 18 |
C -- PLAPTS - IN - the 3 points defining the cutting plane; |
| 19 |
C -- INPT - IN - a point in the mesh, ie, on the opposite side |
| 20 |
C from the cutting plane normal |
| 21 |
C -- CUTPT - OUT - a point on the cutting plane; |
| 22 |
C -- CUTNRM - OUT - the normal to the cutting plane; |
| 23 |
C -- IERR - OUT - non-zero if the input points are colinear (no plane |
| 24 |
C defined) |
| 25 |
|
| 26 |
REAL PLAPTS(3,3) |
| 27 |
REAL INPT(3) |
| 28 |
REAL CUTPT(3) |
| 29 |
REAL CUTNRM(3) |
| 30 |
INTEGER IERR |
| 31 |
REAL VEC1(3), VEC2(3) |
| 32 |
REAL TOL, DOT |
| 33 |
|
| 34 |
C DEFINE TWO VECTORS IN THE PLANE : VEC1 = P1-P2, VEC2 = P3-P2 |
| 35 |
|
| 36 |
VEC1(1) = PLAPTS(1,1) - PLAPTS(1,2) |
| 37 |
VEC1(2) = PLAPTS(2,1) - PLAPTS(2,2) |
| 38 |
VEC1(3) = PLAPTS(3,1) - PLAPTS(3,2) |
| 39 |
VEC2(1) = PLAPTS(1,3) - PLAPTS(1,2) |
| 40 |
VEC2(2) = PLAPTS(2,3) - PLAPTS(2,2) |
| 41 |
VEC2(3) = PLAPTS(3,3) - PLAPTS(3,2) |
| 42 |
|
| 43 |
C DEFINE A TOLERANCE BASED ON THE LENGTH OF VEC1 |
| 44 |
|
| 45 |
TOL = 1E-06 * AMAX1 ( VEC1(1), VEC1(2), VEC1(3) ) |
| 46 |
|
| 47 |
C TAKE THE CROSS PRODUCT OF VEC1 AND VEC2 AS THE NORMAL OF THE PLANE AND |
| 48 |
C NORMALIZE |
| 49 |
|
| 50 |
CUTNRM(1) = VEC1(2)*VEC2(3) - VEC1(3)*VEC2(2) |
| 51 |
CUTNRM(2) = VEC1(3)*VEC2(1) - VEC1(1)*VEC2(3) |
| 52 |
CUTNRM(3) = VEC1(1)*VEC2(2) - VEC1(2)*VEC2(1) |
| 53 |
|
| 54 |
DIST = SQRT( CUTNRM(1)*CUTNRM(1) + CUTNRM(2)*CUTNRM(2) + |
| 55 |
$ CUTNRM(3)*CUTNRM(3) ) |
| 56 |
CUTNRM(1) = CUTNRM(1)/DIST |
| 57 |
CUTNRM(2) = CUTNRM(2)/DIST |
| 58 |
CUTNRM(3) = CUTNRM(3)/DIST |
| 59 |
|
| 60 |
C IF THE NORMAL IS (0,0,0), THE ORIGINAL POINTS WERE COLINEAR |
| 61 |
|
| 62 |
IF( ABS(CUTNRM(1)) .LT. TOL .AND. ABS(CUTNRM(2)) .LT. TOL |
| 63 |
$ .AND. ABS(CUTNRM(3)) .LT. TOL) THEN |
| 64 |
CALL PRTERR ('CMDERR', 'Points do not define a plane') |
| 65 |
IERR = 1 |
| 66 |
ELSE |
| 67 |
IERR = 0 |
| 68 |
|
| 69 |
C USE THE SECOND INPUT POINT AS THE CHOSEN CUTPT |
| 70 |
|
| 71 |
CUTPT(1) = PLAPTS(1,2) |
| 72 |
CUTPT(2) = PLAPTS(2,2) |
| 73 |
CUTPT(3) = PLAPTS(3,2) |
| 74 |
|
| 75 |
C CHECK THE INPT TO SEE IF THE NORMAL IS THE CORRECT SENSE |
| 76 |
|
| 77 |
VEC1(1) = INPT(1) - CUTPT(1) |
| 78 |
VEC1(2) = INPT(2) - CUTPT(2) |
| 79 |
VEC1(3) = INPT(3) - CUTPT(3) |
| 80 |
DOT = VEC1(1)*CUTNRM(1) + VEC1(2)*CUTNRM(2) + |
| 81 |
$ VEC1(3)*CUTNRM(3) |
| 82 |
IF(DOT .GT. 0) THEN |
| 83 |
CUTNRM(1) = -CUTNRM(1) |
| 84 |
CUTNRM(2) = -CUTNRM(2) |
| 85 |
CUTNRM(3) = -CUTNRM(3) |
| 86 |
END IF |
| 87 |
END IF |
| 88 |
|
| 89 |
RETURN |
| 90 |
END |