0023962: Moving OCCT documentation to sources
[occt.git] / dox / user_guides / modeling_algos / modeling_algos.md
1 Modeling Algorithms  {#user_guides__modeling_algos}
2 =========================
3
4 @section occt_modalg_1 Introduction
5
6 @subsection occt_modalg_1_1 The Modeling Algorithms Module
7
8
9 This manual explains how  to use the Modeling Algorithms. It provides basic documentation on modeling  algorithms. For advanced information on Modeling Algorithms, see our offerings  on our web site at <a href="http://www.opencascade.org/support/training/">www.opencascade.org/support/training/</a> 
10
11 The Modeling Algorithms module brings together a  wide range of topological algorithms used in modeling. Along with these tools,  you will find the geometric algorithms, which they call. 
12
13 The algorithms available  are divided into: 
14   * Geometric tools
15   * Topological tools
16   * The Topology API
17   
18 @subsection occt_modalg_1_2 The Topology API
19
20 The Topology  API of Open  CASCADE Technology (**OCCT**) includes the following six packages: 
21
22   * BRepAlgoAPI
23   * BRepBuilderAPI
24   * BRepFilletAPI
25   * BRepFeat
26   * BRepOffsetAPI
27   * BRepPrimAPI
28
29 The classes in these six  packages provide the user with a simple and powerful interface.  
30   * A simple interface: a  function call works ideally,
31   * A powerful interface:  including error handling and access to extra information provided by the  algorithms.
32
33 As an example, the class  BRepBuilderAPI_MakeEdge can be used to create a linear edge from two  points. 
34
35 ~~~~~
36 gp_Pnt P1(10,0,0), P2(20,0,0); 
37 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(P1,P2);
38 ~~~~~
39
40 This is the simplest way to create edge E from two  points P1, P2, but the developer can test for errors when he is not as  confident of the data as in the previous example. 
41
42 ~~~~~
43 #include <gp_Pnt.hxx> 
44 #include <TopoDS_Edge.hxx> 
45 #include <BRepBuilderAPI_MakeEdge.hxx> 
46 void EdgeTest() 
47
48 gp_Pnt P1; 
49 gp_Pnt P2; 
50 BRepBuilderAPI_MakeEdge ME(P1,P2); 
51 if (!ME.IsDone()) 
52
53 // doing ME.Edge() or E = ME here 
54 // would raise StdFail_NotDone 
55 Standard_DomainError::Raise 
56 (“ProcessPoints::Failed to createan edge”); 
57
58 TopoDS_Edge E = ME; 
59
60 ~~~~~
61
62 In this example an  intermediary object ME has been introduced. This can be tested for the  completion of the function before accessing the result. More information on **error  handling** in the topology programming interface can be found in the next  section. 
63
64 BRepBuilderAPI_MakeEdge  provides valuable information. For example, when creating an edge from two  points, two vertices have to be created from the points. Sometimes you may be  interested in getting these vertices quickly without exploring the new edge.  Such information can be provided when using a class. The following example  shows a function creating an edge and two vertices from two points. 
65
66 ~~~~~
67 void MakeEdgeAndVertices(const gp_Pnt&amp; P1, 
68 const gp_Pnt&amp; P2, 
69 TopoDS_Edge&amp; E, 
70 TopoDS_Vertex&amp; V1, 
71 TopoDS_Vertex&amp; V2) 
72
73 BRepBuilderAPI_MakeEdge ME(P1,P2); 
74 if (!ME.IsDone()) { 
75 Standard_DomainError::Raise 
76 (“MakeEdgeAndVerices::Failed  to create an edge”); 
77
78 E = ME; 
79 V1 = ME.Vextex1(); 
80 V2 = ME.Vertex2(); 
81 ~~~~~
82
83 The BRepBuilderAPI_MakeEdge class provides the two methods Vertex1 and  Vertex2, which return the two vertices used to create the edge. 
84
85 How can BRepBuilderAPI_MakeEdge be both a function and a class? It can do this  because it uses the casting capabilities of C++. The BRepBuilderAPI_MakeEdge class has a method called Edge; in the previous  example the line E = ME could have been written. 
86
87 ~~~~~
88 E = ME.Edge(); 
89 ~~~~~
90
91 This instruction tells  the C++ compiler that there is an **implicit casting **of a BRepBuilderAPI_MakeEdge into a TopoDS_Edge  using the Edge method. It means this method is automatically called when a BRepBuilderAPI_MakeEdge is found where a TopoDS_Edge is required. 
92
93 This feature allows you  to provide classes, which have the simplicity of function calls when required  and the power of classes when advanced processing is necessary. All the  benefits of this approach are explained when describing the topology programming  interface classes. 
94
95
96 @subsubsection occt_modalg_1_2_1 Error Handling in the Topology API
97
98 A method can report an  error in the two following situations: 
99   * The data or arguments of the  method are incorrect, i.e. they do not respect the restrictions specified by  the methods in its specifications. Typical example: creating a linear edge from  two identical points is likely to lead to a zero divide when computing the  direction of the line.
100   * Something unexpected  happened. This situation covers every error not included in the first category.  Including: interruption, programming errors in the method or in another method  called by the first method, bad specifications of the arguments (i.e. a set of  arguments that was not expected to fail).
101
102 The second situation is  supposed to become increasingly exceptional as a system is debugged and it is  handled by the **exception mechanism**. Using exceptions avoids handling  error statuses in the call to a method: a very cumbersome style of programming. 
103
104 In the first situation,  an exception is also supposed to be raised because the calling method should  have verified the arguments and if it did not do so, there is a bug. For  example if before calling MakeEdge you are not sure that the two points are  non-identical, this situation must be tested. 
105
106 Making those validity  checks on the arguments can be tedious to program and frustrating as you have  probably correctly surmised that the method will perform the test twice. It  does not trust you. 
107 As the test involves a  great deal of computation, performing it twice is also time-consuming. 
108
109 Consequently, you might  be tempted to adopt the *highly inadvisable *style of programming  illustrated in the following example: 
110
111 ~~~~~
112 #include <Standard_ErrorHandler.hxx> 
113 try { 
114 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(P1,P2); 
115 // go on with the edge 
116
117 catch { 
118 // process the error. 
119
120 ~~~~~
121
122 To help the user, the  Topology API classes only raise the exception **StdFail_NotDone**. Any other  exception means that something happened which was unforeseen in the design of  this API. 
123
124 The **NotDone **exception  is only raised when the user tries to access the result of the computation and  the original data is corrupted. At the construction of the class instance, if  the algorithm cannot be completed, the internal flag NotDone is set. This flag  can be tested and in some situations a more complete description of the error  can be queried. If the user ignores the NotDone status and tries to access the  result, an exception is raised. 
125
126 ~~~~~
127 BRepBuilderAPI_MakeEdge ME(P1,P2); 
128 if (!ME.IsDone()) { 
129 // doing ME.Edge() or E = ME here 
130 // would raise StdFail_NotDone 
131 Standard_DomainError::Raise 
132 (“ProcessPoints::Failed to create an edge”); 
133
134 TopoDS_Edge E = ME; 
135 ~~~~~
136
137 @section occt_modalg_2 Geometric Tools
138
139 @subsection occt_modalg_2_1 Overview
140
141 Open CASCADE Technology  geometric tools include: 
142
143   * Computation of intersections
144   * Interpolation laws
145   * Computation of curves and  surfaces from constraints
146   * Computation of lines and  circles from constraints
147   * Projections
148
149 @subsection occt_modalg_2_2 Intersections
150
151 The *Geom2dAPI_InterCurveCurve *class  allows the evaluation of the intersection points (*gp_Pnt2d*) between two  geometric curves (*Geom2d_Curve*)* *and the evaluation of the points  of self-intersection of a curve. 
152
153 ![](/user_guides/modeling_algos/images/modeling_algos_image003.jpg  "Intersection and self-intersection of curves")
154
155 In both cases, the  algorithm requires a value for the tolerance (Standard_Real) for the confusion  between two points. The default tolerance value used in all constructors is *1.0e-6.* 
156
157 ![](/user_guides/modeling_algos/images/modeling_algos_image004.jpg "Intersection and tangent intersection")
158
159 The algorithm returns a  point in the case of an intersection and a segment in the case of tangent  intersection. 
160
161 @subsubsection occt_modalg_2_2_1 Geom2dAPI_InterCurveCurve
162
163 This class may be  instantiated either for intersection of curves C1 and C2.
164 ~~~~~
165 Geom2dAPI_InterCurveCurve Intersector(C1,C2,tolerance); 
166 ~~~~~
167
168 or for self-intersection of curve C3.
169 ~~~~~
170 Geom2dAPI_InterCurveCurve Intersector(C3,tolerance); 
171 ~~~~~
172
173 ~~~~~
174 Standard_Integer N = Intersector.NbPoints(); 
175 ~~~~~
176 Calls the number of intersection points
177
178 To select the desired intersection point, pass an integer index value in argument. 
179 ~~~~~
180 gp_Pnt2d P = Intersector.Point(Index); 
181 ~~~~~
182
183 ~~~~~
184 Standard_Integer M = Intersector.NbSegments(); 
185 ~~~~~
186
187 Calls the number of intersection segments.
188
189 To select the desired intersection segment pass integer index values in argument. 
190 ~~~~~
191 Handle(Geom2d_Curve) Seg1, Seg2; 
192 Intersector.Segment(Index,Seg1,Seg2); 
193 // if intersection of 2 curves 
194 Intersector.Segment(Index,Seg1); 
195 // if self-intersection of a curve 
196 ~~~~~
197
198 If you need access to a  wider range of functionalities the following method will return the algorithmic  object for the calculation of intersections: 
199
200 ~~~~~
201 Geom2dInt_GInter&amp; TheIntersector = Intersector.Intersector(); 
202 ~~~~~
203
204 @subsubsection occt_modalg_2_2_2 Intersection of Curves and Surfaces
205 The *GeomAPI_IntCS *class  is used to compute the intersection points between a curve and a surface. 
206
207 This class is  instantiated as follows: 
208 ~~~~~
209 GeomAPI_IntCS Intersector(C, S); 
210 ~~~~~
211
212 ~~~~~
213 Standard_Integer nb = Intersector.NbPoints(); 
214 ~~~~~
215 Calls the number of intersection points.
216
217 ~~~~~
218 gp_Pnt&amp; P = Intersector.Point(Index); 
219 ~~~~~
220
221 Where *Index *is an  integer between *1 *and *nb*, calls the intersection points.
222
223 @subsubsection occt_modalg_2_2_3 Intersection of two Surfaces
224 The *GeomAPI_IntSS *class  is used to compute the intersection of two surfaces from *Geom_Surface *with  respect to a given tolerance. 
225
226 This class is  instantiated as follows: 
227 ~~~~~
228 GeomAPI_IntSS Intersector(S1, S2, Tolerance); 
229 ~~~~~
230 Once the *GeomAPI_IntSS  *object has been created, it can be interpreted. 
231
232 ~~~~~
233 Standard_Integer nb = Intersector. NbLines(); 
234 ~~~~~
235 Calls the number of intersection curves.
236
237 ~~~~~
238 Handle(Geom_Curve) C = Intersector.Line(Index) 
239 ~~~~~
240 Where *Index *is an  integer between *1 *and *nb*, calls the intersection curves.
241
242 @subsection occt_modalg_2_3  Interpolations
243 *Interpolation* provides functionalities for interpolating  BSpline curves, whether in 2D, using *Geom2dAPI_Interpolate*, or 3D using *GeomAPI_Interpolate*. 
244
245
246 @subsubsection occt_modalg_2_3_1 Geom2dAPI_Interpolate
247 This class is used to  interpolate a BSplineCurve passing through an array of points. If tangency is  not requested at the point of interpolation, continuity will be *C2 *. If  tangency is requested at the point, continuity will be *C1*. If  Periodicity is requested, the curve will be closed and the junction will be the  first point given. The curve will then have a continuity of *C1* only. 
248 This class may be  instantiated as follows: 
249 ~~~~~
250 Geom2dAPI_Interpolate 
251 (const  Handle_TColgp_HArray1OfPnt2d&amp; Points, 
252 const  Standard_Boolean PeriodicFlag, 
253 const Standard_Real  Tolerance); 
254
255 Geom2dAPI_Interpolate Interp(Points, Standard_False, 
256                                     Precision::Confusion()); 
257 ~~~~~
258
259
260 It is possible to call the BSpline curve from the object defined  above it. 
261 ~~~~~
262 Handle(Geom2d_BSplineCurve) C = Interp.Curve(); 
263 ~~~~~
264
265 Note that the *Handle(Geom2d_BSplineCurve)* operator has been redefined by the method Curve(). Consequently, it is  unnecessary to pass via the construction of an intermediate object of the *Geom2dAPI_Interpolate  *type and the following syntax is correct. 
266
267 ~~~~~
268 Handle(Geom2d_BSplineCurve) C = 
269 Geom2dAPI_Interpolate(Points, 
270     Standard_False, 
271     Precision::Confusion()); 
272 ~~~~~
273
274 @subsubsection occt_modalg_2_3_2 GeomAPI_Interpolate
275
276 This class may be  instantiated as follows: 
277 ~~~~~
278 GeomAPI_Interpolate 
279 (const  Handle_TColgp_HArray1OfPnt&amp; Points, 
280 const  Standard_Boolean PeriodicFlag, 
281 const Standard_Real  Tolerance); 
282
283 GeomAPI_Interpolate Interp(Points, Standard_False, 
284                                     Precision::Confusion()); 
285 ~~~~~
286
287 It is possible to call the BSpline curve from the object defined  above it. 
288 ~~~~~
289 Handle(Geom_BSplineCurve) C = Interp.Curve(); 
290 ~~~~~
291 Note that the *Handle(Geom_BSplineCurve)* operator has been redefined by the method Curve(). Thus, it is unnecessary  to pass via the construction of an intermediate object of the GeomAPI_Interpolate  type and the following syntax is correct. 
292
293 Handle(Geom_BSplineCurve) C = 
294         GeomAPI_Interpolate(Points,  
295                                                 Standard_False,
296                                                 1.0e-7); 
297
298 Boundary conditions may  be imposed with the method Load. 
299 ~~~~~
300 GeomAPI_Interpolate AnInterpolator 
301 (Points, Standard_False, 1.0e-5); 
302 AnInterpolator.Load (StartingTangent, EndingTangent); 
303 ~~~~~
304
305 @subsection occt_modalg_2_4 Lines and  Circles from Constraints
306
307 There are two packages  to create lines and circles from constraints: *Geom2dGcc *and *GccAna*. *Geom2dGcc* deals with reference-handled geometric objects from the *Geom2d *package  while *GccAna* deals with value-handled geometric objects from the *gp* package. 
308
309 The *Geom2dGcc* package  solves geometric constructions of lines and circles expressed by constraints  such as tangency or parallelism, that is, a constraint expressed in geometric  terms. As a simple example the following figure shows a line which is  constrained to pass through a point and be tangent to a circle. 
310
311 ![](/user_guides/modeling_algos/images/modeling_algos_image005.jpg  "A constrained line")
312
313 The *Geom2dGcc *package  focuses on algorithms; it is useful for finding results, but it does not offer  any management or modification functions, which could be applied to the  constraints or their arguments. This package is designed to offer optimum  performance, both in rapidity and precision. Trivial cases (for example, a  circle centered on one point and passing through another) are not treated. 
314
315 The *Geom2dGcc *package  deals only with 2d objects from the *Geom2d *package. These objects are  the points, lines and circles available. 
316
317 All other lines such as  Bezier curves and conic sections - with the exception of circles -are  considered general curves and must be differentiable twice. 
318
319 The *GccAna *package  deals with points, lines, and circles from the *gp *package. Apart from  constructors for lines and circles, it also allows the creation of conics from  the bisection of other geometric objects. 
320
321 @subsection occt_modalg_2_5 Provided algorithms
322
323 The following analytic algorithms using value-handled entities for creation of 2D lines or circles with geometric constraints are available: 
324
325   * circle tangent to three  elements (lines, circles, curves, points),
326   * circle tangent to two  elements and having a radius,
327   * circle tangent to two  elements and centered on a third element,
328   * circle tangent to two  elements and centered on a point,
329   * circle tangent to one element  and centered on a second,
330   * bisector of two points,
331   * bisector of two lines,
332   * bisector of two circles,
333   * bisector of a line and a  point,
334   * bisector of a circle and a  point,
335   * bisector of a line and a  circle,
336   * line tangent to two elements  (points, circles, curves),
337   * line tangent to one element  and parallel to a line,
338   * line tangent to one element  and perpendicular to a line,
339   * line tangent to one element  and forming angle with a line.
340
341 @subsection occt_modalg_2_6 Types of  algorithms
342 There are three  categories of available algorithms, which complement each other: 
343   * analytic,
344   * geometric,
345   * iterative.
346
347 An analytic algorithm  will solve a system of equations, whereas a geometric algorithm works with  notions of parallelism, tangency, intersection and so on. 
348
349 Both methods can provide  solutions. An iterative algorithm, however, seeks to refine an approximate  solution. 
350
351 @subsection occt_modalg_2_7  Performance factors
352
353 The appropriate  algorithm is the one, which reaches a solution of the required accuracy in the  least time. Only the solutions actually requested by the user should be  calculated. A simple means to reduce the number of solutions is the notion of a  &quot;qualifier&quot;. There are four qualifiers, which are: 
354
355   * Unqualified: the position of  the solution is undefined with respect to this argument.
356   * Enclosing: the solution  encompasses this argument.
357   * Enclosed: the solution is  encompassed by this argument.
358   * Outside: the solution and  argument are outside each other.
359
360
361 @subsection occt_modalg_2_8  Conventions
362
363 @subsubsection occt_modalg_2_8_1 Exterior/Interior
364 It is not hard to define  the interior and exterior of a circle. As is shown in the following diagram,  the exterior is indicated by the sense of the binormal, that is to say the  right side according to the sense of traversing the circle. The left side is  therefore the interior (or &quot;material&quot;). 
365
366 ![](/user_guides/modeling_algos/images/modeling_algos_image006.jpg "Exterior/Interior of a Circle")
367
368 By extension, the  interior of a line or any open curve is defined as the left side according to  the passing direction, as shown in the following diagram: 
369
370 ![](/user_guides/modeling_algos/images/modeling_algos_image007.jpg "Exterior/Interior of a Line and a Curve")
371
372 @subsubsection occt_modalg_2_8_2 Orientation of a Line
373 It is sometimes  necessary to define in advance the sense of travel along a line to be created.  This sense will be from first to second argument. 
374
375 The following figure shows a line, which is  first tangent to circle C1 which is interior to the line, and then passes  through point P1. 
376
377 ![](/user_guides/modeling_algos/images/modeling_algos_image008.jpg "An Oriented Line")
378
379 @subsection occt_modalg_2_9 Examples
380
381 @subsubsection occt_modalg_2_9_1 Line tangent to two circles
382 The following four  diagrams illustrate four cases of using qualifiers in the creation of a line.  The fifth shows the solution if no qualifiers are given.
383  
384 Note that the qualifier  &quot;Outside&quot; is used to mean &quot;Mutually exterior&quot;. 
385
386 **Example 1 Case 1** 
387
388 ![](/user_guides/modeling_algos/images/modeling_algos_image009.jpg "Both circles outside")
389
390 Constraints: 
391 Tangent and Exterior to  C1. 
392 Tangent and Exterior to  C2. 
393
394 Syntax: 
395
396 ~~~~~
397 GccAna_Lin2d2Tan 
398         Solver(GccEnt::Outside(C1), 
399                 GccEnt::Outside(C2), 
400                 Tolerance); 
401 ~~~~~
402
403 **Example 1 Case 2** 
404
405 ![](/user_guides/modeling_algos/images/modeling_algos_image010.jpg "Both circles enclosed")
406
407 Constraints: 
408 Tangent and Including  C1. 
409 Tangent and Including  C2. 
410
411 Syntax: 
412
413 ~~~~~
414 GccAna_Lin2d2Tan 
415         Solver(GccEnt::Enclosing(C1), 
416                 GccEnt::Enclosing(C2), 
417                 Tolerance); 
418 ~~~~~
419
420 **Example  1 Case 3**
421  
422 ![](/user_guides/modeling_algos/images/modeling_algos_image011.jpg "C1 enclosed, C2 outside")
423
424 Constraints: 
425 Tangent and Including C1. 
426 Tangent and Exterior to  C2. 
427
428 Syntax: 
429 ~~~~~
430 GccAna_Lin2d2Tan 
431         Solver(GccEnt::Enclosing(C1), 
432                 GccEnt::Outside(C2), 
433                 Tolerance); 
434 ~~~~~
435
436 **Example 1 Case 4** 
437
438 ![](/user_guides/modeling_algos/images/modeling_algos_image012.jpg "C1 outside, C2 enclosed")
439 Constraints: 
440 Tangent and Exterior to  C1. 
441 Tangent and Including  C2. 
442
443 Syntax: 
444 ~~~~~
445 GccAna_Lin2d2Tan 
446         Solver(GccEnt::Outside(C1), 
447                 GccEnt::Enclosing(C2), 
448                 Tolerance); 
449 ~~~~~
450
451 **Example 1 Case 5** 
452
453 ![](/user_guides/modeling_algos/images/modeling_algos_image013.jpg "With no qualifiers specified")
454
455 Constraints: 
456 Tangent and Undefined  with respect to C1. 
457 Tangent and Undefined  with respect to C2. 
458
459 Syntax: 
460 ~~~~~
461 GccAna_Lin2d2Tan 
462         Solver(GccEnt::Unqualified(C1), 
463                 GccEnt::Unqualified(C2), 
464                 Tolerance); 
465 ~~~~~
466
467 @subsubsection occt_modalg_2_9_2 Circle of given radius tangent to two circles
468 The following four  diagrams show the four cases in using qualifiers in the creation of a circle. 
469
470 **Example 2 Case 1** 
471 ![](/user_guides/modeling_algos/images/modeling_algos_image014.jpg "Both solutions outside")
472
473 Constraints: 
474 Tangent and Exterior to  C1. 
475 Tangent and Exterior to  C2. 
476
477 Syntax: 
478 ~~~~~
479 GccAna_Circ2d2TanRad 
480         Solver(GccEnt::Outside(C1), 
481         GccEnt::Outside(C2),  Rad, Tolerance); 
482 ~~~~~
483
484 **Example 2 Case 2** 
485
486 ![](/user_guides/modeling_algos/images/modeling_algos_image015.jpg "C2 encompasses C1")
487
488 Constraints: 
489 Tangent and Exterior to  C1. 
490 Tangent and Included by  C2. 
491
492 Syntax: 
493 ~~~~~
494 GccAna_Circ2d2TanRad 
495         Solver(GccEnt::Outside(C1), 
496                 GccEnt::Enclosed(C2),  Rad, Tolerance); 
497 ~~~~~
498
499 **Example  2 Case 3**
500 ![](/user_guides/modeling_algos/images/modeling_algos_image016.jpg "Solutions enclose C2")
501
502 Constraints: 
503 Tangent and Exterior to  C1. 
504 Tangent and Including  C2. 
505
506 Syntax: 
507 ~~~~~
508 GccAna_Circ2d2TanRad 
509         Solver(GccEnt::Outside(C1), 
510                 GccEnt::Enclosing(C2),  Rad, Tolerance); 
511 ~~~~~
512                 
513 **Example 2 Case 4**
514 ![](/user_guides/modeling_algos/images/modeling_algos_image017.jpg "Solutions enclose C1")
515
516 Constraints: 
517 Tangent and Enclosing  C1. 
518 Tangent and Enclosing  C2. 
519
520 Syntax: 
521 ~~~~~
522 GccAna_Circ2d2TanRad 
523         Solver(GccEnt::Enclosing(C1), 
524                 GccEnt::Enclosing(C2),  Rad, Tolerance); 
525 ~~~~~
526
527 **Example 2 Case 5**
528 The following syntax  will give all the circles of radius *Rad, *which are tangent to *C1 *and  *C2 *without discrimination of relative position: 
529
530 ~~~~~
531 GccAna_Circ2d2TanRad  Solver(GccEnt::Unqualified(C1), 
532                                                         GccEnt::Unqualified(C2), 
533                                                         Rad,Tolerance); 
534 ~~~~~                                                   
535                                                         
536 @subsection occt_modalg_2_10  Algorithms
537
538 The objects created by  this toolkit are non-persistent. 
539
540 @subsubsection occt_modalg_2_10_1  Qualifiers
541 The *GccEnt* package  contains the following package methods: 
542         * Unqualified,
543         * Enclosing,
544         * Enclosed,
545         * Outside.
546
547 This enables creation of expressions,  for example:
548 ~~~~~
549 GccAna_Circ2d2TanRad 
550         Solver(GccEnt::Outside(C1), 
551                 GccEnt::Enclosing(C2),  Rad, Tolerance); 
552 ~~~~~
553
554 The objective in this case is to find all circles  of radius *Rad*, which are tangent to both circle *C1* and *C2*, C1 being outside and C2 being inside.
555
556 @subsubsection occt_modalg_2_10_2 General Remarks about Algorithms
557
558 We consider the  following to be the case: 
559   * If a circle passes through a  point then the circle is tangential to it.
560   * A distinction is made between the trivial case of the center at a point and the complex case of the center on a line.
561
562 @subsubsection occt_modalg_2_10_3 Analytic Algorithms
563 GccAna package  implements analytic algorithms. It deals only with points, lines, and  circles from  gp package. Here is a list of the services offered: 
564
565 Creation of a Line
566 ------------------
567
568 ~~~~~
569 Tangent ( point  | circle ) &amp; Parallel ( line ) 
570 Tangent ( point  | circle ) &amp; Perpendicular ( line | circle ) 
571 Tangent ( point  | circle ) &amp; Oblique ( line ) 
572 Tangent ( 2 { point |  circle } ) 
573 Bisector( line | line ) 
574 ~~~~~
575
576 Creation of Conics
577 ------------------
578
579 ~~~~~
580 Bisector ( point | point  ) 
581 Bisector ( line | point  ) 
582 Bisector ( circle | point  ) 
583 Bisector ( line | line ) 
584 Bisector ( circle | line  ) 
585 Bisector ( circle |  circle ) 
586 ~~~~~
587
588 Creation of a Circle
589 --------------------
590 ~~~~~
591 Tangent ( point | line |  circle ) &amp; Center ( point ) 
592 Tangent ( 3 { point |  line | circle } ) 
593 Tangent ( 2 { point |  line | circle } ) &amp; Radius ( real ) 
594 Tangent ( 2 { point |  line | circle } ) &amp; Center ( line | circle ) 
595 Tangent ( point | line |  circle ) &amp; Center ( line | circle ) &amp; Radius ( real ) 
596 ~~~~~
597
598 For each algorithm, the tolerance (and angular tolerance if appropriate) is given as an  argument. Calculation is done with the highest precision available from the  hardware. 
599
600 @subsubsection occt_modalg_2_10_4 Geometric Algorithms
601
602 *Geom2dGcc *package  offers algorithms, which produce 2d lines or circles with geometric  constraints. For arguments, it takes curves for which an approximate solution  is not requested. A tolerance value on the result is given as a starting  parameter. The following services are provided: 
603
604 Creation of a Circle
605 --------------------
606
607 ~~~~~
608 Tangent ( curve ) &amp;  Center ( point ) 
609 Tangent ( curve , point  | line | circle | curve ) &amp; Radius ( real ) 
610 Tangent ( 2 {point |  line | circle} ) &amp; Center ( curve ) 
611 Tangent ( curve ) &amp;  Center ( line | circle | curve ) &amp; Radius ( real ) 
612 Tangent ( point | line |  circle ) &amp; Center ( curve ) &amp; Radius ( real ) 
613 ~~~~~
614
615 All calculations will be  done to the highest precision available from the hardware. 
616
617 @subsubsection occt_modalg_2_10_5 Iterative Algorithms
618 Geom2dGcc package  offers iterative algorithms find a solution by refining an approximate  solution. It produces 2d lines or circles with geometric constraints. For all  geometric arguments except points, an approximate solution may be given as a  starting parameter. The tolerance or angular tolerance value is given as an  argument. The following services are provided: 
619
620 Creation of a Line
621 ------------------
622 ~~~~~
623 Tangent ( curve ) &amp;  Oblique ( line ) 
624 Tangent ( curve , {  point | circle | curve } ) 
625 ~~~~~
626
627 Creation of a Circle
628 --------------------
629
630 ~~~~~
631 Tangent ( curve , 2 {  point | circle | curve } ) 
632 Tangent ( curve , {  point | circle | curve } ) 
633 &amp; Center ( line |  circle | curve ) 
634 ~~~~~
635
636 @subsection occt_modalg_2_1 Curves  and Surfaces from Constraints
637
638 @subsubsection occt_modalg_2_1_1 Fair Curve
639
640 *FairCurve* package  provides a set of classes to create faired 2D curves or 2D curves with minimal  variation in curvature. 
641
642 Creation of Batten Curves
643 -------------------------
644 The class Batten allows  producing faired curves defined on the basis of one or more constraints on  each of the two reference points. These include point, angle of tangency and  curvature settings. 
645 The following constraint orders are available: 
646
647   * 0 the curve must pass through  a point
648   * 1 the curve must pass through  a point and have a given tangent
649   * 2 the curve must pass through  a point, have a given tangent and a given curvature.
650
651 Only 0 and 1 constraint orders are used. 
652 The function Curve  returns the result as a 2D BSpline curve. 
653
654 Creation of Minimal Variation Curves
655 ------------------------------------
656 The class  MinimalVariation allow producing curves with minimal variation in  curvature at each reference point. The following constraint  orders are available: 
657
658   * 0 the curve must pass through  a point
659   * 1 the curve must pass through  a point and have a given tangent
660   * 2 the curve must pass through  a point, have a given tangent and a given curvature.
661
662 Constraint orders of 0, 1 and 2 can be used. The algorithm minimizes tension, sagging and jerk energy. 
663
664 The function *Curve* returns  the result as a 2D BSpline curve. 
665
666 Specifying the length of the curve
667 ----------------------------------
668 If you want to give a  specific length to a batten curve, use: 
669
670 ~~~~~
671 b.SetSlidingFactor(L / b.SlidingOfReference()) 
672 ~~~~~
673 where *b* is the name of  the batten curve object 
674
675 Limitations 
676 -----------
677 Free sliding is  generally more aesthetically pleasing than constrained sliding. 
678 However, the computation  can fail with values such as angles greater than p/2, because in this case, the  length is theoretically infinite. 
679
680 In other cases, when  sliding is imposed and the sliding factor is too large, the batten can  collapse. 
681
682 Computation Time
683 ----------------
684 The constructor parameters, *Tolerance* and *NbIterations*, control how precise the computation is,  and how long it will take. 
685
686 @subsubsection occt_modalg_2_11_2 Surfaces from Boundary Curves
687
688 The *GeomFill* package  provides the following services for creating surfaces from boundary curves: 
689
690 Creation of Bezier surfaces
691 ---------------------------
692 The class *BezierCurves* allows producing a Bezier surface from contiguous Bezier curves. Note  that problems may occur with rational Bezier Curves. 
693
694 Creation of BSpline surfaces
695 ----------------------------
696 The class *BSplineCurves* allows producing a BSpline surface from contiguous BSpline curves.  Note that problems may occur with rational BSplines. 
697
698 Creation of a Pipe
699 ------------------
700 The class *Pipe* allows you producing a pipe by sweeping a curve (the section) along another curve  (the path). The result is a BSpline surface. 
701
702 Filling a contour
703 ----------------
704 The class *GeomFill_ConstrainedFilling* allows filling a contour defined by two, three or four curves as well  as by tangency constraints. The resulting surface is a BSpline. 
705
706 Creation of a Boundary
707 ----------------------
708 The class *GeomFill_SimpleBound* allows you defining a boundary for the surface to be constructed. 
709
710 Creation of a Boundary with an adjoining surface
711 ------------------------------------------------
712 The class *GeomFill_BoundWithSurf* allows defining a boundary for the surface to be constructed. This boundary will already be joined to another surface. 
713
714 Filling styles
715 --------------
716 The enumerations *FillingStyle* specify the styles used to build the surface. These include: 
717
718   * *Stretch* - the style with the flattest patches
719   * *Coons* - a rounded style with less depth than *Curved*
720   * *Curved* - the style with the most rounded patches.
721
722 ![](/user_guides/modeling_algos/images/modeling_algos_image018.jpg "Intersecting filleted edges with different radii leave a gap, is filled by a surface)
723
724
725 @subsubsection occt_modalg_2_11_3 Surfaces from curve and point constraints
726 The *GeomPlate* package  provides the following services for creating surfaces respecting curve and  point constraints: 
727
728 Definition of a Framework
729 -------------------------
730 The class *BuildPlateSurface* allows creating a framework to build surfaces according to curve and  point constraints as well as tolerance settings. The result is returned with  the function *Surface*. 
731
732 Note that you do not have to specify an initial surface at the time of construction. It can be added later  or, if none is loaded, a surface will  be computed automatically. 
733
734 Definition of a Curve Constraint
735 --------------------------------
736 The class *CurveConstraint* allows defining curves as constraints to the surface, which you want  to build. 
737
738 Definition of a Point Constraint
739 --------------------------------
740 The class *PointConstraint* allows defining points as constraints to the surface, which you want  to build. 
741
742 Applying Geom_Surface to Plate Surfaces
743 --------------------------------------
744 The class *Surface* allows describing the characteristics of plate surface objects returned by **BuildPlateSurface::Surface** using the methods of *Geom_Surface* 
745
746 Approximating a Plate surface to a BSpline
747 ------------------------------------------
748 The class *MakeApprox* allows converting a *GeomPlate* surface into a *Geom_BSplineSurface*. 
749
750 ![](/user_guides/modeling_algos/images/modeling_algos_image019.jpg "Surface generated from four curves and a point")
751
752 **Example** 
753
754 Create a Plate surface  and approximate it from a polyline as a curve constraint and a point constraint 
755
756 ~~~~~
757 Standard_Integer NbCurFront=4, 
758 NbPointConstraint=1; 
759 gp_Pnt P1(0.,0.,0.); 
760 gp_Pnt P2(0.,10.,0.); 
761 gp_Pnt P3(0.,10.,10.); 
762 gp_Pnt P4(0.,0.,10.); 
763 gp_Pnt P5(5.,5.,5.); 
764 BRepBuilderAPI_MakePolygon W; 
765 W.Add(P1); 
766 W.Add(P2); 
767 W.Add(P3); 
768 W.Add(P4); 
769 W.Add(P1); 
770 // Initialize a BuildPlateSurface 
771 GeomPlate_BuildPlateSurface BPSurf(3,15,2); 
772 // Create the curve constraints 
773 BRepTools_WireExplorer anExp; 
774 for(anExp.Init(W); anExp.More(); anExp.Next()) 
775
776 TopoDS_Edge E = anExp.Current(); 
777 Handle(BRepAdaptor_HCurve) C = new 
778 BRepAdaptor_HCurve(); 
779 C-ChangeCurve().Initialize(E); 
780 Handle(BRepFill_CurveConstraint) Cont= new 
781 BRepFill_CurveConstraint(C,0); 
782 BPSurf.Add(Cont); 
783
784 // Point constraint 
785 Handle(GeomPlate_PointConstraint) PCont= new 
786 GeomPlate_PointConstraint(P5,0); 
787 BPSurf.Add(PCont); 
788 // Compute the Plate surface 
789 BPSurf.Perform(); 
790 // Approximation of the Plate surface 
791 Standard_Integer MaxSeg=9; 
792 Standard_Integer MaxDegree=8; 
793 Standard_Integer CritOrder=0; 
794 Standard_Real dmax,Tol; 
795 Handle(GeomPlate_Surface) PSurf = BPSurf.Surface(); 
796 dmax = Max(0.0001,10*BPSurf.G0Error()); 
797 Tol=0.0001; 
798 GeomPlate_MakeApprox 
799 Mapp(PSurf,Tol,MaxSeg,MaxDegree,dmax,CritOrder); 
800 Handle (Geom_Surface) Surf (Mapp.Surface()); 
801 // create a face corresponding to the approximated Plate 
802 Surface 
803 Standard_Real Umin, Umax, Vmin, Vmax; 
804 PSurf-Bounds( Umin, Umax, Vmin, Vmax); 
805 BRepBuilderAPI_MakeFace MF(Surf,Umin, Umax, Vmin, Vmax); 
806 ~~~~~
807
808 @subsection occt_modalg_2_12 Projections
809 This package provides  functionality for projecting points onto 2D and 3D curves and surfaces. 
810
811 @subsubsection occt_modalg_2_12_1 Projection of a Point onto a Curve
812 *Geom2dAPI_ProjectPointOnCurve*  allows calculation of all the normals projected from a point (*gp_Pnt2d*)  onto a geometric curve (*Geom2d_Curve*). The calculation may be restricted  to a given domain. 
813
814
815 ![](/user_guides/modeling_algos/images/modeling_algos_image020.jpg  "Normals from a point to a curve")
816
817 Note 
818 ----
819 The  curve does not have to be a *Geom2d_TrimmedCurve*. The algorithm will function with any 
820 class inheriting  Geom2d_Curve. 
821
822 @subsubsection occt_modalg_2_12_2 Geom2dAPI_ProjectPointOnCurve
823 This class may be  instantiated as in the following example: 
824
825 ~~~~~
826 gp_Pnt2d P; 
827 Handle(Geom2d_BezierCurve) C = 
828         new  Geom2d_BezierCurve(args); 
829 Geom2dAPI_ProjectPointOnCurve Projector (P, C); 
830 ~~~~~
831
832 To restrict the search  for normals to a given domain *[U1,U2]*, use the following constructor: 
833 ~~~~~
834 Geom2dAPI_ProjectPointOnCurve Projector (P, C, U1, U2); 
835 ~~~~~
836 Having thus created the *Geom2dAPI_ProjectPointOnCurve* object, we can now interrogate it. 
837
838 Calling the number of solution points
839 -------------------------------------
840 ~~~~~
841 Standard_Integer NumSolutions = Projector.NbPoints(); 
842 ~~~~~
843
844 Calling the location of a solution point
845 ----------------------------------------
846 The solutions are  indexed in a range from *1* to *Projector.NbPoints()*. The point,  which corresponds to a given *Index* may be found: 
847 ~~~~~
848 gp_Pnt2d Pn = Projector.Point(Index); 
849 ~~~~~
850
851 Calling the parameter of a solution point
852 -----------------------------------------
853 For a given point  corresponding to a given *Index*: 
854
855 ~~~~~
856 Standard_Real U = Projector.Parameter(Index); 
857 ~~~~~
858
859 This can also be  programmed as: 
860
861 ~~~~~
862 Standard_Real U; 
863 Projector.Parameter(Index,U); 
864 ~~~~~
865
866 Calling the distance between the start and end points
867 -----------------------------------------------------
868 We can find the distance  between the initial point and a point, which corresponds to the given *Index*: 
869
870 ~~~~~
871 Standard_Real D = Projector.Distance(Index); 
872 ~~~~~
873
874 Calling the nearest solution point
875 ---------------------------------
876
877 This class offers a  method to return the closest solution point to the starting point. This  solution is accessed as follows: 
878 ~~~~~
879 gp_Pnt2d P1 = Projector.NearestPoint(); 
880 ~~~~~
881
882 Calling the parameter of the nearest solution point
883 ---------------------------------------------------
884 ~~~~~
885 Standard_Real U = Projector.LowerDistanceParameter(); 
886 ~~~~~
887
888 Calling the minimum distance from the point to the curve
889 -------------------------------------------------------
890 ~~~~~
891 Standard_Real D = Projector.LowerDistance(); 
892 ~~~~~
893
894 @subsubsection occt_modalg_2_12_3 Redefined operators
895
896 Some operators have been  redefined to find the closest solution. 
897
898 *Standard_Real()* returns  the minimum distance from the point to the curve. 
899
900 ~~~~~
901 Standard_Real D = Geom2dAPI_ProjectPointOnCurve (P,C); 
902 ~~~~~
903
904 *Standard_Integer()* returns the number of solutions. 
905
906 ~~~~~
907 Standard_Integer N = 
908 Geom2dAPI_ProjectPointOnCurve (P,C); 
909 ~~~~~
910
911 *gp_Pnt2d()* returns the  nearest solution point. 
912
913 ~~~~~
914 gp_Pnt2d P1 = Geom2dAPI_ProjectPointOnCurve (P,C); 
915 ~~~~~
916
917 Using these operators  makes coding easier when you only need the nearest point. Thus: 
918 ~~~~~
919 Geom2dAPI_ProjectPointOnCurve Projector (P, C); 
920 gp_Pnt2d P1 = Projector.NearestPoint(); 
921 ~~~~~
922 can be written more  concisely as: 
923 ~~~~~
924 gp_Pnt2d P1 = Geom2dAPI_ProjectPointOnCurve (P,C); 
925 ~~~~~
926 However, note that in  this second case no intermediate *Geom2dAPI_ProjectPointOnCurve* object is created, and thus it  is impossible to have access to other solution points. 
927
928
929 @subsubsection occt_modalg_2_12_4 Access to lower-level functionalities
930
931 If you want to use the  wider range of functionalities available from the *Extrema* package, a call to  the *Extrema()* method will return the algorithmic object for calculating  extrema. For example: 
932
933 ~~~~~
934 Extrema_ExtPC2d&amp; TheExtrema = Projector.Extrema(); 
935 ~~~~~
936
937 @subsubsection occt_modalg_2_12_5 GeomAPI_ProjectPointOnCurve
938
939 This class is  instantiated as in the following example: 
940 ~~~~~
941 gp_Pnt P; 
942 Handle(Geom_BezierCurve) C = 
943         new  Geom_BezierCurve(args); 
944 GeomAPI_ProjectPointOnCurve Projector (P, C); 
945 ~~~~~
946 If you wish to restrict  the search for normals to the given domain [U1,U2], use the following  constructor: 
947 ~~~~~
948 GeomAPI_ProjectPointOnCurve Projector (P, C, U1, U2); 
949 ~~~~~
950 Having thus created the  *GeomAPI_ProjectPointOnCurve* object, you can now interrogate it. 
951
952 Calling the number of solution points
953 -------------------------------------
954 ~~~~~
955 Standard_Integer NumSolutions = Projector.NbPoints(); 
956 ~~~~~
957
958 Calling the location of a solution point
959 ----------------------------------------
960 The solutions are  indexed in a range from 1 to *Projector.NbPoints()*. The point, which corresponds  to a given index, may be found: 
961 ~~~~~
962 gp_Pnt Pn = Projector.Point(Index); 
963 ~~~~~
964
965 Calling the parameter of a solution point
966 -----------------------------------------
967 For a given point  corresponding to a given index: 
968
969 ~~~~~
970 Standard_Real U = Projector.Parameter(Index); 
971 ~~~~~
972
973 This can also be  programmed as: 
974 ~~~~~
975 Standard_Real U; 
976 Projector.Parameter(Index,U); 
977 ~~~~~
978
979 Calling the distance between the start and end point
980 ----------------------------------------------------
981 The distance between the  initial point and a point, which corresponds to a given index, may be found: 
982 ~~~~~
983 Standard_Real D = Projector.Distance(Index); 
984 ~~~~~
985
986 Calling the nearest solution point
987 ----------------------------------
988 This class offers a  method to return the closest solution point to the starting point. This  solution is accessed as follows: 
989 ~~~~~
990 gp_Pnt P1 = Projector.NearestPoint(); 
991 ~~~~~
992
993 Calling the parameter of the nearest solution point
994 ---------------------------------------------------
995 ~~~~~
996 Standard_Real U = Projector.LowerDistanceParameter(); 
997 ~~~~~
998
999 Calling the minimum distance from the point to the curve
1000 --------------------------------------------------------
1001 ~~~~~
1002 Standard_Real D =  Projector.LowerDistance(); 
1003 ~~~~~
1004
1005 Redefined  operators 
1006 --------------------
1007 Some operators have been  redefined to find the nearest solution. 
1008
1009 *Standard_Real()* returns  the minimum distance from the point to the curve. 
1010
1011 ~~~~~
1012 Standard_Real D = GeomAPI_ProjectPointOnCurve (P,C); 
1013 ~~~~~
1014
1015 *Standard_Integer()* returns  the number of solutions. 
1016 ~~~~~
1017 Standard_Integer N =  GeomAPI_ProjectPointOnCurve (P,C); 
1018 ~~~~~
1019
1020 *gp_Pnt2d()* returns the  nearest solution point. 
1021
1022 ~~~~~
1023 gp_Pnt P1 = GeomAPI_ProjectPointOnCurve (P,C); 
1024 ~~~~~
1025 Using these operators  makes coding easier when you only need the nearest point. In this way, 
1026
1027 ~~~~~
1028 GeomAPI_ProjectPointOnCurve Projector (P, C); 
1029 gp_Pnt P1 = Projector.NearestPoint(); 
1030 ~~~~~
1031
1032 can be written more  concisely as: 
1033 ~~~~~
1034 gp_Pnt P1 = GeomAPI_ProjectPointOnCurve (P,C); 
1035 ~~~~~
1036 In the second case,  however, no intermediate *GeomAPI_ProjectPointOnCurve* object is created, and it  is impossible to access other solutions points. 
1037
1038 Access to lower-level functionalities
1039 -------------------------------------
1040 If you want to use the  wider range of functionalities available from the Extrema package, a call to  the *Extrema()* method will return the algorithmic object for calculating the  extrema. For example: 
1041
1042 ~~~~~
1043 Extrema_ExtPC&amp; TheExtrema = Projector.Extrema(); 
1044 ~~~~~
1045
1046 @subsubsection occt_modalg_2_12_6 Projection of a Point on a Surface
1047
1048 *GeomAPI_ProjectPointOnSurf* class allows calculation of all normals  projected from a point from *gp_Pnt* onto a geometric surface from Geom_Surface. 
1049
1050
1051 ![](/user_guides/modeling_algos/images/modeling_algos_image021.jpg  "Projection of normals from a point to a surface")
1052
1053 Note
1054 ---- 
1055 Note that the  surface does not have to be of *Geom_RectangularTrimmedSurface* type.  
1056 The algorithm  will function with any class inheriting Geom_Surface.
1057
1058 *GeomAPI_ProjectPointOnSurf* is instantiated as in the following  example: 
1059 ~~~~~
1060 gp_Pnt P; 
1061 Handle (Geom_Surface) S = new Geom_BezierSurface(args); 
1062 GeomAPI_ProjectPointOnSurf Proj (P, S); 
1063 ~~~~~
1064
1065 To restrict the search  for normals within the given rectangular domain [U1, U2, V1, V2], use the  following constructor: 
1066
1067 ~~~~~
1068 GeomAPI_ProjectPointOnSurf Proj (P, S, U1, U2, V1, V2); 
1069 ~~~~~
1070
1071 The values of U1, U2, V1  and V2 lie at or within their maximum and minimum limits, i.e.: 
1072 ~~~~~
1073 Umin <=  U1 < U2 <= Umax 
1074 Vmin <=  V1 < V2 <= Vmax 
1075 ~~~~~
1076 Having thus created the  *GeomAPI_ProjectPointOnSurf* object, you can interrogate it. 
1077
1078 Calling the number of solution points
1079 -------------------------------------
1080
1081 ~~~~~
1082 Standard_Integer NumSolutions = Proj.NbPoints(); 
1083 ~~~~~
1084
1085 Calling the location of a solution point
1086 ----------------------------------------
1087 The solutions are  indexed in a range from 1 to *Proj.NbPoints()*. The point corresponding to the  given index may be found: 
1088
1089 ~~~~~
1090 gp_Pnt Pn = Proj.Point(Index); 
1091 ~~~~~
1092
1093 Calling the parameters of a solution point
1094 ------------------------------------------
1095 For a given point  corresponding to the given index: 
1096
1097 ~~~~~
1098 Standard_Real U,V; 
1099 Proj.Parameters(Index, U, V); 
1100 ~~~~~
1101
1102 Calling the distance between the start and end point
1103 ----------------------------------------------------
1104
1105 The distance between the  initial point and a point corresponding to the given index may be found: 
1106 ~~~~~
1107 Standard_Real D = Projector.Distance(Index); 
1108 ~~~~~
1109
1110 Calling the nearest solution point
1111 ----------------------------------
1112 This class offers a  method, which returns the closest solution point to the starting point. This  solution is accessed as follows: 
1113 ~~~~~
1114 gp_Pnt P1 = Proj.NearestPoint(); 
1115 ~~~~~
1116
1117 Calling the parameters of the nearest solution point
1118 ----------------------------------------------------
1119 ~~~~~
1120 Standard_Real U,V; 
1121 Proj.LowerDistanceParameters (U, V); 
1122 ~~~~~
1123
1124 Calling the minimum distance from a point to the surface
1125 --------------------------------------------------------
1126 ~~~~~
1127 Standard_Real D = Proj.LowerDistance(); 
1128 ~~~~~
1129
1130 Redefined operators
1131 -------------------
1132 Some operators have been  redefined to help you find the nearest solution. 
1133
1134 *Standard_Real()* returns  the minimum distance from the point to the surface. 
1135
1136 ~~~~~
1137 Standard_Real D = GeomAPI_ProjectPointOnSurf (P,S); 
1138 ~~~~~
1139
1140 *Standard_Integer()* returns  the number of solutions. 
1141
1142 ~~~~~
1143 Standard_Integer N = GeomAPI_ProjectPointOnSurf (P,S); 
1144 ~~~~~
1145
1146 *gp_Pnt2d()* returns the  nearest solution point. 
1147
1148 ~~~~~
1149 gp_Pnt P1 = GeomAPI_ProjectPointOnSurf (P,S); 
1150 ~~~~~
1151
1152 Using these operators  makes coding easier when you only need the nearest point. In this way, 
1153
1154 ~~~~~
1155 GeomAPI_ProjectPointOnSurface Proj (P, S); 
1156 gp_Pnt P1 = Proj.NearestPoint(); 
1157 ~~~~~
1158
1159 can be written more concisely as: 
1160
1161 ~~~~~
1162 gp_Pnt P1 = GeomAPI_ProjectPointOnSurface (P,S); 
1163 ~~~~~
1164
1165 In the second case,  however, no intermediate *GeomAPI_ProjectPointOnSurf* object is created,  and it is impossible to access other solution points. 
1166
1167 @subsubsection occt_modalg_2_12_7 Access to lower-level functionalities
1168
1169 If you want to use the  wider range of functionalities available from the Extrema package, a call to  the Extrema() method will return the algorithmic object for calculating the  extrema as follows: 
1170
1171 ~~~~~
1172 Extrema_ExtPS&amp; TheExtrema = Proj.Extrema(); 
1173 ~~~~~
1174
1175
1176 @subsubsection occt_modalg_2_12_8 Switching from 2d and 3d Curves
1177 The To2d and To3d methods are used to; 
1178
1179   * build a 2d curve from a 3d  Geom_Curve lying on a gp_Pln plane
1180   * build a 3d curve from a  Geom2d_Curve and a gp_Pln plane.
1181
1182 These methods are called  as follows: 
1183 ~~~~~
1184 Handle(Geom2d_Curve) C2d = GeomAPI::To2d(C3d, Pln); 
1185 Handle(Geom_Curve) C3d = GeomAPI::To3d(C2d, Pln); 
1186 ~~~~~
1187
1188
1189 @section occt_modalg_3 Topological Tools
1190
1191 Open CASCADE Technology  topological tools include: 
1192
1193   * Standard topological objects  combining topological data structure and boundary representation
1194   * Geometric Transformations
1195   * Conversion to NURBS geometry
1196   * Finding Planes
1197   * Duplicating Shapes
1198   * Checking Validity
1199
1200
1201 @subsection occt_modalg_3_1 Creation of Standard  Topological Objects
1202
1203 The standard topological  objects include 
1204   * Vertices
1205   * Edges
1206   * Wires
1207   * Faces
1208   * Shells
1209   * Solids.
1210
1211 There are two root classes for their construction and modification: 
1212 * The deferred class  *BRepBuilderAPI_MakeShape* is the root of all *BRepBuilderAPI* classes,  which build shapes. It inherits from the class *BRepBuilderAPI_Command* and provides a field to store the constructed shape. 
1213 * The deferred *BRepBuilderAPI_ModifyShape* is used as a root for the shape  modifications. It inherits *BRepBuilderAPI_MakeShape* and implements the methods  used to trace the history of all sub-shapes. 
1214
1215 @subsubsection occt_modalg_3_1_1 Vertex
1216
1217 *BRepBuilderAPI_MakeVertex*  creates a new vertex from a 3D point from gp. 
1218 ~~~~~
1219 gp_Pnt P(0,0,10); 
1220 TopoDS_Vertex V = BRepBuilderAPI_MakeVertex(P); 
1221 ~~~~~
1222
1223 This class always creates a new vertex and has no other methods.
1224
1225 @subsubsection occt_modalg_3_1_2 Edge
1226
1227 Use *BRepBuilderAPI_MakeEdge* to create from a curve and vertices. The basic method is to  construct an edge from a curve, two vertices, and two parameters. All other constructions are derived from this one. The basic method and its arguments are  described first, followed by the other methods. The BRepBuilderAPI_MakeEdge  class can provide extra information and return an error status. 
1228
1229 Basic Edge construction
1230 -----------------------
1231
1232 ~~~~~
1233 Handle(Geom_Curve) C = ...; // a curve 
1234 TopoDS_Vertex V1 = ...,V2 = ...;// two Vertices 
1235 Standard_Real p1 = ..., p2 = ..;// two parameters 
1236 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(C,V1,V2,p1,p2); 
1237 ~~~~~
1238
1239 where C is the domain of the edge; V1 is the first vertex oriented FORWARD; V2 is the second vertex oriented REVERSED; p1  and p2 are the parameters for the vertices V1 and V2 on the curve. The default  tolerance is associated with this edge. 
1240
1241 ![](/user_guides/modeling_algos/images/modeling_algos_image022.jpg "Basic Edge Construction")
1242
1243 The following rules  apply to the arguments: 
1244
1245 **The curve**
1246   * Must not be a Null Handle.
1247   * If the curve is a trimmed  curve, the basis curve is used.
1248
1249 **The vertices** 
1250   * Can be null shapes. When V1  or V2 is Null the edge is open in the corresponding direction and the  corresponding parameter p1 or p2 must be infinite (i.e p1 is RealFirst(),  p2 is RealLast()).
1251   * Must be different vertices if  they have different 3d locations and identical vertices if they have the same  3d location (identical vertices are used when the curve is closed).
1252
1253 **The parameters**
1254   * Must be increasing and in the  range of the curve, i.e.:
1255 ~~~~~
1256   C->FirstParameter() <=  p1 < p2 <= C->LastParameter() 
1257 ~~~~~  
1258   
1259 * If the parameters are  decreasing, the Vertices are switched, i.e. V2 becomes V1 and V1 becomes V2.
1260 * On a periodic curve the  parameters p1 and p2 are adjusted by adding or subtracting the period to obtain  p1 in the range of the curve and p2 in the range p1 < p2 <= p1+ Period.  So on a parametric curve p2 can be greater than the second parameter,  see the figure below.
1261 * Can be infinite but the  corresponding vertex must be Null (see above).
1262 * The distance between the Vertex 3d location and the point  evaluated on the curve with the parameter must be lower than the default  precision.
1263
1264 The figure below  illustrates two special cases, a semi-infinite edge and an edge on a periodic  curve. 
1265
1266 ![](/user_guides/modeling_algos/images/modeling_algos_image023.jpg   "Infinite and Periodic Edges")
1267
1268
1269 Other Edge constructions
1270 ------------------------
1271 *BRepBuilderAPI_MakeEdge* class provides methods, which are all simplified calls  of the previous one: 
1272
1273   * The parameters can be  omitted. They are computed by projecting the vertices on the curve.
1274   * 3d points (Pnt from gp) can  be given in place of vertices. Vertices are created from the points. Giving  vertices is useful when creating connected vertices.
1275   * The vertices or points can be  omitted if the parameters are given. The points are computed by evaluating the  parameters on the curve.
1276   * The vertices or points and  the parameters can be omitted. The first and the last parameters of the curve are used.
1277
1278 The five following  methods are thus derived from the basic construction: 
1279
1280 ~~~~~
1281 Handle(Geom_Curve) C = ...; // a curve 
1282 TopoDS_Vertex V1 = ...,V2 = ...;// two Vertices 
1283 Standard_Real p1 = ..., p2 = ..;// two parameters 
1284 gp_Pnt P1 = ..., P2 = ...;// two points 
1285 TopoDS_Edge E; 
1286 // project the vertices on the curve 
1287 E = BRepBuilderAPI_MakeEdge(C,V1,V2); 
1288 // Make vertices from points 
1289 E = BRepBuilderAPI_MakeEdge(C,P1,P2,p1,p2); 
1290 // Make vertices from points and project them 
1291 E = BRepBuilderAPI_MakeEdge(C,P1,P2); 
1292 // Computes the points from the parameters 
1293 E = BRepBuilderAPI_MakeEdge(C,p1,p2); 
1294 // Make an edge from the whole curve 
1295 E = BRepBuilderAPI_MakeEdge(C); 
1296 ~~~~~
1297
1298
1299 Six methods (the five above and the basic method) are also provided for curves from the gp package in  place of Curve from Geom. The methods create the corresponding Curve from Geom  and are implemented for the following classes: 
1300
1301 *gp_Lin*       creates a  *Geom_Line* 
1302 *gp_Circ*      creates a  *Geom_Circle* 
1303 *gp_Elips*    creates a  *Geom_Ellipse* 
1304 *gp_Hypr*    creates a  *Geom_Hyperbola* 
1305 *gp_Parab*   creates a  *Geom_Parabola* 
1306
1307 There are also two  methods to construct edges from two vertices or two points. These methods  assume that the curve is a line; the vertices or points must have different  locations. 
1308
1309 ~~~~~
1310
1311 TopoDS_Vertex V1 = ...,V2 = ...;// two Vertices 
1312 gp_Pnt P1 = ..., P2 = ...;// two points 
1313 TopoDS_Edge E; 
1314
1315 // linear edge from two vertices 
1316 E = BRepBuilderAPI_MakeEdge(V1,V2); 
1317
1318 // linear edge from two points 
1319 E = BRepBuilderAPI_MakeEdge(P1,P2); 
1320 ~~~~~
1321
1322 Other information and error status
1323 ----------------------------------
1324 If BRepBuilderAPI_MakeEdge is used as a class, it can provide two vertices. This is useful when  the vertices were not provided as arguments, for example when the edge was  constructed from a curve and parameters. The two methods Vertex1 and Vertex2  return the vertices. Note that the returned vertices can be null if the edge is  open in the corresponding direction. 
1325
1326 The *Error* method  returns a term of the *BRepBuilderAPI_EdgeError* enumeration. It can be used to analyze the error when *IsDone* method returns False. The terms are: 
1327
1328   * **EdgeDone** - No error occurred, *IsDone* returns True. 
1329   * **PointProjectionFailed** - No parameters were given, but the projection of  the 3D points on the curve failed. This happens if the point distance to the  curve is greater than the precision. 
1330   * **ParameterOutOfRange** - The given parameters are not in the range  *C->FirstParameter()*, *C->LastParameter()* 
1331   * **DifferentPointsOnClosedCurve** -  The  two vertices or points have different locations but they are the extremities of  a closed curve. 
1332   * **PointWithInfiniteParameter** - A finite coordinate point was associated with an  infinite parameter (see the Precision package for a definition of infinite  values). 
1333   * **DifferentsPointAndParameter**  - The distance of the 3D point and the point  evaluated on the curve with the parameter is greater than the precision. 
1334   * **LineThroughIdenticPoints** - Two identical points were given to define a line  (construction of an edge without curve), *gp::Resolution* is used to test confusion . 
1335
1336 The following example  creates a rectangle centered on the origin of dimensions H, L with fillets of radius R. The edges and the vertices are stored in the arrays *theEdges* and *theVertices*. We use class *Array1OfShape* (i.e. not arrays of edges or vertices).  See the image below. 
1337
1338 ![](/user_guides/modeling_algos/images/modeling_algos_image024.jpg "Creating a Wire")
1339
1340 ~~~~~
1341 #include <BRepBuilderAPI_MakeEdge.hxx> 
1342 #include <TopoDS_Shape.hxx> 
1343 #include <gp_Circ.hxx> 
1344 #include <gp.hxx> 
1345 #include <TopoDS_Wire.hxx> 
1346 #include <TopTools_Array1OfShape.hxx> 
1347 #include <BRepBuilderAPI_MakeWire.hxx> 
1348
1349 // Use MakeArc method to make an edge and two vertices 
1350 void MakeArc(Standard_Real x,Standard_Real y, 
1351 Standard_Real R, 
1352 Standard_Real ang, 
1353 TopoDS_Shape&amp; E, 
1354 TopoDS_Shape&amp; V1, 
1355 TopoDS_Shape&amp; V2) 
1356
1357 gp_Ax2 Origin = gp::XOY(); 
1358 gp_Vec Offset(x, y, 0.); 
1359 Origin.Translate(Offset); 
1360 BRepBuilderAPI_MakeEdge 
1361 ME(gp_Circ(Origin,R),  ang, ang+PI/2); 
1362 E = ME; 
1363 V1 = ME.Vertex1(); 
1364 V2 = ME.Vertex2(); 
1365
1366
1367 TopoDS_Wire MakeFilletedRectangle(const Standard_Real H, 
1368 const Standard_Real L, 
1369 const Standard_Real  R) 
1370
1371 TopTools_Array1OfShape theEdges(1,8); 
1372 TopTools_Array1OfShape theVertices(1,8); 
1373
1374 // First create the circular edges and the vertices 
1375 // using the MakeArc function described above. 
1376 void MakeArc(Standard_Real, Standard_Real, 
1377 Standard_Real, Standard_Real, 
1378 TopoDS_Shape&amp;, TopoDS_Shape&amp;,  TopoDS_Shape&amp;); 
1379
1380 Standard_Real x = L/2 - R, y = H/2 - R; 
1381 MakeArc(x,-y,R,3.*PI/2.,theEdges(2),theVertices(2), 
1382 theVertices(3)); 
1383 MakeArc(x,y,R,0.,theEdges(4),theVertices(4), 
1384 theVertices(5)); 
1385 MakeArc(-x,y,R,PI/2.,theEdges(6),theVertices(6), 
1386 theVertices(7)); 
1387 MakeArc(-x,-y,R,PI,theEdges(8),theVertices(8), 
1388 theVertices(1)); 
1389 // Create the linear edges 
1390 for (Standard_Integer i = 1; i <= 7; i += 2) 
1391
1392 theEdges(i) = BRepBuilderAPI_MakeEdge 
1393 (TopoDS::Vertex(theVertices(i)),TopoDS::Vertex 
1394 (theVertices(i+1))); 
1395
1396 // Create the wire using the BRepBuilderAPI_MakeWire 
1397 BRepBuilderAPI_MakeWire MW; 
1398 for (i = 1; i <= 8; i++) 
1399
1400 MW.Add(TopoDS::Edge(theEdges(i))); 
1401
1402 return MW.Wire(); 
1403
1404 ~~~~~
1405
1406 @subsubsection occt_modalg_3_1_3 Edge 2D
1407
1408 Use *BRepBuilderAPI_MakeEdge2d* class to make  edges on a working plane from 2d curves. The working plane is a default value  of the *BRepBuilderAPI* package (see the *Plane* methods). 
1409
1410 *BRepBuilderAPI_MakeEdge2d* class is strictly similar to BRepBuilderAPI_MakeEdge, but it uses 2D geometry from gp and Geom2d instead of  3D geometry. 
1411
1412 @subsubsection occt_modalg_3_1_4 Polygon
1413
1414 *BRepBuilderAPI_MakePolygon* class is used to build polygonal wires from vertices  or points. Points are automatically changed to vertices as in  *BRepBuilderAPI_MakeEdge*. 
1415
1416 The basic usage of  *BRepBuilderAPI_MakePolygon* is to create a wire by adding vertices or points  using the Add method. At any moment, the current wire can be extracted. The  close method can be used to close the current wire. In the following example, a  closed wire is created from an array of points. 
1417
1418 ~~~~~
1419 #include <TopoDS_Wire.hxx> 
1420 #include <BRepBuilderAPI_MakePolygon.hxx> 
1421 #include <TColgp_Array1OfPnt.hxx> 
1422
1423 TopoDS_Wire ClosedPolygon(const TColgp_Array1OfPnt&amp;  Points) 
1424
1425 BRepBuilderAPI_MakePolygon MP; 
1426 for(Standard_Integer i=Points.Lower();i=Points.Upper();i++) 
1427
1428 MP.Add(Points(i)); 
1429
1430 MP.Close(); 
1431 return MP; 
1432
1433 ~~~~~
1434
1435 Short-cuts are provided  for 2, 3, or 4 points or vertices. Those methods have a Boolean last argument  to tell if the polygon is closed. The default value is False. 
1436
1437 Two examples: 
1438
1439 Example of a closed  triangle from three vertices:
1440 ~~~~~ 
1441 TopoDS_Wire W =  BRepBuilderAPI_MakePolygon(V1,V2,V3,Standard_True); 
1442 ~~~~~
1443
1444 Example of an open  polygon from four points:
1445 ~~~~~
1446 TopoDS_Wire W = BRepBuilderAPI_MakePolygon(P1,P2,P3,P4); 
1447 ~~~~~
1448
1449 BRepBuilderAPI_MakePolygon class maintains a current wire. The current wire can  be extracted at any moment and the construction can proceed to a longer wire.  After each point insertion, the class maintains the last created edge and  vertex, which are returned by the methods Edge, FirstVertex and LastVertex. 
1450
1451 When the added point or  vertex has the same location as the previous one it is not added to the current  wire but the most recently created edge becomes Null. The **Added** method  can be used to test this condition. The MakePolygon class never raises an  error. If no vertex has been added, the Wire is Null. If two vertices are at  the same location, no edge is created. 
1452
1453 @subsubsection occt_modalg_3_1_5 Face
1454
1455 Use *BRepBuilderAPI_MakeFace* class to create a face from a surface and wires. An underlying surface is  constructed from a surface and optional parametric values. Wires can be added  to the surface. A planar surface can be constructed from a wire. An error  status can be returned after face construction. 
1456
1457 Basic face construction
1458 -----------------------
1459
1460 A face can be  constructed from a surface and four parameters to determine a limitation of the  UV space. The parameters are optional, if they are omitted the natural bounds  of the surface are used. Up to four edges and vertices are created with a wire.  No edge is created when the parameter is infinite. 
1461
1462 ~~~~~
1463 Handle(Geom_Surface) S = ...; // a surface 
1464 Standard_Real umin,umax,vmin,vmax; // parameters 
1465 TopoDS_Face F =  BRepBuilderAPI_MakeFace(S,umin,umax,vmin,vmax); 
1466 ~~~~~
1467
1468 ![](/user_guides/modeling_algos/images/modeling_algos_image025.jpg   Basic Face Construction)
1469
1470 To make a face from the  natural boundary of a surface, the parameters are not required: 
1471
1472 ~~~~~
1473 Handle(Geom_Surface) S = ...; // a surface 
1474 TopoDS_Face F = BRepBuilderAPI_MakeFace(S); 
1475 ~~~~~
1476
1477 Constraints on the  parameters are similar to the constraints in *BRepBuilderAPI_MakeEdge*. 
1478   * umin,umax (vmin,vmax) must be  in the range of the surface and must be increasing.
1479   * On a U (V) periodic surface  umin and umax (vmin,vmax) are adjusted.
1480   * umin, umax, vmin, vmax can be  infinite. There will be no edge in the corresponding direction.
1481
1482
1483 Other face constructions
1484 ------------------------
1485 The two basic  constructions (from a surface and from a surface and parameters) are  implemented for all the gp package surfaces, which are transformed in the  corresponding Surface from Geom. 
1486
1487 *gp_Pln*                creates  a *Geom_Plane* 
1488 *gp_Cylinder*           creates  a *Geom_CylindricalSurface* 
1489 *gp_Cone*               creates  a *Geom_ConicalSurface* 
1490 *gp_Sphere*             creates  a *Geom_SphericalSurface* 
1491 *gp_Torus*              creates  a *Geom_ToroidalSurface* 
1492
1493 Once a face has been  created, a wire can be added using the Add method. For example, the following  code creates a cylindrical surface and adds a wire. 
1494
1495 ~~~~~
1496 gp_Cylinder C = ..; // a cylinder 
1497 TopoDS_Wire W = ...;// a wire 
1498 BRepBuilderAPI_MakeFace MF(C); 
1499 MF.Add(W); 
1500 TopoDS_Face F = MF; 
1501 ~~~~~
1502
1503 More than one wire can  be added to a face, provided that they do not cross each other and they define  only one area on the surface. (Note that this is not checked). The edges on a  Face must have a parametric curve description. 
1504
1505 If there is no  parametric curve for an edge of the wire on the Face it is computed by  projection. 
1506
1507 For one wire, a simple  syntax is provided to construct the face from the surface and the wire. The  above lines could be written: 
1508
1509 ~~~~~
1510 TopoDS_Face F = BRepBuilderAPI_MakeFace(C,W); 
1511 ~~~~~
1512
1513 A planar face can be  created from only a wire, provided this wire defines a plane. For example, to  create a planar face from a set of points you can use *BRepBuilderAPI_MakePolygon* and *BRepBuilderAPI_MakeFace*.
1514
1515 ~~~~~
1516 #include <TopoDS_Face.hxx> 
1517 #include <TColgp_Array1OfPnt.hxx> 
1518 #include <BRepBuilderAPI_MakePolygon.hxx> 
1519 #include <BRepBuilderAPI_MakeFace.hxx> 
1520
1521 TopoDS_Face PolygonalFace(const TColgp_Array1OfPnt&amp;  thePnts) 
1522
1523 BRepBuilderAPI_MakePolygon MP; 
1524 for(Standard_Integer i=thePnts.Lower(); 
1525 i<=thePnts.Upper(); i++) 
1526
1527 MP.Add(thePnts(i)); 
1528
1529 MP.Close(); 
1530 TopoDS_Face F = BRepBuilderAPI_MakeFace(MP.Wire()); 
1531 return F; 
1532
1533 ~~~~~
1534
1535 The last use of MakeFace is to copy an existing face to  add new wires. For example the following code adds a new wire to a face: 
1536
1537 ~~~~~
1538 TopoDS_Face F = ...; // a face 
1539 TopoDS_Wire W = ...; // a wire 
1540 F = BRepBuilderAPI_MakeFace(F,W); 
1541 ~~~~~
1542
1543 To add more than one  wire an instance of the *BRepBuilderAPI_MakeFace* class can be created with the  face and the first wire and the new wires inserted with the Add method. 
1544
1545 Error status
1546 ------------
1547 The Error method returns  an error status, which is a term from the *BRepBuilderAPI_FaceError* enumeration. 
1548
1549 * *FaceDone* - no  error occurred. 
1550 * *NoFace* - no initialization of the algorithm; an empty constructor was used. 
1551 * *NotPlanar* - no  surface was given and the wire was not planar. 
1552 * *CurveProjectionFailed* - no curve was found  in the parametric space of the surface for an edge. 
1553 * *ParametersOutOfRange* - the parameters  umin,umax,vmin,vmax are out of the surface. 
1554
1555 @subsubsection occt_modalg_3_1_6 Wire
1556 The wire is a composite shape built not from a geometry, but by the assembly of edges. *BRepBuilderAPI_MakeWire* class can build a wire from one or more edges or connect new edges to an  existing wire. 
1557
1558 Up to four edges can be used directly, for example: 
1559
1560 ~~~~~
1561 TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3,E4); 
1562 ~~~~~
1563
1564 For a higher or unknown  number of edges the Add method must be used; for example, to build a wire from  an array of shapes (to be edges). 
1565
1566 ~~~~~
1567 TopTools_Array1OfShapes theEdges; 
1568 BRepBuilderAPI_MakeWire MW; 
1569 for (Standard_Integer i = theEdge.Lower(); 
1570 i <= theEdges.Upper(); i++) 
1571 MW.Add(TopoDS::Edge(theEdges(i)); 
1572 TopoDS_Wire W = MW; 
1573 ~~~~~
1574
1575 The class can be  constructed with a wire. A wire can also be added. In this case, all the edges  of the wires are added. For example to merge two wires: 
1576
1577 ~~~~~
1578 #include <TopoDS_Wire.hxx> 
1579 #include <BRepBuilderAPI_MakeWire.hxx> 
1580
1581 TopoDS_Wire MergeWires (const TopoDS_Wire&amp; W1, 
1582 const  TopoDS_Wire&amp; W2) 
1583
1584 BRepBuilderAPI_MakeWire MW(W1); 
1585 MW.Add(W2); 
1586 return MW; 
1587
1588 ~~~~~
1589
1590 *BRepBuilderAPI_MakeWire* class connects the edges to the wire. When a new edge  is added if one of its vertices is shared with the wire it is considered as  connected to the wire. If there is no shared vertex, the algorithm searches for  a vertex of the edge and a vertex of the wire, which are at the same location (the  tolerances of the vertices are used to test if they have the same location). If  such a pair of vertices is found, the edge is copied with the vertex of the  wire in place of the original vertex. All the vertices of the edge can be  exchanged for vertices from the wire. If no connection is found the wire is  considered to be disconnected. This is an error. 
1591
1592 BRepBuilderAPI_MakeWire class can return the last edge added to the wire (Edge  method). This edge can be different from the original edge if it was copied. 
1593
1594 The Error method returns  a term of the *BRepBuilderAPI_WireError* enumeration: 
1595 *WireDone* - no  error occurred. 
1596 *EmptyWire* - no  initialization of the algorithm, an empty constructor was used. 
1597 *DisconnectedWire* - the last added edge was not connected to the wire. 
1598 *NonManifoldWire* - the  wire with some singularity. 
1599
1600 @subsubsection occt_modalg_3_1_7 Shell
1601 The shell is a composite shape built not from a geometry, but by the assembly of faces.
1602 Use *BRepBuilderAPI_MakeShell* class  to build a Shell from a set of Faces. What may be important is that each face  should have the required continuity. That is why an initial surface is broken  up into faces. 
1603
1604 @subsubsection occt_modalg_3_1_8 Solid
1605 The solid is a composite shape built not from a geometry, but by the assembly of shells. Use  *BRepBuilderAPI_MakeSolid* class  to build a Solid from a set of Shells. Its use is similar to the use of the  MakeWire class: shells are added to the solid in the same way that edges are  added to the wire in MakeWire. 
1606
1607
1608 @subsubsection occt_modalg_3_2 Modification Operators
1609
1610 @subsubsection occt_modalg_3_2_1 Transformation
1611 *BRepBuilderAPI_Transform* class can be used to apply a transformation to a shape (see class  *gp_Trsf*). The methods have a boolean argument to copy or share the  original shape, as long as the transformation allows (it is only possible for  direct isometric transformations). By default, the original shape is shared. 
1612
1613 The following example  deals with the rotation of shapes. 
1614
1615 ~~~~~
1616
1617 TopoDS_Shape myShape1 = ...; 
1618 // The original shape 1 
1619 TopoDS_Shape myShape2 = ...; 
1620 // The original shape2 
1621 gp_Trsf T; 
1622 T.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.),gp_Vec(0.,0.,1.)), 
1623 2.*PI/5.); 
1624 BRepBuilderAPI_Transformation theTrsf(T); 
1625 theTrsf.Perform(myShape1); 
1626 TopoDS_Shape myNewShape1 = theTrsf.Shape() 
1627 theTrsf.Perform(myShape2,Standard_True); 
1628 // Here duplication is forced 
1629 TopoDS_Shape myNewShape2 = theTrsf.Shape() 
1630 ~~~~~
1631
1632 @subsubsection occt_modalg_3_2_2 Duplication
1633
1634 Use the  BRepBuilderAPI_Copy class to duplicate a shape. A new shape is thus created. 
1635 In the following example, a  solid is copied: 
1636
1637 ~~~~~
1638 TopoDS Solid MySolid; 
1639 ....// Creates a solid 
1640
1641 TopoDS_Solid myCopy = BRepBuilderAPI_Copy(mySolid); 
1642 ~~~~~
1643
1644 @section occt_modalg_4 Construction of  Primitives
1645 @subsection occt_modalg_4_1 Making  Primitives
1646 @subsubsection occt_modalg_4_1_1 Box
1647
1648 BRepPrimAPI_MakeBox class allows building a parallelepiped box. The result is either a Shell or a Solid. There are  four ways to build a box: 
1649
1650 * From three dimensions  dx,dy,dz. The box is parallel to the axes and extends for [0,dx] [0,dy] [0,dz]. 
1651 * From a point and three  dimensions. The same as above but the point is the new origin. 
1652 * From two points, the box  is parallel to the axes and extends on the intervals defined by the coordinates  of the two points. 
1653 * From a system of axes  (gp_Ax2) and three dimensions. Same as the first way but the box is parallel to the given system of axes. 
1654
1655 An error is raised if  the box is flat in any dimension using the default precision. The following  code shows how to create a box: 
1656 ~~~~~
1657 TopoDS_Solid theBox = BRepPrimAPI_MakeBox(10.,20.,30.); 
1658 ~~~~~
1659
1660 The four methods to build a box are shown in the figure: 
1661
1662 ![](/user_guides/modeling_algos/images/modeling_algos_image026.jpg  "Making Boxes")
1663
1664 @subsubsection occt_modalg_4_1_2 Wedge
1665 BRepPrimAPI_MakeWedge class allows building a wedge, which is a slanted box, i.e. a  box with angles. The wedge is constructed in much the same way as a box i.e.  from three dimensions dx,dy,dz plus arguments or from an axis system, three  dimensions, and arguments. 
1666
1667 The following figure  shows two ways to build wedges. One is to add an ltx dimension, which is the  length in x of the face at dy. The second is to add xmin, xmax, zmin, zmax to  describe the face at dy. 
1668
1669 The first method is a  particular case of the second with xmin = 0, xmax = ltx, zmin = 0, zmax = dz. 
1670 To make a centered  pyramid you can use xmin = xmax = dx / 2, zmin = zmax = dz / 2. 
1671
1672 ![](/user_guides/modeling_algos/images/modeling_algos_image027.jpg "Making Wedges")
1673
1674 @subsubsection occt_modalg_4_1_3 Rotation object
1675 BRepPrimAPI_MakeOneAxis is a deferred class used as a root class for all classes constructing rotational primitives. Rotational primitives are  created by rotating a curve around an axis. They cover the cylinder, the cone,  the sphere, the torus, and the revolution, which provides all other curves. 
1676
1677 The particular  constructions of these primitives are described, but they all have some common  arguments, which are: 
1678
1679   * A system of coordinates,  where the Z axis is the rotation axis..
1680   * An angle in the range  [0,2*PI].
1681   * A vmin, vmax parameter range  on the curve.
1682
1683 The result of the  OneAxis construction is a Solid, a Shell, or a Face. The face is the face  covering the rotational surface. Remember that you will not use the OneAxis  directly but one of the derived classes, which provide improved constructions.  The following figure illustrates the OneAxis arguments. 
1684
1685 ![](/user_guides/modeling_algos/images/modeling_algos_image028.jpg  "MakeOneAxis  arguments")
1686
1687 @subsubsection occt_modalg_4_1_4 Cylinder
1688 BRepPrimAPI_MakeCylinder class allows creating cylindrical primitives. A cylinder is created either in the  default coordinate system or in a given coordinate system (gp_Ax2). There are  two constructions: 
1689
1690   * Radius and height, to build a  full cylinder.
1691   * Radius, height and angle to  build a portion of a cylinder.
1692
1693 The following code  builds the cylindrical face of the figure, which is a quarter of cylinder along  the Y axis with the origin at X,Y,Z, a length of DY, and a radius R. 
1694
1695 ~~~~~
1696
1697 Standard_Real X = 20, Y = 10, Z = 15, R = 10, DY = 30; 
1698 // Make the system of coordinates 
1699 gp_Ax2 axes = gp::ZOX(); 
1700 axes.Translate(gp_Vec(X,Y,Z)); 
1701 TopoDS_Face F = 
1702 BRepPrimAPI_MakeCylinder(axes,R,DY,PI/2.); 
1703 ~~~~~
1704 ![](/user_guides/modeling_algos/images/modeling_algos_image029.jpg  "Cylinder")
1705
1706 @subsubsection occt_modalg_4_1_5 Cone
1707 BRepPrimAPI_MakeCone  class allows creating conical primitives. Like a cylinder, a cone is created either in  the default coordinate system or in a given coordinate system (gp_Ax2). There  are two constructions: 
1708
1709   * Two radii and height, to  build a full cone. One of the radii can be null to make a sharp cone.
1710   * Radii, height and angle to  build a truncated cone.
1711
1712 The following code  builds the solid cone of the figure, which is located in the default system  with radii R1 and R2 and height H. 
1713
1714 ~~~~~
1715 Standard_Real R1 = 30, R2 = 10, H = 15; 
1716 TopoDS_Solid S = BRepPrimAPI_MakeCone(R1,R2,H); 
1717 ~~~~~
1718
1719 ![](/user_guides/modeling_algos/images/modeling_algos_image030.jpg "Cone")
1720
1721 @subsubsection occt_modalg_4_1_6 Sphere
1722 BRepPrimAPI_MakeSphere class allows creating spherical primitives. Like a cylinder, a  sphere is created either in the default coordinate system or in a given  coordinate system (gp_Ax2). There are four constructions: 
1723
1724   * From a radius - builds a full  sphere. 
1725   * From a radius and an angle - builds  a lune (digon).
1726   * From a radius and two angles - builds a wraparound spherical segment between two latitudes. The angles a1, a2 must follow the relation: PI/2 <= a1 < a2 <= PI/2. 
1727   * From a radius and three angles - a combination of two previous methods builds a portion of spherical segment. 
1728
1729 The following code  builds four spheres from a radius and three angles. 
1730
1731 ~~~~~
1732 Standard_Real R = 30, ang = 
1733         PI/2, a1 = -PI/2.3,  a2 = PI/4; 
1734 TopoDS_Solid S1 = BRepPrimAPI_MakeSphere(R); 
1735 TopoDS_Solid S2 = BRepPrimAPI_MakeSphere(R,ang); 
1736 TopoDS_Solid S3 = BRepPrimAPI_MakeSphere(R,a1,a2); 
1737 TopoDS_Solid S4 = BRepPrimAPI_MakeSphere(R,a1,a2,ang); 
1738 ~~~~~
1739
1740 Note that we could  equally well choose to create Shells instead of Solids. 
1741
1742 ![](/user_guides/modeling_algos/images/modeling_algos_image031.jpg  "Examples of  Spheres")
1743
1744
1745 @subsubsection occt_modalg_4_1_7 Torus
1746 BRepPrimAPI_MakeTorus class allows creating toroidal primitives. Like the other  primitives, a torus is created either in the default coordinate system or in a  given coordinate system (gp_Ax2). There are four constructions similar to the  sphere constructions: 
1747
1748   * Two radii - builds a full  torus.
1749   * Two radii and an angle - builds  an angular torus segment.
1750   * Two radii and two angles -  builds a wraparound torus segment between two radial planes. The angles a1, a2 must follow  the relation 0 < a2 - a1 < 2*PI. 
1751   * Two radii and three angles - a combination of two previous methods builds a portion of torus segment.
1752
1753 ![](/user_guides/modeling_algos/images/modeling_algos_image032.gif "Examples of Tori")
1754
1755 The following code  builds four toroidal shells from two radii and three angles. 
1756
1757 ~~~~~
1758 Standard_Real R1 = 30, R2 = 10, ang = PI, a1 = 0, 
1759         a2 = PI/2; 
1760 TopoDS_Shell S1 = BRepPrimAPI_MakeTorus(R1,R2); 
1761 TopoDS_Shell S2 = BRepPrimAPI_MakeTorus(R1,R2,ang); 
1762 TopoDS_Shell S3 = BRepPrimAPI_MakeTorus(R1,R2,a1,a2); 
1763 TopoDS_Shell S4 = 
1764         BRepPrimAPI_MakeTorus(R1,R2,a1,a2,ang); 
1765 ~~~~~
1766
1767 Note that we could  equally well choose to create Solids instead of Shells. 
1768
1769 @subsubsection occt_modalg_4_1_8 Revolution
1770 BRepPrimAPI_MakeRevolution class allows building a uniaxial primitive from a curve. As other uniaxial primitives it can be created in the default coordinate system  or in a given coordinate system. 
1771
1772 The curve can be any  *Geom_Curve*, provided it is planar and lies in the same plane as the Z-axis of  local coordinate system. There are four modes of construction: 
1773
1774   * From a curve, use the full  curve and make a full rotation.
1775   * From a curve and an angle of  rotation.
1776   * From a curve and two  parameters to trim the curve. The two parameters must be growing and within the  curve range.
1777   * From a curve, two parameters,  and an angle. The two parameters must be growing and within the curve range.
1778
1779
1780 @subsection occt_modalg_4_2 Sweeping:  Prism, Revolution and Pipe
1781 @subsubsection occt_modalg_4_2_1 Sweeping
1782
1783 Sweeps are the objects  you obtain by sweeping a **profile** along a **path**. The profile can be of any topology. The path is usually a curve or a wire. The profile generates  objects according to the following rules: 
1784
1785   * Vertices generate Edges
1786   * Edges generate Faces.
1787   * Wires generate Shells.
1788   * Faces generate Solids.
1789   * Shells generate Composite Solids
1790
1791 It is forbidden to sweep  Solids and Composite Solids. A Compound generates a Compound with the sweep of  all its elements. 
1792
1793 ![](/user_guides/modeling_algos/images/modeling_algos_image033.jpg "Generating a  sweep")
1794
1795 *BRepPrimAPI_MakeSweep class* is a deferred class used as a root of the the following sweep classes:
1796 * *BRepPrimAPI_MakePrism* - produces a linear sweep
1797 * *BRepPrimAPI_MakeRevol* - produces a rotational sweep
1798 * *BRepPrimAPI_MakePipe* - produces a general sweep. 
1799
1800
1801 @subsubsection occt_modalg_4_2_2 Prism
1802 BRepPrimAPI_MakePrism class allows creating a linear **prism** from a shape and a vector or a direction. 
1803 * A vector allows creating a finite  prism;
1804 * A direction allows creating an infinite or semi-infinite prism. The semi-infinite or infinite  prism is toggled by a Boolean argument. All constructors have a boolean argument to copy the original  shape or share it (by default). 
1805 The following code creates a finite, an infinite and a semi-infinite solid using a face, a  direction and a length
1806
1807 ~~~~~
1808 TopoDS_Face F = ..; // The swept face 
1809 gp_Dir direc(0,0,1); 
1810 Standard_Real l = 10; 
1811 // create a vector from the direction and the length 
1812 gp_Vec v = direc; 
1813 v *= l; 
1814 TopoDS_Solid P1 = BRepPrimAPI_MakePrism(F,v); 
1815 // finite 
1816 TopoDS_Solid P2 = BRepPrimAPI_MakePrism(F,direc); 
1817 // infinite 
1818 TopoDS_Solid P3 =  BRepPrimAPI_MakePrism(F,direc,Standard_False); 
1819 // semi-infinite 
1820 ~~~~~
1821
1822 ![](/user_guides/modeling_algos/images/modeling_algos_image034.jpg   "Finite, infinite, and semi-infinite prisms")
1823
1824 @subsubsection occt_modalg_4_2_3 Rotation
1825 BRepPrimAPI_MakeRevol class allows creating a rotational sweep from a shape, an axis  (gp_Ax1), and an angle. The angle has a default value of 2*PI which means a  closed revolution. 
1826
1827 BRepPrimAPI_MakeRevol constructors  have a last argument to copy or share the original shape. The following code creates a a full and a partial rotation using a face, an axis and an angle.
1828
1829 ~~~~~
1830 TopoDS_Face F = ...; // the profile 
1831 gp_Ax1 axis(gp_Pnt(0,0,0),gp_Dir(0,0,1)); 
1832 Standard_Real ang = PI/3; 
1833 TopoDS_Solid R1 = BRepPrimAPI_MakeRevol(F,axis); 
1834 // Full revol 
1835 TopoDS_Solid R2 = BRepPrimAPI_MakeRevol(F,axis,ang); 
1836 ~~~~~
1837
1838 ![](/user_guides/modeling_algos/images/modeling_algos_image035.jpg "Full and partial  rotation")
1839
1840 @section occt_modalg_5 Boolean  Operations
1841
1842 Boolean operations are  used to create new shapes from the combinations of two shapes. 
1843 |Fuse   |  all points in S1 or S2  |
1844 |Common |  all points in S1 and S2 |
1845 |Cut S1 by S2| all points in S1 and not in S2 | 
1846
1847 BRepAlgoAPI_BooleanOperation class is the deferred root class for Boolean  operations.
1848
1849 ![](/user_guides/modeling_algos/images/modeling_algos_image036.jpg  "Boolean Operations")
1850
1851 @subsection occt_modalg_5_1 Fuse
1852
1853 BRepAlgoAPI_Fuse performs the Fuse operation. 
1854 ~~~~~
1855 TopoDS_Shape A = ..., B = ...; 
1856 TopoDS_Shape S = BRepAlgoAPI_Fuse(A,B); 
1857 ~~~~~
1858
1859 @subsection occt_modalg_5_2 Common
1860 BRepAlgoAPI_Common  performs the Common operation. 
1861
1862 ~~~~~
1863 TopoDS_Shape A = ..., B = ...; 
1864 TopoDS_Shape S = BRepAlgoAPI_Common(A,B); 
1865 ~~~~~
1866
1867 @subsection occt_modalg_5_3 Cut
1868 BRepAlgoAPI_Cut performs the Cut operation. 
1869
1870 ~~~~~
1871 TopoDS_Shape A = ..., B = ...; 
1872 TopoDS_Shape S = BRepAlgoAPI_Cut(A,B); 
1873 ~~~~~
1874
1875 @subsection occt_modalg_5_4 Section
1876
1877 BRepAlgoAPI_Section performs the section, described as a *TopoDS_Compound* made of *TopoDS_Edge*. 
1878
1879 ![](/user_guides/modeling_algos/images/modeling_algos_image037.jpg "Section  operation")
1880
1881 ~~~~~
1882 TopoDS_Shape A = ...,  TopoDS_ShapeB = ...; 
1883 TopoDS_Shape S =  BRepAlgoAPI_Section(A,B); 
1884 ~~~~~
1885
1886 @section occt_modalg_6 Fillets and  Chamfers
1887 @subsection occt_modalg_6_1 Fillets  
1888 @subsection occt_modalg_6_1_1 Fillet on shape
1889
1890 A fillet is a smooth  face replacing a sharp edge.
1891
1892 *BRepFilletAPI_MakeFillet* class allows filleting a shape.  
1893
1894 To produce a fillet, it is necessary to define the filleted shape at the construction of the class and  add fillet  descriptions using the *Add* method.
1895 A fillet description contains an edge and a  radius. The edge must be shared by two faces. The fillet is automatically extended to all edges in a smooth continuity with the original  edge. 
1896 It is not an error to Add a fillet twice,  the last description holds. 
1897
1898 ![](/user_guides/modeling_algos/images/modeling_algos_image038.jpg "Filleting two edges using radii r1 and  r2.")
1899
1900 In the following example  a filleted box with dimensions a,b,c and radius r is created. 
1901
1902 Constant  radius 
1903 ----------------
1904
1905 ~~~~~
1906 #include <TopoDS_Shape.hxx> 
1907 #include <TopoDS.hxx> 
1908 #include <BRepPrimAPI_MakeBox.hxx> 
1909 #include <TopoDS_Solid.hxx> 
1910 #include <BRepFilletAPI_MakeFillet.hxx> 
1911 #include <TopExp_Explorer.hxx> 
1912
1913 TopoDS_Shape FilletedBox(const Standard_Real a, 
1914                                                 const Standard_Real  b, 
1915                                                 const Standard_Real  c, 
1916                                                 const Standard_Real  r) 
1917
1918         TopoDS_Solid Box =  BRepPrimAPI_MakeBox(a,b,c); 
1919         BRepFilletAPI_MakeFillet  MF(Box); 
1920
1921         // add all the edges  to fillet 
1922         TopExp_Explorer  ex(Box,TopAbs_EDGE); 
1923         while (ex.More()) 
1924         { 
1925         MF.Add(r,TopoDS::Edge(ex.Current())); 
1926         ex.Next(); 
1927         } 
1928         return MF.Shape(); 
1929         } 
1930 ~~~~~
1931
1932 ![](/user_guides/modeling_algos/images/modeling_algos_image039.jpg "Fillet with constant radius")
1933
1934 Changing radius
1935 ---------------
1936
1937 ~~~~~
1938 void CSampleTopologicalOperationsDoc::OnEvolvedblend1() 
1939
1940         TopoDS_Shape theBox  = BRepPrimAPI_MakeBox(200,200,200); 
1941
1942         BRepFilletAPI_MakeFillet  Rake(theBox); 
1943         ChFi3d_FilletShape  FSh = ChFi3d_Rational; 
1944         Rake.SetFilletShape(FSh); 
1945
1946         TColgp_Array1OfPnt2d  ParAndRad(1, 6); 
1947         ParAndRad(1).SetCoord(0.,  10.); 
1948         ParAndRad(1).SetCoord(50.,  20.); 
1949         ParAndRad(1).SetCoord(70.,  20.); 
1950         ParAndRad(1).SetCoord(130.,  60.); 
1951         ParAndRad(1).SetCoord(160.,  30.); 
1952         ParAndRad(1).SetCoord(200.,  20.); 
1953
1954         TopExp_Explorer  ex(theBox,TopAbs_EDGE); 
1955         Rake.Add(ParAndRad, TopoDS::Edge(ex.Current())); 
1956         TopoDS_Shape  evolvedBox = Rake.Shape(); 
1957
1958 ~~~~~
1959
1960 ![](/user_guides/modeling_algos/images/modeling_algos_image040.jpg      "Fillet with changing radius")
1961  
1962 @subsection occt_modalg_6_1_2 Chamfer
1963
1964 A chamfer is a rectilinear edge  replacing a sharp vertex of the face.
1965
1966 The use of *BRepFilletAPI_MakeChamfer* class is similar to the use of  *BRepFilletAPI_MakeFillet*, except for the following: 
1967
1968 *The surfaces created are  ruled and not smooth. 
1969 *The *Add* syntax for  selecting edges requires one or two distances, one edge and one face  (contiguous to the edge):
1970
1971 ~~~~~ 
1972 Add(dist,  E, F) 
1973 Add(d1,  d2, E, F) with d1 on the face F. 
1974 ~~~~~
1975
1976 ![](/user_guides/modeling_algos/images/modeling_algos_image041.jpg      "Chamfer")
1977
1978 @subsection occt_modalg_6_1_3 Fillet on a planar face
1979
1980 BRepFilletAPI_MakeFillet2d class allows constructing fillets and chamfers on planar faces. 
1981 To create a fillet on planar face: define it, indicate, which vertex is  to be deleted, and give the fillet radius with *AddFillet* method. 
1982 A chamfer can be calculated with *AddChamfer* method. It can be  described by 
1983   * two edges and two distances
1984   * one edge, one vertex, one  distance and one angle.
1985 Fillets and chamfers are calculated when addition is  complete. 
1986
1987 If face F2 is created by 2D fillet and chamfer builder from face F1, the builder can be rebuilt (the  builder recovers the status it had before deletion). To do so, use the  following syntax: 
1988 ~~~~~
1989 BRepFilletAPI_MakeFillet2d builder; 
1990 builder.Init(F1,F2); 
1991 ~~~~~
1992
1993 Planar Fillet
1994 -------------
1995
1996 ~~~~~
1997 #include “BRepPrimAPI_MakeBox.hxx” 
1998 #include “TopoDS_Shape.hxx” 
1999 #include “TopExp_Explorer.hxx” 
2000 #include “BRepFilletAPI_MakeFillet2d.hxx” 
2001 #include “TopoDS.hxx” 
2002 #include “TopoDS_Solid.hxx” 
2003
2004 TopoDS_Shape FilletFace(const Standard_Real a, 
2005                                                 const Standard_Real  b, 
2006                                                 const Standard_Real c, 
2007                                                 const Standard_Real  r) 
2008
2009
2010         TopoDS_Solid Box =  BRepPrimAPI_MakeBox (a,b,c); 
2011         TopExp_Explorer  ex1(Box,TopAbs_FACE); 
2012
2013         const  TopoDS_Face&amp; F = TopoDS::Face(ex1.Current()); 
2014         BRepFilletAPI_MakeFillet2d  MF(F); 
2015         TopExp_Explorer  ex2(F, TopAbs_VERTEX); 
2016         while (ex2.More()) 
2017         { 
2018         MF.AddFillet(TopoDS::Vertex(ex2.Current()),r); 
2019         ex2.Next(); 
2020         } 
2021         // while... 
2022         return MF.Shape(); 
2023
2024 ~~~~~
2025
2026 @section occt_modalg_7 Offsets, Drafts, Pipes and Evolved shapes
2027 @subsection occt_modalg_7_1 Shelling 
2028
2029 Shelling is used to offset given faces of a solid by a specific value. It rounds or intersects adjacent faces along its edges depending on the convexity of the edge. 
2030
2031 The constructor *BRepOffsetAPI_MakeThickSolid* shelling operator takes the solid, the list of faces to remove and an offset value as input.
2032
2033 ~~~~~
2034 TopoDS_Solid SolidInitial = ...;
2035
2036 Standard_Real                   Of              = ...;
2037 TopTools_ListOfShape    LCF;
2038 TopoDS_Shape                    Result;
2039 Standard_Real                   Tol = Precision::Confusion();
2040
2041 for (Standard_Integer i = 1 ;i <= n; i++) {
2042         TopoDS_Face SF = ...; // a face from SolidInitial
2043         LCF.Append(SF);
2044 }
2045
2046 Result = BRepOffsetAPI_MakeThickSolid   (SolidInitial,
2047                                                                                 LCF,
2048                                                                                 Of,
2049                                                                                 Tol);
2050 ~~~~~
2051
2052 ![](/user_guides/modeling_algos/images/modeling_algos_image042.jpg      "Shelling")
2053
2054
2055 @subsection occt_modalg_7_2  Draft Angle
2056
2057 *BRepOffsetAPI_DraftAngle* class allows modifying a shape by applying draft angles to its planar, cylindrical and conical faces. 
2058 The class is created or  initialized from a shape, then faces to be modified are added; for each face,  three arguments are used: 
2059
2060   * Direction: the direction with  which the draft angle is measured
2061   * Angle: value of the angle
2062   * Neutral plane: intersection  between the face and the neutral plane is invariant.
2063
2064 The following code  places a draft angle on several faces of a shape; the same direction, angle and  neutral plane are used for each face: 
2065
2066 ~~~~~
2067 TopoDS_Shape myShape = ... 
2068 // The original shape 
2069 TopTools_ListOfShape ListOfFace; 
2070 // Creation of the list of faces to be modified 
2071 ... 
2072
2073 gp_Dir Direc(0.,0.,1.); 
2074 // Z direction 
2075 Standard_Real Angle = 5.*PI/180.; 
2076 // 5 degree angle 
2077 gp_Pln Neutral(gp_Pnt(0.,0.,5.), Direc); 
2078 // Neutral plane Z=5 
2079 BRepOffsetAPI_DraftAngle theDraft(myShape); 
2080 TopTools_ListIteratorOfListOfShape itl; 
2081 for (itl.Initialize(ListOfFace); itl.More(); itl.Next())  { 
2082         theDraft.Add(TopoDS::Face(itl.Value()),Direc,Angle,Neutral); 
2083         if  (!theDraft.AddDone()) { 
2084                 // An error has occurred. The faulty face is given by //  ProblematicShape 
2085                 break; 
2086                 } 
2087
2088 if (!theDraft.AddDone()) { 
2089         // An error has  occurred 
2090         TopoDS_Face guilty =  theDraft.ProblematicShape(); 
2091         ... 
2092
2093 theDraft.Build(); 
2094 if (!theDraft.IsDone()) { 
2095         // Problem  encountered during reconstruction 
2096         ... 
2097
2098 else { 
2099         TopoDS_Shape  myResult = theDraft.Shape(); 
2100         ... 
2101
2102 ~~~~~
2103
2104 ![](/user_guides/modeling_algos/images/modeling_algos_image043.jpg  "DraftAngle")
2105
2106 @subsection occt_modalg_7_3 Pipe  Constructor
2107
2108 *BRepOffsetAPI_MakePipe* class allows creating a pipe from a Spine,  which is a Wire and a Profile which is a Shape. This implementation is limited  to spines with smooth transitions, sharp transitions are precessed by  *BRepOffsetAPI_MakePipeShell*. To be more precise the continuity must be G1,  which means that the tangent must have the same direction, though not necessarily the same magnitude, at neighboring edges. 
2109 The angle between the spine and the profile is preserved throughout the pipe. 
2110
2111 ~~~~~
2112 TopoDS_Wire Spine = ...; 
2113 TopoDS_Shape Profile = ...; 
2114 TopoDS_Shape Pipe =  BRepOffsetAPI_MakePipe(Spine,Profile); 
2115 ~~~~~
2116
2117 ![](/user_guides/modeling_algos/images/modeling_algos_image044.jpg "Example of a Pipe")
2118
2119 @subsection occt_modalg_7_4 Evolved Solid
2120
2121 *BRepOffsetAPI_MakeEvolved* class allows creating an evolved solid from a Spine (planar face or wire) and a profile (wire). 
2122 The evolved solid is an unlooped sweep generated by the spine and the profile. 
2123 The evolved solid is  created by sweeping the profile’s reference axes on the spine. The origin of  the axes moves to the spine, the X axis and the local tangent coincide and the  Z axis is normal to the face. 
2124
2125 The reference axes of  the profile can be defined following two distinct modes: 
2126
2127 * The reference axes of the  profile are the origin axes. 
2128 * The references axes of  the profile are calculated as follows: 
2129   + the origin is given by the  point on the spine which is the closest to the profile
2130   + the X axis is given by the  tangent to the spine at the point defined above
2131   + the Z axis is the normal to  the plane which contains the spine.
2132
2133 ~~~~~
2134 TopoDS_Face Spine = ...; 
2135 TopoDS_Wire Profile = ...; 
2136 TopoDS_Shape Evol = 
2137 BRepOffsetAPI_MakeEvolved(Spine,Profile); 
2138 ~~~~~
2139
2140 @section occt_modalg_8 Sewing operators
2141 @subsection occt_modalg_8_1 Sewing
2142
2143 *BRepOffsetAPI_Sewing*  class allows sewing TopoDS Shapes together along their common edges. The edges  can be partially shared as in the following example. 
2144
2145 ![](/user_guides/modeling_algos/images/modeling_algos_image045.jpg "Shapes with partially shared edges")
2146
2147 The constructor takes as  arguments the tolerance (default value is 10-6) and a flag, which is used to mark the  degenerate shapes. 
2148 The following methods are used in this class:
2149 * *Add* adds shapes, as it is needed; 
2150 * *Perform* forces calculation of the sewed shape. 
2151 * *SewedShape* returns the result. 
2152 Additional methods can  be used to give information on the number of free boundaries, multiple edges and degenerate shapes. 
2153
2154 @subsection occt_modalg_8_2 Find Contiguous Edges
2155 *BRepOffsetAPI_FindContiguousEdges* class is used to find edges, which coincide  among a set of shapes within the given tolerance; these edges can be analyzed  for tangency, continuity (C1, G2, etc.)... 
2156
2157 The constructor takes as  arguments the tolerance defining the edge proximity (10-6 by default) and a flag used to mark degenerated  shapes. 
2158 The following methods are used in this class: 
2159 * *Add* adds shapes, which are to be analyzed; 
2160 * *NbEdges* returns the total number of edges; 
2161 * *NbContiguousEdges* returns the number of contiguous edges within the given tolerance as defined above; 
2162 * *ContiguousEdge* takes an edge number as an argument and returns the *TopoDS* edge  contiguous to another edge; 
2163 * *ContiguousEdgeCouple*  gives all edges or sections, which are common to the  edge with the number given above. 
2164 * *SectionToBoundary*  finds the original edge on the original shape from the  section. 
2165
2166 @section occt_modalg_9 Features
2167
2168 @subsection occt_modalg_9_1 The  BRepFeat Classes and their use
2169 BRepFeat package is  used to manipulate extensions of the classical boundary representation of  shapes closer to features. In that sense, BRepFeat is an extension of BRepBuilderAPI  package. 
2170
2171 @subsubsection occt_modalg_9_1_1 Form classes
2172 The Form from BRepFeat  class is a deferred class used as a root for form features. It inherits  MakeShape from BRepBuilderAPI and provides implementation of methods keep track of all sub-shapes. 
2173
2174 MakePrism
2175 ---------
2176 MakePrism from  BRepFeat class is used to build a prism interacting with a shape. It is created  or initialized from 
2177   * a shape (the basic shape),
2178   * the base of the prism,
2179   * a face (the face of sketch on  which the base has been defined and used to determine whether the base has been  defined on the basic shape or not),
2180   * a direction,
2181   * a Boolean indicating the type  of operation (fusion=protrusion or cut=depression) on the basic shape,
2182   * another Boolean indicating if  the self-intersections have to be found (not used in every case).
2183
2184 There are six Perform  methods: 
2185
2186 |Perform(Height)       | The  resulting prism is of the given length. |
2187 |Perform(Until)        | The  prism is defined between the position of the base and the given face. |
2188 |Perform(From, Until)  | The  prism is defined between the two faces From and Until. |
2189 |PerformUntilEnd()     | The  prism is semi-infinite, limited by the actual position of the base. |
2190 |PerformFromEnd(Until) | The  prism is semi-infinite, limited by the face Until. |
2191 | PerformThruAll()     | The  prism is infinite. In the case of a depression, the result is similar to a cut  with an infinite prism. In the case of a protrusion, infinite parts are not  kept in the result. |
2192
2193 **Note** *Add* method can be used before *Perform* methods to indicate that a face  generated by an edge slides onto a face of the base shape.
2194
2195 In the following  sequence, a protrusion is performed, i.e. a face of the shape is changed into a  prism. 
2196
2197 ~~~~~
2198 TopoDS_Shape Sbase = ...;  // an initial shape 
2199 TopoDS_Face Fbase = ....; // a base of prism 
2200
2201 gp_Dir Extrusion (.,.,.); 
2202
2203 // An empty face is given as the sketch face 
2204
2205 BRepFeat_MakePrism thePrism(Sbase, Fbase, TopoDS_Face(),  Extrusion, Standard_True, Standard_True); 
2206
2207 thePrism, Perform(100.); 
2208 if (thePrism.IsDone()) { 
2209         TopoDS_Shape  theResult = thePrism; 
2210         ... 
2211
2212 ~~~~~
2213
2214 ![](/user_guides/modeling_algos/images/modeling_algos_image047.jpg  "Fusion with MakePrism")
2215
2216 ![](/user_guides/modeling_algos/images/modeling_algos_image048.jpg  "Creating a  prism between two faces with Perform(From, Until)")
2217
2218 MakeDPrism
2219 ----------
2220 MakeDPrism from  BRepFeat class is used to build draft prism topologies interacting with a basis  shape . These can be depressions or protrusions. A class object is created or  initialized from 
2221   * a shape (basic shape),
2222   * the base of the prism,
2223   * a face (face of sketch on  which the base has been defined and used to determine whether the base has been  defined on the basic shape or not),
2224   * an angle,
2225   * a Boolean indicating the type  of operation (fusion=protrusion or cut=depression) on the basic shape,
2226   * another Boolean indicating if  self-intersections have to be found (not used in every case).
2227   
2228 Evidently the input data  for MakeDPrism are the same as for MakePrism except for a new parameter Angle  and a missing parameter Direction: the direction of the prism generation is  determined automatically as the normal to the base of the prism. 
2229 The semantics of draft  prism feature creation is based on the construction of shapes: 
2230   * along a length
2231   * up to a limiting face
2232   * from a limiting face to a  height.
2233
2234 The shape defining  construction of the draft prism feature can be either the supporting edge or the concerned area of a face. 
2235
2236 In case of the  supporting edge, this contour can be attached to a face of the basis shape by  binding. When the contour is bound to this face, the information that the  contour will slide on the face becomes available to the relevant class methods. 
2237 In case of the  concerned area of a face, it is possible to cut it out and move it to a  different height, which will define the limiting face of a protrusion or depression direction . 
2238
2239 The *Perform* methods are the same as for *MakePrism*. 
2240
2241 ~~~~~
2242 TopoDS_Shape S = BRepPrimAPI_MakeBox(400.,250.,300.); 
2243 TopExp_Explorer Ex; 
2244 Ex.Init(S,TopAbs_FACE); 
2245 Ex.Next(); 
2246 Ex.Next(); 
2247 Ex.Next(); 
2248 Ex.Next(); 
2249 Ex.Next(); 
2250 TopoDS_Face F = TopoDS::Face(Ex.Current()); 
2251 Handle(Geom_Surface) surf = BRep_Tool::Surface(F); 
2252 gp_Circ2d 
2253 c(gp_Ax2d(gp_Pnt2d(200.,130.),gp_Dir2d(1.,0.)),50.); 
2254 BRepBuilderAPI_MakeWire MW; 
2255 Handle(Geom2d_Curve) aline = new Geom2d_Circle(c); 
2256 MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,PI)); 
2257 MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,PI,2.*PI)); 
2258 BRepBuilderAPI_MakeFace MKF; 
2259 MKF.Init(surf,Standard_False); 
2260 MKF.Add(MW.Wire()); 
2261 TopoDS_Face FP = MKF.Face(); 
2262 BRepLib::BuildCurves3d(FP); 
2263 BRepFeat_MakeDPrism MKDP (S,FP,F,10*PI180,Standard_True, 
2264                                                         Standard_True); 
2265 MKDP.Perform(200); 
2266 TopoDS_Shape res1 = MKDP.Shape(); 
2267 ~~~~~
2268
2269 ![](/user_guides/modeling_algos/images/modeling_algos_image049.jpg  "A tapered prism")
2270
2271 MakeRevol
2272 ---------
2273 The MakeRevol from  BRepFeat class is used to build a revolution interacting with a 
2274 shape. It is created or initialized from 
2275
2276   * a shape (the basic shape,)
2277   * the base of the revolution,
2278   * a face (the face of sketch on  which the base has been defined and used to determine whether the base has been  defined on the basic shape or not),
2279   * an axis of revolution,
2280   * a boolean indicating the type  of operation (fusion=protrusion or cut=depression) on the basic shape,
2281   * another boolean indicating  whether the self-intersections have to be found (not used in every case).
2282
2283 There are four Perform  methods: 
2284 |Perform(Angle)       | The  resulting revolution is of the given magnitude. |
2285 |Perform(Until)       |The  revolution is defined between the actual position of the base and the given face. |
2286 |Perform(From, Until) | The  revolution is defined between the two faces, From and Until. |
2287 |PerformThruAll()     |          The  result is similar to Perform(2*PI). |
2288
2289 **Note** *Add* method can be used before *Perform* methods to indicate that a face  generated by an edge slides onto a face of the base shape.
2290
2291
2292 In the following sequence, a face is revolved and  the revolution is limited by a face of the base shape. 
2293
2294 ~~~~~
2295 TopoDS_Shape Sbase = ...;  // an initial shape 
2296 TopoDS_Face Frevol = ....; // a base of prism 
2297 TopoDS_Face FUntil = ....; // face limiting the revol 
2298
2299 gp_Dir RevolDir (.,.,.); 
2300 gp_Ax1 RevolAx(gp_Pnt(.,.,.), RevolDir); 
2301
2302 // An empty face is given as the sketch face 
2303
2304 BRepFeat_MakeRevol theRevol(Sbase, Frevol, TopoDS_Face(), RevolAx,  Standard_True, Standard_True); 
2305
2306 theRevol.Perform(FUntil); 
2307 if (theRevol.IsDone()) { 
2308         TopoDS_Shape  theResult = theRevol; 
2309         ... 
2310
2311 ~~~~~
2312
2313 MakePipe
2314 --------
2315 This method constructs compound  shapes with pipe features: depressions or protrusions. A class object is created or initialized from 
2316   * a shape (basic shape),
2317   * a base face (profile of the  pipe)
2318   * a face (face of sketch on  which the base has been defined and used to determine whether the base has been  defined on the basic shape or not),
2319   * a spine wire
2320   * a Boolean indicating the type  of operation (fusion=protrusion or cut=depression) on the basic shape,
2321   * another Boolean indicating if  self-intersections have to be found (not used in every case).
2322
2323 There are three Perform  methods: 
2324
2325 | Perform()            | The  pipe is defined along the entire path (spine wire)   |
2326 | Perform(Until)       | The  pipe is defined along the path until a given face |
2327 | Perform(From, Until) | The  pipe is defined between the two faces From and Until | 
2328
2329 ~~~~~
2330 TopoDS_Shape S = BRepPrimAPI_MakeBox(400.,250.,300.); 
2331 TopExp_Explorer Ex; 
2332 Ex.Init(S,TopAbs_FACE); 
2333 Ex.Next(); 
2334 Ex.Next(); 
2335 TopoDS_Face F1 = TopoDS::Face(Ex.Current()); 
2336 Handle(Geom_Surface) surf = BRep_Tool::Surface(F1); 
2337 BRepBuilderAPI_MakeWire MW1; 
2338 gp_Pnt2d p1,p2; 
2339 p1 = gp_Pnt2d(100.,100.); 
2340 p2 = gp_Pnt2d(200.,100.); 
2341 Handle(Geom2d_Line) aline = GCE2d_MakeLine(p1,p2).Value(); 
2342
2343 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2))); 
2344 p1 = p2; 
2345 p2 = gp_Pnt2d(150.,200.); 
2346 aline = GCE2d_MakeLine(p1,p2).Value(); 
2347
2348 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2))); 
2349 p1 = p2; 
2350 p2 = gp_Pnt2d(100.,100.); 
2351 aline = GCE2d_MakeLine(p1,p2).Value(); 
2352
2353 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2))); 
2354 BRepBuilderAPI_MakeFace MKF1; 
2355 MKF1.Init(surf,Standard_False); 
2356 MKF1.Add(MW1.Wire()); 
2357 TopoDS_Face FP = MKF1.Face(); 
2358 BRepLib::BuildCurves3d(FP); 
2359 TColgp_Array1OfPnt CurvePoles(1,3); 
2360 gp_Pnt pt = gp_Pnt(150.,0.,150.); 
2361 CurvePoles(1) = pt; 
2362 pt = gp_Pnt(200.,100.,150.); 
2363 CurvePoles(2) = pt; 
2364 pt = gp_Pnt(150.,200.,150.); 
2365 CurvePoles(3) = pt; 
2366 Handle(Geom_BezierCurve) curve = new Geom_BezierCurve 
2367 (CurvePoles); 
2368 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve); 
2369 TopoDS_Wire W = BRepBuilderAPI_MakeWire(E); 
2370 BRepFeat_MakePipe MKPipe (S,FP,F1,W,Standard_False, 
2371 Standard_True); 
2372 MKPipe.Perform(); 
2373 TopoDS_Shape res1 = MKPipe.Shape(); 
2374 ~~~~~
2375
2376 ![](/user_guides/modeling_algos/images/modeling_algos_image050.jpg  "Pipe depression")
2377
2378 @subsubsection occt_modalg_9_1_2 Linear Form
2379 --------------
2380 *MakeLinearForm* class creates a rib or a groove  along a planar surface. 
2381 The semantics of  mechanical features is built around giving thickness to a contour. This  thickness can either be symmetrical - on one side of the contour - or  dissymmetrical - on both sides. As in the semantics of form features, the  thickness is defined by construction of shapes in specific contexts. 
2382
2383 The development contexts  differ, however, in the case of mechanical features. 
2384 Here they include  extrusion: 
2385   * to a limiting face of the  basis shape;
2386   * to or from a limiting plane;
2387   * to a height.
2388 A class object is  created or initialized from 
2389   * a shape (basic shape);
2390   * a wire (base of rib or  groove);
2391   * a plane (plane of the wire);
2392   * direction1 (a vector along  which thickness will be built up);
2393   * direction2 (vector opposite  to the previous one along which thickness will be built up, may be null);
2394   * a Boolean indicating the type  of operation (fusion=rib or cut=groove) on the basic shape;
2395   * another Boolean indicating  if self-intersections have to be found (not used in every case).
2396
2397 There is one Perform() method, which performs a  prism from the wire along the direction1 and direction2 interacting base shape Sbase. The height of the prism is Magnitude(Direction1)+Magnitude(direction2).  
2398
2399 ~~~~~
2400 BRepBuilderAPI_MakeWire mkw; 
2401 gp_Pnt p1 = gp_Pnt(0.,0.,0.); 
2402 gp_Pnt p2 = gp_Pnt(200.,0.,0.); 
2403 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2)); 
2404 p1 = p2; 
2405 p2 = gp_Pnt(200.,0.,50.); 
2406 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2)); 
2407 p1 = p2; 
2408 p2 = gp_Pnt(50.,0.,50.); 
2409 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2)); 
2410 p1 = p2; 
2411 p2 = gp_Pnt(50.,0.,200.); 
2412 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2)); 
2413 p1 = p2; 
2414 p2 = gp_Pnt(0.,0.,200.); 
2415 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2)); 
2416 p1 = p2; 
2417 mkw.Add(BRepBuilderAPI_MakeEdge(p2,gp_Pnt(0.,0.,0.))); 
2418 TopoDS_Shape S = BRepBuilderAPI_MakePrism(BRepBuilderAPI_MakeFace 
2419         (mkw.Wire()),gp_Vec(gp_Pnt(0.,0.,0.),gp_P 
2420          nt(0.,100.,0.))); 
2421 TopoDS_Wire W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt 
2422         (50.,45.,100.), 
2423 gp_Pnt(100.,45.,50.))); 
2424 Handle(Geom_Plane) aplane = 
2425         new Geom_Plane(gp_Pnt(0.,45.,0.),  gp_Vec(0.,1.,0.)); 
2426 BRepFeat_MakeLinearForm aform(S, W, aplane, gp_Dir 
2427         (0.,5.,0.), gp_Dir(0.,-3.,0.),  1, Standard_True); 
2428 aform.Perform(); 
2429 TopoDS_Shape res = aform.Shape(); 
2430 ~~~~~
2431
2432 ![](/user_guides/modeling_algos/images/modeling_algos_image051.jpg  "Creating a rib")
2433
2434 @subsubsection occt_modalg_9_1_3 Gluer
2435
2436 The Gluer from BRepFeat  class allows gluing two solids along faces. The contact faces of the glued  shape must not have parts outside the contact faces of the basic shape. 
2437 The class is created or  initialized from two shapes: the “glued” shape and the basic shape (on which  the other shape is glued). 
2438 Two Bind methods are  used to bind a face of the glued shape to a face of the basic shape and an edge  of the glued shape to an edge of the basic shape. 
2439
2440 **Note** Every face and edge has to be  bounded, if two edges of two glued faces are  coincident they must be explicitly bounded.
2441
2442 ~~~~~
2443 TopoDS_Shape Sbase = ...; // the basic shape 
2444 TopoDS_Shape Sglued = ...; // the glued shape 
2445
2446 TopTools_ListOfShape Lfbase; 
2447 TopTools_ListOfShape Lfglued; 
2448 // Determination of the glued faces 
2449 ... 
2450
2451 BRepFeat_Gluer theGlue(Sglue, Sbase); 
2452 TopTools_ListIteratorOfListOfShape itlb(Lfbase); 
2453 TopTools_ListIteratorOfListOfShape itlg(Lfglued); 
2454 for (; itlb.More(); itlb.Next(), itlg(Next()) { 
2455 const TopoDS_Face&amp; f1 = TopoDS::Face(itlg.Value()); 
2456 const TopoDS_Face&amp; f2 = TopoDS::Face(itlb.Value()); 
2457 theGlue.Bind(f1,f2); 
2458 // for example, use the class FindEdges from LocOpe to 
2459 // determine coincident edges 
2460 LocOpe_FindEdge fined(f1,f2); 
2461 for (fined.InitIterator(); fined.More(); fined.Next()) { 
2462 theGlue.Bind(fined.EdgeFrom(),fined.EdgeTo()); 
2463
2464
2465 theGlue.Build(); 
2466 if (theGlue.IsDone() { 
2467 TopoDS_Shape  theResult = theGlue; 
2468 ... 
2469
2470 ~~~~~
2471
2472 @subsubsection occt_modalg_9_1_3 Split Shape
2473
2474 SplitShape from  BRepFeat class is used to split faces of a shape with wires or edges. The shape  containing the new entities is rebuilt, sharing the unmodified ones. 
2475
2476 The class is created or  initialized from a shape (the basic shape). 
2477 Three Add methods are  available: 
2478
2479 | Add(Wire, Face)  | Adds  a new wire on a face of the basic shape. |
2480 | Add(Edge, Face)  | Adds  a new edge on a face of the basic shape. |
2481 | Add(EdgeNew, EdgeOld) | Adds  a new edge on an existing one (the old edge must contain the new edge). |
2482
2483 **Note** The added wires and edges must  define closed wires on faces or wires located between two  existing edges. Existing edges must not be intersected. 
2484
2485 ~~~~~
2486 TopoDS_Shape Sbase = ...; // basic shape 
2487 TopoDS_Face Fsplit = ...; // face of Sbase 
2488 TopoDS_Wire Wsplit = ...; // new wire contained in Fsplit 
2489 BRepFeat_SplitShape Spls(Sbase); 
2490 Spls.Add(Wsplit, Fsplit); 
2491 TopoDS_Shape theResult = Spls; 
2492 ...
2493 ~~~~~
2494
2495
2496 @section occt_modalg_10 Hidden Line  Removal
2497
2498 To provide the  precision required in industrial design, drawings need to offer the possibility  of removing lines, which are hidden in a given projection. 
2499
2500 For this the Hidden  Line Removal component provides two algorithms: HLRBRep_Algo  and HLRBRep_PolyAlgo. 
2501
2502 These algorithms are  based on the principle of comparing each edge of the shape to be visualized  with each of its faces, and calculating the visible and the hidden parts of  each edge. Note that these are not the  algorithms used in generating  shading, which calculate the visible and hidden parts of each face in a shape  to be visualized by comparing each face in the shape with every other face in  the same shape. 
2503 These algorithms operate  on a shape and remove or indicate edges hidden by faces. For a given  projection, they calculate a set of lines characteristic of the object being  represented. They are also used in conjunction with extraction utilities, which  reconstruct a new, simplified shape from a selection of the results of the  calculation. This new shape is made up of edges, which represent the shape  visualized in the projection. 
2504
2505 HLRBRep_Algo takes the shape  itself into account whereas HLRBRep_PolyAlgo works with a polyhedral simplification of the shape. When you use HLRBRep_Algo, you obtain an exact result, whereas, when you  use HLRBRep_PolyAlgo, you reduce the computation time. 
2506
2507 No smoothing algorithm  is provided. Consequently, a polyhedron will be treated as such and the  algorithms will give the results in  form of line segments conforming to the  mathematical definition of the polyhedron. This is always the case with HLRBRep_PolyAlgo. 
2508
2509 HLRBRep_Algo and HLRBRep_PolyAlgo can deal with any kind of object, for example, assemblies of  volumes, surfaces, and lines, as long as there are no unfinished  objects or points within it. 
2510
2511 However, there some restrictions in HLR use:
2512   * Points are not processed;
2513   * Z-clipping planes are not used;
2514   * Infinite faces or lines are not processed.
2515
2516   
2517 ![](/user_guides/modeling_algos/images/modeling_algos_image052.jpg "Sharp, smooth and sewn edges  in a simple screw shape")
2518
2519 ![](/user_guides/modeling_algos/images/modeling_algos_image053.jpg "Outline edges  and isoparameters in the same shape")
2520
2521 ![](/user_guides/modeling_algos/images/modeling_algos_image054.jpg "A simple screw shape seen with shading")
2522
2523 ![](/user_guides/modeling_algos/images/modeling_algos_image055.jpg "An extraction  showing hidden sharp edges")
2524
2525
2526 @subsection occt_modalg_10_2 Services
2527 The following services are related to Hidden Lines Removal : 
2528
2529 Loading Shapes
2530 --------------
2531 To pass a *TopoDS_Shape* to an *HLRBRep_Algo*  object, use *HLRBRep_Algo::Add*. With an *HLRBRep_PolyAlgo* object, use *HLRBRep_PolyAlgo::Load*. If you wish to add several shapes, use Add or Load as often  as necessary. 
2532
2533 Setting view parameters
2534 -----------------------
2535 HLRBRep_Algo::Projector and HLRBRep_PolyAlgo::Projector set a projector object which defines the  parameters of the view. This object is an HLRAlgo_Projector. 
2536
2537 Computing the projections
2538 -------------------------
2539 HLRBRep_PolyAlgo::Update  launches the calculation of outlines of the shape visualized by the HLRBRep_PolyAlgo framework. 
2540 In the case of HLRBRep_Algo, use HLRBRep_Algo::Update. With this algorithm, you must also call the method HLRBRep_Algo::Hide to calculate visible and hidden lines of the  shape to be visualized. With an HLRBRep_PolyAlgo object, visible and hidden lines are computed by HLRBRep_PolyHLRToShape. 
2541
2542 Extracting edges
2543 ----------------
2544 The classes HLRBRep_HLRToShape and HLRBRep_PolyHLRToShape present a range of extraction filters for an HLRBRep_Algo object and an HLRBRep_PolyAlgo object, respectively. They highlight the type of  edge from the results calculated by the algorithm on a shape. With  both extraction classes, you can highlight the following types of output: 
2545   * visible/hidden sharp edges;
2546   * visible/hidden smooth edges;
2547   * visible/hidden sewn edges;
2548   * visible/hidden outline edges. 
2549
2550 To perform extraction on an *HLRBRep_PolyHLRToShape* object, use *HLRBRep_PolyHLRToShape::Update*  function. 
2551 For an *HLRBRep_HLRToShape* object built from an *HLRBRepAlgo* object you can also highlight: 
2552   * visible isoparameters and
2553   * hidden isoparameters.
2554
2555 @subsection occt_modalg_10_3 Examples
2556
2557 HLRBRep_Algo
2558 ------------
2559 ~~~~~
2560 // Build The algorithm object 
2561 myAlgo = new HLRBRep_Algo(); 
2562
2563 // Add Shapes into the algorithm 
2564 TopTools_ListIteratorOfListOfShape anIterator(myListOfShape); 
2565 for (;anIterator.More();anIterator.Next()) 
2566 myAlgo-Add(anIterator.Value(),myNbIsos); 
2567
2568 // Set The Projector (myProjector is a 
2569 HLRAlgo_Projector) 
2570 myAlgo-Projector(myProjector); 
2571
2572 // Build HLR 
2573 myAlgo->Update(); 
2574
2575 // Set The Edge Status 
2576 myAlgo->Hide(); 
2577
2578 // Build the extraction object : 
2579 HLRBRep_HLRToShape aHLRToShape(myAlgo); 
2580
2581 // extract the results : 
2582 TopoDS_Shape VCompound           = aHLRToShape.VCompound(); 
2583 TopoDS_Shape Rg1LineVCompound                            = 
2584 aHLRToShape.Rg1LineVCompound(); 
2585 TopoDS_Shape RgNLineVCompound                            = 
2586 aHLRToShape.RgNLineVCompound(); 
2587 TopoDS_Shape OutLineVCompound                            = 
2588 aHLRToShape.OutLineVCompound(); 
2589 TopoDS_Shape IsoLineVCompound                            = 
2590 aHLRToShape.IsoLineVCompound(); 
2591 TopoDS_Shape HCompound           = aHLRToShape.HCompound(); 
2592 TopoDS_Shape Rg1LineHCompound                            = 
2593 aHLRToShape.Rg1LineHCompound(); 
2594 TopoDS_Shape RgNLineHCompound                            = 
2595 aHLRToShape.RgNLineHCompound(); 
2596 TopoDS_Shape OutLineHCompound                            = 
2597 aHLRToShape.OutLineHCompound(); 
2598 TopoDS_Shape IsoLineHCompound                            = 
2599 aHLRToShape.IsoLineHCompound(); 
2600 ~~~~~
2601
2602 HLRBRep_PolyAlgo
2603 ----------------
2604
2605 ~~~~~
2606
2607 // Build The algorithm object 
2608 myPolyAlgo = new HLRBRep_PolyAlgo(); 
2609
2610 // Add Shapes into the algorithm 
2611 TopTools_ListIteratorOfListOfShape 
2612 anIterator(myListOfShape); 
2613 for (;anIterator.More();anIterator.Next()) 
2614 myPolyAlgo-Load(anIterator.Value()); 
2615
2616 // Set The Projector (myProjector is a 
2617 HLRAlgo_Projector) 
2618 myPolyAlgo->Projector(myProjector); 
2619
2620 // Build HLR 
2621 myPolyAlgo->Update(); 
2622
2623 // Build the extraction object : 
2624 HLRBRep_PolyHLRToShape aPolyHLRToShape; 
2625 aPolyHLRToShape.Update(myPolyAlgo); 
2626
2627 // extract the results : 
2628 TopoDS_Shape VCompound = 
2629 aPolyHLRToShape.VCompound(); 
2630 TopoDS_Shape Rg1LineVCompound = 
2631 aPolyHLRToShape.Rg1LineVCompound(); 
2632 TopoDS_Shape RgNLineVCompound = 
2633 aPolyHLRToShape.RgNLineVCompound(); 
2634 TopoDS_Shape OutLineVCompound = 
2635 aPolyHLRToShape.OutLineVCompound(); 
2636 TopoDS_Shape HCompound = 
2637 aPolyHLRToShape.HCompound(); 
2638 TopoDS_Shape Rg1LineHCompound = 
2639 aPolyHLRToShape.Rg1LineHCompound(); 
2640 TopoDS_Shape RgNLineHCompound = 
2641 aPolyHLRToShape.RgNLineHCompound(); 
2642 TopoDS_Shape OutLineHCompound = 
2643 aPolyHLRToShape.OutLineHCompound(); 
2644 ~~~~~
2645
2646 @section occt_modalg_10_4 Meshing of  Shapes
2647
2648 The *HLRBRep_PolyAlgo*  algorithm works with triangulation of shapes. This is provided by the function  *BRepMesh::Mesh*, which adds a triangulation of the shape to its topological data  structure. This triangulation is computed with a given deflection. 
2649
2650 ~~~~~
2651 Standard_Real radius=10. ; 
2652 Standard_Real height=25. ; 
2653 BRepBuilderAPI_MakeCylinder myCyl (radius, height) ; 
2654 TopoDS_Shape myShape = myCyl.Shape() ; 
2655 Standard_Real Deflection = 0.01 ; 
2656 BRepMesh::Mesh (myShape, Deflection); 
2657 ~~~~~
2658
2659 Meshing covers a shape with a triangular mesh. Other  than hidden line removal, you can use meshing to transfer the shape to another  tool: a manufacturing tool, a shading algorithm, a finite element algorithm, or  a collision algorithm, for example. 
2660
2661 You can obtain  information on the shape by first exploring it. To then access triangulation of  a face in the shape, use *BRepTool::Triangulation*. To access a polygon which is  the approximation of an edge of the face, use *BRepTool::PolygonOnTriangulation*.