summaryrefslogtreecommitdiff
path: root/src/IGESGeom/IGESGeom_ConicArc.cxx
blob: 45bcea61416405cc301963042d3f06d4cb039285 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
//--------------------------------------------------------------------
//
//  File Name : IGESGeom_ConicArc.cxx
//  Date      :
//  Author    : CKY / Contract Toubro-Larsen
//  Copyright : MATRA-DATAVISION 1993
//
//--------------------------------------------------------------------
//#59 rln 29.12.98 PRO17015

#include <IGESGeom_ConicArc.ixx>
#include <gp_Dir2d.hxx>
#include <gp_GTrsf.hxx>


    IGESGeom_ConicArc::IGESGeom_ConicArc ()    {  }


    void  IGESGeom_ConicArc::Init
  (const Standard_Real A, const Standard_Real B,
   const Standard_Real C, const Standard_Real D,  const Standard_Real E,
   const Standard_Real F, const Standard_Real ZT, const gp_XY& aStart,
   const gp_XY& anEnd)
{
  theA = A;
  theB = B;
  theC = C;
  theD = D;
  theE = E;
  theF = F;
  theZT = ZT;
  theStart = aStart;
  theEnd   = anEnd;

  Standard_Integer fn = FormNumber();
  if (fn == 0) fn = ComputedFormNumber();
  InitTypeAndForm(104,fn);
}

    Standard_Boolean  IGESGeom_ConicArc::OwnCorrect ()
{
  Standard_Integer cfn = ComputedFormNumber();
  if (FormNumber() == cfn) return Standard_False;
  InitTypeAndForm(104,cfn);
  return Standard_True;
}

    void  IGESGeom_ConicArc::Equation
  (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D,
   Standard_Real& E, Standard_Real& F) const
{
  A = theA;
  B = theB;
  C = theC;
  D = theD;
  E = theE;
  F = theF;
}

    Standard_Real  IGESGeom_ConicArc::ZPlane () const
{
  return theZT;
}

    gp_Pnt2d  IGESGeom_ConicArc::StartPoint () const
{
  gp_Pnt2d start(theStart.X(), theStart.Y());
  return start;
}

    gp_Pnt  IGESGeom_ConicArc::TransformedStartPoint () const
{
  gp_XYZ start(theStart.X(), theStart.Y(), theZT);
  if (HasTransf()) Location().Transforms(start);
  gp_Pnt transStart(start);
  return transStart;
}

    gp_Pnt2d  IGESGeom_ConicArc::EndPoint () const
{
  gp_Pnt2d end(theEnd.X(), theEnd.Y());
  return end;
}

    gp_Pnt  IGESGeom_ConicArc::TransformedEndPoint () const
{
  gp_XYZ end(theEnd.X(), theEnd.Y(), theZT);
  if (HasTransf()) Location().Transforms(end);
  gp_Pnt transEnd(end);
  return transEnd;
}

    Standard_Integer  IGESGeom_ConicArc::ComputedFormNumber () const
{
  Standard_Real eps,eps2,eps4;
  eps = 1.E-08;  eps2 = eps*eps; eps4 = eps2*eps2;//#59 rln
  Standard_Real Q1 = theA   * (theC*theF   - theE*theE/4.)
    + theB/2. * (theE*theD/4. - theB*theF/2.)
      + theD/2. * (theB*theE/4. - theC*theD/2.);
  Standard_Real Q2 = theA*theC - theB*theB/4;
  Standard_Real Q3 = theA + theC;

//  Resultats
  //#59 rln 29.12.98 PRO17015 face#67, ellipse
  //each Qi has its own dimension:
  //[Q1] = L^-4, [Q2]=L^-4, [Q3]=L^-2
  if (Q2       >  eps4 && Q1*Q3    < 0   ) return 1;    // Ellipse
  if (Q2       < -eps4 && Abs (Q1) > eps4) return 2;    // Hyperbola
  if (Abs (Q2) <= eps4 && Abs (Q1) > eps4) return 3;    // Parabola
  return 0;
}

    Standard_Boolean  IGESGeom_ConicArc::IsFromParabola () const
{
  Standard_Integer fn = FormNumber();
  if (fn == 0)     fn = ComputedFormNumber();
  return (fn == 3);
}

    Standard_Boolean  IGESGeom_ConicArc::IsFromEllipse () const
{
  Standard_Integer fn = FormNumber();
  if (fn == 0)     fn = ComputedFormNumber();
  return (fn == 1);
}

    Standard_Boolean  IGESGeom_ConicArc::IsFromHyperbola () const
{
  Standard_Integer fn = FormNumber();
  if (fn == 0)     fn = ComputedFormNumber();
  return (fn == 2);
}

    Standard_Boolean  IGESGeom_ConicArc::IsClosed () const
{
  return ((theStart.X() == theEnd.X()) && (theStart.Y() == theEnd.Y()));
}

    gp_Dir IGESGeom_ConicArc::Axis () const
{
  gp_Dir axis(0.0 , 0.0, 1.0);
  return axis;
}

