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: s1617.c,v 1.2 2001-03-19 15:58:52 afr Exp $
45  *
46  */
47 
48 
49 #define S1617
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
s1617(double epoint[],int inbpnt,int idim,int eptyp[],double aepsge,double econic[],double estart[],double etang[],double estop[],double * ashape,int * jstat)54 void s1617(double epoint[], int inbpnt, int idim, int eptyp[],
55 	   double aepsge, double econic[],
56 	   double estart[], double etang[], double estop[],
57 	   double *ashape, int *jstat)
58 #else
59 void s1617(epoint, inbpnt, idim, eptyp, aepsge, econic,
60 	   estart, etang, estop, ashape, jstat)
61      double epoint[];
62      int    inbpnt;
63      int    idim;
64      int    eptyp[];
65      double aepsge;
66      double econic[];
67      double estart[];
68      double etang[];
69      double estop[];
70      double *ashape;
71      int    *jstat;
72 #endif
73 /*
74 *************************************************************************
75 *
76 * PURPOSE: To produce interpolation conditions to interpolate the
77 *          conic curve described by Epoint, Eptyp and Econic.
78 *
79 * INPUT:
80 *        Epoint - The points/tangents describing the conic.
81 *        Inbpnt - No. of points/tangents in the epoint array.
82 *        Idim   - The dimension of the space in which the points lie.
83 *        Eptyp  - Type indicator for the points/tangents :
84 *                  1 - Ordinary point.
85 *                  2 - Knuckle point. (Is treated as an ordinary point.)
86 *                  3 - Tangent to next point.
87 *                  4 - Tangent to prior point.
88 *        Aepsge - The geometry reolution.
89 *        Econic - The conic coefficients of the points in the Epoint array.
90 *
91 * Output:
92 *        Estart - Start-point of conic segment.
93 *        Etang  - Intersection point of tangents from start- and endpoint.
94 *        Estop   - End-point of conic segment.
95 *        Ashape - Shape factor.
96 *        Jstat  - Status variable.
97 *
98 * Method:
99 * 	The conics are classified into ellipses, parabolas and hyperbolas.
100 * 	The description of the arc by the output type of parameters is produced.
101 *-
102 * Calls: s1619,s6err.
103 *
104 * Written by: A.M. Ytrehus, si Oslo, Oct.91.
105 * After FORTRAN, (P1617), written by: T. Dokken  SI.
106 *****************************************************************
107 */
108 {
109   int kk, kp;
110   double ta11, ta12, ta13, ta22, ta23, ta33;
111   double td13, td23, td33, tda;
112   double tshape;
113   int ktyp;
114   int kstat = 0;
115   int kpos = 0;
116 
117   *jstat = 0;
118 
119 
120   /* Initiate variables. */
121 
122   ta11 = econic[0];
123   ta12 = econic[1];
124   ta13 = econic[3];		/* ? */
125   ta22 = econic[2];		/* ? */
126   ta23 = econic[4];
127   ta33 = econic[5];
128 
129 
130   /* Calculate determinants. */
131 
132   td13 = ta12 * ta23 - ta22 * ta13;
133   td23 = ta11 * ta23 - ta12 * ta13;
134   td33 = ta11 * ta22 - ta12 * ta12;
135   tda = ta13 * td13 - ta23 * td23 + ta33 * td33;
136 
137 
138   /* Discussion of the conic. */
139 
140   if (DEQUAL(tda + (double) 1.0, (double) 1.0))
141     {
142       /* Degenerate conic. Produce straight line. */
143 
144       *jstat = 1;
145       goto out;
146     }
147 
148   /* Decide if ellipse, parabola or hyperbola. */
149 
150   if (td33 > (double) 0.0)
151     {
152       /* Ellipse, decide if imaginary or real. */
153 
154       if (tda * ta11 > (double) 0.0)
155 	{
156 	  /* Imaginary ellipse. Produce straight line. */
157 
158 	  *jstat = 1;
159 	  goto out;
160 	}
161       else
162 	{
163 	  /* Real eelipse. */
164 
165 	  ktyp = 2;
166 	}
167     }
168   else
169     {
170       /* Parabola or hyperbola. */
171 
172       if (td33 < (double) 0.0)
173 	{
174 	  /* Hyperbola. */
175 
176 	  ktyp = 4;
177 	}
178       else
179 	{
180 	  /* Parabola. */
181 
182 	  ktyp = 3;
183 	}
184     }
185 
186 
187   /* Find rational description of conic. */
188 
189   s1619 (epoint, inbpnt, idim, eptyp, econic, ktyp,
190 	 etang, &tshape, &kstat);
191   if (kstat < 0)
192     goto error;
193   if (kstat == 1)
194     {
195       /* Create straight line. */
196 
197       *jstat = 1;
198       goto out;
199     }
200 
201   kk = idim * (inbpnt - 1);
202 
203   for (kp = 0; kp < idim; kp++)
204     {
205       estart[kp] = epoint[kp];
206       estop[kp] = epoint[kk + kp];
207     }
208 
209   *ashape = tshape;
210 
211   goto out;
212 
213 
214   /* Error in lower level routine. */
215 
216 error:
217   *jstat = kstat;
218   s6err ("s1617", *jstat, kpos);
219   goto out;
220 
221 out:
222 
223   return;
224 }
225