1 /* 2 * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT, 3 * Applied Mathematics, Norway. 4 * 5 * Contact information: E-mail: tor.dokken@sintef.no 6 * SINTEF ICT, Department of Applied Mathematics, 7 * P.O. Box 124 Blindern, 8 * 0314 Oslo, Norway. 9 * 10 * This file is part of SISL. 11 * 12 * SISL is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU Affero General Public License as 14 * published by the Free Software Foundation, either version 3 of the 15 * License, or (at your option) any later version. 16 * 17 * SISL is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU Affero General Public License for more details. 21 * 22 * You should have received a copy of the GNU Affero General Public 23 * License along with SISL. If not, see 24 * <http://www.gnu.org/licenses/>. 25 * 26 * In accordance with Section 7(b) of the GNU Affero General Public 27 * License, a covered work must retain the producer line in every data 28 * file that is created or manipulated using SISL. 29 * 30 * Other Usage 31 * You can be released from the requirements of the license by purchasing 32 * a commercial license. Buying such a license is mandatory as soon as you 33 * develop commercial activities involving the SISL library without 34 * disclosing the source code of your own applications. 35 * 36 * This file may be used in accordance with the terms contained in a 37 * written agreement between you and SINTEF ICT. 38 */ 39 40 #include "sisl-copyright.h" 41 42 /* 43 * 44 * $Id: s6dplane.c,v 1.1 1994-04-21 12:10:42 boh Exp $ 45 * 46 */ 47 48 49 #define S6DPLANE 50 51 #include "sislP.h" 52 53 #if defined(SISLNEEDPROTOTYPES) 54 double s6dplane(double eq1[],double eq2[],double eq3[],double epoint[],int idim,int * jstat)55 s6dplane(double eq1[],double eq2[],double eq3[],double epoint[], 56 int idim,int *jstat) 57 #else 58 double s6dplane(eq1,eq2,eq3,epoint,idim,jstat) 59 double eq1[]; 60 double eq2[]; 61 double eq3[]; 62 double epoint[]; 63 int idim; 64 int *jstat; 65 #endif 66 /* 67 ********************************************************************* 68 * 69 ********************************************************************* 70 * 71 * PURPOSE : Compute the distance between a plane given by three 72 * points in the plane and a fourth point. 73 * 74 * 75 * 76 * INPUT : eq1 - Point in the plane 77 * eq2 - Point in the plane 78 * eq3 - Point in the plane 79 * epoint - Point. Dimension is idim. 80 * idim - Dimension of geometry space. 81 * 82 * 83 * 84 * OUTPUT : s6dplane - Distance between plane and point. 85 * jstat - status messages 86 * > 0 : warning 87 * = 0 : ok 88 * < 0 : error 89 * 90 * 91 * METHOD : 92 * 93 * 94 * 95 * REFERENCES : 96 * 97 *- 98 * CALLS : s6scpr - Scalar product between two vectors. 99 * s6diff - Difference vector between two vectors. 100 * s6norm - Normalize vector. 101 * s6crss - Cross product between two vectors. 102 * s6dist - Distance between points. 103 * 104 * WRITTEN BY : Vibeke Skytt, SI, 91-02. 105 * 106 ********************************************************************* 107 */ 108 { 109 int kstat = 0; /* Local status varaible. */ 110 double tdist; /* Distance between point and line. */ 111 double snorm[3]; /* Normal vector to the plane. */ 112 double sdiff1[3]; /* Difference vector between points in the plane. */ 113 double sdiff2[3]; /* Difference vector between points in the plane. */ 114 double sdiff3[3]; /* Difference vector. */ 115 116 /* Test dimension. */ 117 118 if (idim != 3) goto err104; 119 120 /* Compute difference vectors. */ 121 122 s6diff(eq2,eq1,idim,sdiff1); 123 s6diff(eq3,eq1,idim,sdiff2); 124 s6diff(epoint,eq1,idim,sdiff3); 125 126 /* Compute normalized plane normal. */ 127 128 s6crss(sdiff1,sdiff2,snorm); 129 (void)s6norm(snorm,idim,snorm,&kstat); 130 131 /* Compute distance to closest point in plane. */ 132 133 if (kstat) 134 tdist = fabs(s6scpr(sdiff3,snorm,idim)); 135 else 136 tdist = s6dist(eq1,epoint,idim); /* Normal of zero length. */ 137 138 /* Set status. */ 139 140 *jstat = 0; 141 goto out; 142 143 /* Error in input, dimension not equal to 3. */ 144 145 err104 : *jstat = -104; 146 goto out; 147 148 out : 149 return tdist; 150 } 151