//    Valeurs calculees

    gp_Dir IGESGeom_ConicArc::TransformedAxis () const
{
  gp_XYZ axis(0.0 , 0.0, 1.0);
  if (!HasTransf()) return gp_Dir(axis);
  gp_GTrsf loc = Location();
  loc.SetTranslationPart (gp_XYZ(0.,0.,0.));
  loc.Transforms(axis);
  return gp_Dir(axis);
}


    void  IGESGeom_ConicArc::Definition
  (gp_Pnt& Center, gp_Dir& MainAxis,
   Standard_Real& Rmin, Standard_Real& Rmax) const
{
  Standard_Real Xcen,Ycen, Xax,Yax;
  ComputedDefinition (Xcen,Ycen, Xax,Yax, Rmin,Rmax);
  Center.SetCoord (Xcen,Ycen,theZT);
  MainAxis.SetCoord (Xax,Yax,0.);
}

    void  IGESGeom_ConicArc::TransformedDefinition
  (gp_Pnt& Center, gp_Dir& MainAxis,
   Standard_Real& Rmin, Standard_Real& Rmax) const
{
  if (!HasTransf()) {
    Definition (Center,MainAxis,Rmin,Rmax);
    return;
  }
  Standard_Real Xcen,Ycen, Xax,Yax;
  ComputedDefinition (Xcen,Ycen, Xax,Yax, Rmin,Rmax);
  gp_GTrsf loc = Location();
  gp_XYZ cen  (Xcen,Ycen,theZT);
  gp_XYZ axis (Xax, Yax, 0.);
  loc.Transforms (cen);
  loc.SetTranslationPart (gp_XYZ(0.,0.,0.));
  loc.Transforms (axis);
  Center.SetCoord   (cen.X(), cen.Y(), cen.Z() );
  MainAxis.SetCoord (axis.X(),axis.Y(),axis.Z());
}


    void  IGESGeom_ConicArc::ComputedDefinition
  (Standard_Real& Xcen, Standard_Real& Ycen,
   Standard_Real& Xax,  Standard_Real& Yax,
   Standard_Real& Rmin, Standard_Real& Rmax) const
{
  Standard_Real a,b,c,d,e,f;
  //  conic : a*x2 + 2*b*x*y + c*y2 + 2*d*x + 2*e*y + f = 0.
  Equation (a,b,c,d,e,f);
  b = b/2.;  d = d/2.;  e = e/2.;    // chgt de variable

  Standard_Real eps = 1.E-08;  // ?? comme ComputedForm

  if (IsFromParabola()) {
    Rmin = Rmax = -1.;  // rayons : yena pas
    if ( (Abs(a) <= eps) && (Abs(b) <= eps)) {
      Xcen = (f*c - e*e) /c /d /2.;
      Ycen = e/c;
      Standard_Real focal = -d/c;
      Xax  = (focal >= 0 ? 1. : -1.);
      Yax  = 0.;
      Rmin = Rmax = Abs(focal);
    } 
    else {
      Standard_Real ss = a+c;
      Standard_Real cc =   - (a*d+b*e) / ss;
      Standard_Real dd = d + (c*d - b*e) / ss;
      Standard_Real fc =     (a*e - b*d) / ss;
      Standard_Real ee = e + fc;

      Standard_Real dn = a*ee - dd*b;
      Xcen = ( cc*ee + f*b) / dn;
      Ycen = (-cc*dd - f*a) / dn;

      Standard_Real teta = PI/2.;
      if (Abs(b) > eps) teta = ATan (-a/b);
      if (fc < 0) teta += PI;
      Xax  = Cos(teta);
      Yax  = Sin(teta);

      Rmin = Rmax = Abs(fc)/sqrt(a*a+b*b)/2.;
    }
  } 

  else {
    //   -> Conique a centre, cas general
    //  On utilise les Determinants des matrices :
    //               | a b d |
    //  gdet (3x3) = | b c e |  et pdet (2X2) = | a b |
    //               | d e f |                  | b c |
    
    Standard_Real gdet = a*c*f + 2*b*d*e - c*d*d - a*e*e - b*b*f;
    Standard_Real pdet = a*c - b*b;
    
    Xcen = (b*e - c*d) / pdet;
    Ycen = (b*d - a*e) / pdet;

    Standard_Real term1 = a-c;
    Standard_Real term2 = 2*b;
    Standard_Real cos2t;
    Standard_Real auxil;

    if (Abs(term2)<= eps && Abs(term1)<= eps) {
      cos2t = 1.;
      auxil = 0.;
    }
    else {
      Standard_Real t2d = term2/term1; //skl 28.12.2001
      cos2t = 1./sqrt(1+t2d*t2d);
      auxil = sqrt (term1*term1 + term2*term2);
    }
    
    Standard_Real cost = sqrt ( (1+cos2t)/2. );
    Standard_Real sint = sqrt ( (1-cos2t)/2. );

    Standard_Real aprim = (a+c+auxil)/2.;
    Standard_Real cprim = (a+c-auxil)/2.;
    
    term1 = -gdet/(aprim*pdet);
    term2 = -gdet/(cprim*pdet);
      
    if (IsFromEllipse()) {
      Xax = cost;
      Yax = sint;
      Rmin = sqrt ( term1);
      Rmax = sqrt ( term2);
      if(Rmax<Rmin){    //skl 28.12.2001
        Rmax = sqrt ( term1);
        Rmin = sqrt ( term2);
      }
    }
    else if (term1 <= eps){
      Xax  = -sint;
      Yax  =  cost;
      Rmin = sqrt (-term1);
      Rmax = sqrt (term2);
    } 
    else {
      Xax  =  cost;
      Yax  =  sint;
      Rmin = sqrt (-term2);
      Rmax = sqrt (term1);
    }
  }
}