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: evalcrvarc.c,v 1.1 1994-04-21 12:10:42 boh Exp $ 45 * 46 */ 47 48 49 #define EVAL_CRV_ARC 50 51 #include "sislP.h" 52 53 #if defined(SISLNEEDPROTOTYPES) 54 void eval_crv_arc(SISLCurve * pc1,double center[],double radius,int ider,double epar[],int * ilfs,double eder[],int * jstat)55 eval_crv_arc(SISLCurve *pc1,double center[],double radius,int ider, 56 double epar[],int *ilfs,double eder[],int *jstat) 57 #else 58 void eval_crv_arc(pc1,center,radius,ider,epar,ilfs,eder,jstat) 59 SISLCurve *pc1; 60 double center[]; 61 double radius; 62 int ider; 63 double epar[]; 64 int *ilfs; 65 double eder[]; 66 int *jstat; 67 #endif 68 /* 69 ********************************************************************* 70 * 71 ********************************************************************* 72 * 73 * PURPOSE : Evaluate the surface expressed by ((pc2x - pc1x,pc2y - 74 * pc1y)*(-(dpc1/ds)y,(dpc1/ds)x), (pc2x - pc1x,pc2y - pc1y) 75 * *(-(dpc2/dt)y,(dpc2/dt)x)), at the parameter values given 76 * in epar, where pc2 is a circle. Compute ider derivatives. 77 * 78 * 79 * 80 * INPUT : pc1 - Pointer to the first curve. 81 * center - Center of the circle. 82 * radius - Radius of the circle. 83 * ider - Number of derivatives to calculate. 84 * < 0 : No derivative calculated. 85 * = 0 : Position calculated. 86 * = 1 : Position and first derivative calculated. 87 * etc. 88 * epar - Parameter-value at which to calculate. Dimension 89 * of epar is 2. 90 * 91 * 92 * 93 * INPUT/OUTPUT : ilfs - Pointer to the interval in the knotvector 94 * in first parameter direction where epar[0] 95 * is found. The relation 96 * 97 * et1[ilfs] <= epar[0] < et1[ilfs+1] 98 * 99 * where et1 is the knotvektor should hold. 100 * ilfs is set equal to zero at the first call 101 * to the routine. 102 * 103 * 104 * 105 * 106 * OUTPUT : eder - Array where the derivative of the curve in 107 * apar is placed. The sequence is position, 108 * first derivative in first parameter direction, 109 * first derivative in second parameter direction, 110 * (2,0) derivative, (1,1) derivative, (0,2) 111 * derivative, etc. Dimension of eder is 112 * idim*(1+2+...+(ider+1)). 113 * jstat - status messages 114 * = 0 : ok 115 * < 0 : error 116 * 117 * 118 * METHOD : 119 * 120 * REFERENCES : 121 * 122 *- 123 * CALLS : 124 * 125 * WRITTEN BY : Johannes Kaasa, SI, March 1992. 126 * 127 ********************************************************************* 128 */ 129 { 130 int kstat=0; /* Local status variable. */ 131 int kpos=0; /* The position of error. */ 132 int kder = ider + 1; /* Number of necessary curve derivatives. */ 133 double crv1[8]; /* The derivatives of the first curve. */ 134 double crv2[8]; /* The derivatives of the second curve. */ 135 double diffvec[2]; /* Difference vector between the two curves. */ 136 double ang_cos; /* Cosine of the angle in the circle. */ 137 double ang_sin; /* Sine of the angle in the circle. */ 138 139 /* Check the input. */ 140 141 if (pc1->idim != 2) goto err102; 142 if (ider > 2) goto err103; 143 144 /* Evaluate the curve. */ 145 146 s1221(pc1, kder, epar[0], ilfs, crv1, &kstat); 147 if (kstat < 0) goto error; 148 149 /* Evaluate the circle. */ 150 151 ang_cos = cos(epar[1]); 152 ang_sin = sin(epar[1]); 153 154 crv2[0] = center[0] + radius*ang_cos; 155 crv2[1] = center[1] + radius*ang_sin; 156 crv2[2] = - radius*ang_sin; 157 crv2[3] = radius*ang_cos; 158 crv2[4] = - radius*ang_cos; 159 crv2[5] = - radius*ang_sin; 160 crv2[6] = radius*ang_sin; 161 crv2[7] = - radius*ang_cos; 162 163 diffvec[0] = crv2[0] - crv1[0]; 164 diffvec[1] = crv2[1] - crv1[1]; 165 166 /* Calculate the position on the surface. */ 167 168 eder[0] = diffvec[1]*crv1[2] - diffvec[0]*crv1[3]; 169 eder[1] = diffvec[1]*crv2[2] - diffvec[0]*crv2[3]; 170 171 /* Calculate the first derivatives. */ 172 173 if (ider > 0) 174 { 175 eder[2] = diffvec[1]*crv1[4] - diffvec[0]*crv1[5]; 176 eder[3] = crv1[2]*crv2[3] - crv1[3]*crv2[2]; 177 eder[4] = crv1[2]*crv2[3] - crv1[3]*crv2[2]; 178 eder[5] = diffvec[1]*crv2[4] - diffvec[0]*crv2[5]; 179 } 180 181 /* Calculate the second derivatives. */ 182 183 if (ider > 1) 184 { 185 eder[6] = crv1[2]*crv1[5] - crv1[3]*crv1[4] 186 + diffvec[1]*crv1[6] - diffvec[0]*crv1[7]; 187 eder[7] = crv1[4]*crv2[3] - crv1[5]*crv2[2]; 188 eder[8] = crv1[4]*crv2[3] - crv1[5]*crv2[2]; 189 eder[9] = crv1[2]*crv2[5] - crv1[3]*crv2[4]; 190 eder[10] = crv1[2]*crv2[5] - crv1[3]*crv2[4]; 191 eder[11] = crv2[3]*crv2[4] - crv2[2]*crv2[5] 192 + diffvec[1]*crv2[6] - diffvec[0]*crv2[7]; 193 } 194 195 196 /* Successful computations. */ 197 198 *jstat = 0; 199 goto out; 200 201 /* Error in lower level routine. */ 202 203 error : *jstat = kstat; 204 s6err("eval_crv_arc",*jstat,kpos); 205 goto out; 206 207 /* Dimension unequal to 2. */ 208 209 err102: *jstat = -102; 210 s6err("eval_crv_arc",*jstat,kpos); 211 goto out; 212 213 /* More than 2 derivatives. */ 214 215 err103: *jstat = -103; 216 s6err("eval_crv_arc",*jstat,kpos); 217 218 out: 219 220 return; 221 } 222 223