summaryrefslogtreecommitdiff
path: root/src/GC/GC_MakeArcOfCircle.cxx
blob: a8eabcf5f94a335c25d3bf6d8bc102ed20ae2b5b (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
// File:	GC_MakeArcOfCircle.cxx
// Created:	Fri Oct  2 16:30:57 1992
// Author:	Remi GILET
//		<reg@topsn3>

#include <GC_MakeArcOfCircle.ixx>
#include <gce_MakeCirc.hxx>
#include <gce_MakeLin.hxx>
#include <Geom_Circle.hxx>
#include <Extrema_ExtElC.hxx>
#include <Extrema_POnCurv.hxx>
#include <StdFail_NotDone.hxx>
#include <ElCLib.hxx>

//=======================================================================
//function : GC_MakeArcOfCircle
//purpose  : 
//=======================================================================
GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt&  P1 ,
				       const gp_Pnt&  P2 ,
				       const gp_Pnt&  P3  ) 
{
  Standard_Boolean sense;
  //
  gce_MakeCirc Cir(P1, P2, P3);
  TheError = Cir.Status();
  if (TheError == gce_Done) {
    Standard_Real Alpha1, Alpha3;//,Alpha2
    gp_Circ C(Cir.Value());
    //modified by NIZNHY-PKV Thu Mar  3 10:53:02 2005f
    //Alpha1 is always =0.
    //Alpha1 = ElCLib::Parameter(C,P1);
    //Alpha2 = ElCLib::Parameter(C,P2);
    //Alpha3 = ElCLib::Parameter(C,P3);
    //
    //if (Alpha2 >= Alpha1 && Alpha2 <= Alpha3) sense = Standard_True;
    //else if (Alpha1 <= Alpha3 && Alpha2 >= Alpha3 ) sense = Standard_True;
    //else sense = Standard_False;
    // 
    Alpha1=0.;
    Alpha3 = ElCLib::Parameter(C, P3);
    sense=Standard_True;
    //modified by NIZNHY-PKV Thu Mar  3 10:53:04 2005t
    
    Handle(Geom_Circle) Circ = new Geom_Circle(C);
    TheArc= new Geom_TrimmedCurve(Circ, Alpha1, Alpha3, sense);
  }
}

//=======================================================================
//function : GC_MakeArcOfCircle
//purpose  : 
//=======================================================================
GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 ,
				       const gp_Vec& V  ,
				       const gp_Pnt& P2 )
{
  gp_Circ cir;
  gce_MakeLin Corde(P1,P2);
  TheError = Corde.Status();
  if (TheError == gce_Done) {
    gp_Lin corde(Corde.Value());
    gp_Dir dir(corde.Direction());
    gp_Dir dbid(V);
    gp_Dir Daxe(dbid^dir);
    gp_Dir Dir1(Daxe^dir);
    gp_Lin bis(gp_Pnt((P1.X()+P2.X())/2.,(P1.Y()+P2.Y())/2.,
		      (P1.Z()+P2.Z())/2.),Dir1);
    gp_Dir d(dbid^Daxe);
    gp_Lin norm(P1,d);
    Standard_Real Tol = 0.000000001;
    Extrema_ExtElC distmin(bis,norm,Tol);
    if (!distmin.IsDone()) { TheError = gce_IntersectionError; }
    else {
      Standard_Integer nbext = distmin.NbExt();
      if (nbext == 0) { TheError = gce_IntersectionError; }
      else {
	Standard_Real TheDist = RealLast();
	gp_Pnt pInt,pon1,pon2;
	Standard_Integer i = 1;
	Extrema_POnCurv Pon1,Pon2;
	while (i<=nbext) {
	  if (distmin.SquareDistance(i)<TheDist) {
	    TheDist = distmin.SquareDistance(i);
	    distmin.Points(i,Pon1,Pon2);
	    pon1 = Pon1.Value();
	    pon2 = Pon2.Value();
	    pInt = gp_Pnt((pon1.XYZ()+pon2.XYZ())/2.);
	  }
	  i++;
	}
	Standard_Real Rad = (pInt.Distance(P1)+pInt.Distance(P2))/2.;
	cir = gp_Circ(gp_Ax2(pInt,Daxe,d),Rad);
	Standard_Real Alpha1 = ElCLib::Parameter(cir,P1);
	Standard_Real Alpha3 = ElCLib::Parameter(cir,P2);
	Handle(Geom_Circle) Circ = new Geom_Circle(cir);
	TheArc= new Geom_TrimmedCurve(Circ,Alpha1,Alpha3, Standard_True);
      }
    }
  }
}
//=======================================================================
//function : GC_MakeArcOfCircle
//purpose  : 
//=======================================================================
GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
				       const gp_Pnt&  P1     ,
				       const gp_Pnt&  P2     ,
				       const Standard_Boolean  Sense  ) 
{
  Standard_Real Alpha1 = ElCLib::Parameter(Circ,P1);
  Standard_Real Alpha2 = ElCLib::Parameter(Circ,P2);
  Handle(Geom_Circle) C = new Geom_Circle(Circ);
  TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
  TheError = gce_Done;
}
//=======================================================================
//function : GC_MakeArcOfCircle
//purpose  : 
//=======================================================================
GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
				       const gp_Pnt&  P      ,
				       const Standard_Real     Alpha  ,
				       const Standard_Boolean  Sense  ) 
{
  Standard_Real Alphafirst = ElCLib::Parameter(Circ,P);
  Handle(Geom_Circle) C = new Geom_Circle(Circ);
  TheArc= new Geom_TrimmedCurve(C,Alphafirst,Alpha,Sense);
  TheError = gce_Done;
}
//=======================================================================
//function : GC_MakeArcOfCircle
//purpose  : 
//=======================================================================
GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
					 const Standard_Real     Alpha1 ,
					 const Standard_Real     Alpha2 ,
					 const Standard_Boolean  Sense  ) 
{
  Handle(Geom_Circle) C = new Geom_Circle(Circ);
  TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
  TheError = gce_Done;
}
//=======================================================================
//function : Value
//purpose  : 
//=======================================================================
const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Value() const
{ 
  StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
  return TheArc;
}
//=======================================================================
//function : Operator
//purpose  : 
//=======================================================================
const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Operator() const 
{
  return Value();
}
//=======================================================================
//function : operator
//purpose  : 
//=======================================================================
GC_MakeArcOfCircle::operator Handle(Geom_TrimmedCurve) () const
{
  return Value();
}