Opencascade常用函数 更新中...

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

Opencascade常用函数


几何创建

坐标

gp_Ax1 axe = gp_Ax1(gp_Pnt(110,60,60),gp_Dir(0.,1.,0.));

gp_Ax3 theAxe(gp::XOY());
gp_Ax22d A(P,D);

gp_Pnt P1(2,3,4);                           
gp_Dir D(4,5,6);                            
gp_Ax3 A(P1,D); 

gp_Ax1 axe = gp_Ax1(gp_Pnt(-170.,-170.,0.),gp_Dir(0.,0.,1.));
Handle(Geom_Axis1Placement) Gax1 = new Geom_Axis1Placement(axe);
方向
gp_Dir D2(3,4,5);
gp_Vec V1 (P1,P2);                       
2d方向
gp_Dir2d D; 
坐标系
变换
gp_Trsf TRSF;     

曲线

gp_XYZ A(1,2,3); 
gp_Pnt P1(1,2,3); 
2d点
gp_Pnt2d P1(0,5);
点数组/点集
gp_Pnt P1(0,0,5);
gp_Pnt P2(1,2,3);
gp_Pnt P3(2,3,-2);
gp_Pnt P4(4,3,5);
gp_Pnt P5(5,5,4);                                                
TColgp_Array1OfPnt array (1,5); 
array.SetValue(1,P1);
array.SetValue(2,P2);
array.SetValue(3,P3);
array.SetValue(4,P4);
array.SetValue(5,P5);
Standard_Real Tolerance = 8;
GProp_PEquation PE (array,Tolerance);


直线
2d直线
gp_Pnt2d P1(1,2);
gp_Pnt2d P2(4,5);
gp_Lin2d L = gce_MakeLin2d(P1,P2);

// 二等分直线
gp_Pnt2d P1(1,2);
gp_Pnt2d P2(4,5);
gp_Lin2d L;
GccAna_Pnt2dBisec B(P1,P2);
if (B.IsDone())
{
L = B.ThisSolution();
}
线段
gp_Pnt P1(-5,-5,0);
gp_Pnt P2(9,9,9);
Handle(Geom_Curve) aCurve = GC_MakeSegment(P1,P2).Value();
2d线段
gp_Pnt2d P1(-1,-2);
gp_Pnt2d P2(0,15);
gp_Dir2d V1 = gp::DY2d();
Handle(Geom2d_TrimmedCurve) TC1 = GCE2d_MakeSegment(P1,V1,P2);
2d圆
Standard_Real radius = 5;                          
Handle(Geom2d_Circle) C = new Geom2d_Circle(gp::OX2d(),radius); 

gp_Pnt2d P1 (9,6);
gp_Pnt2d P2 (10,4);
gp_Pnt2d P3 (6,7);
gp_Circ2d C = gce_MakeCirc2d (P1,P2,P3);

Standard_Real radius = 3;
Handle(Geom2d_Circle) circle = new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(-7,2),gp_Dir2d(1,0)),radius);
gp_Pnt centre (5,5,0); gp_Pnt axispoint (9,9,0);
Standard_Real radius = 3;
Handle(Geom_Circle) circle =
GC_MakeCircle(centre,axispoint,radius);
圆弧
2d圆弧
gp_Pnt2d P1(0,5);                                       
gp_Pnt2d P2(5.5,1);                                     
gp_Pnt2d P3(-2,2); 
Handle(Geom2d_Curve) C =  GCE2d_MakeArcOfCircle (P1,P2,P3).Value();
2d椭圆
Standard_Real major = 12;
Standard_Real minor = 4;
gp_Ax2d axis = gp::OX2d();
gp_Elips2d EE(axis,major,minor);
Handle(Geom2d_TrimmedCurve) arc = GCE2d_MakeArcOfEllipse(EE,0.0,M_PI/4);
椭圆
Standard_Real MinorRadius = 5; 
Standard_Real MajorRadius = 8; 
gp_Elips EL (gp::YOZ(),MajorRadius,MinorRadius); 

 Handle(Geom_Ellipse) E = GC_MakeEllipse( gp::XOY() ,3,1).Value();
抛物线
  gp_Parab aParab(anAxis2.Translated(gp_Vec(0.0, 0.0, 20.0)), 2.0);
  Handle(Geom_Parabola) aGeomParabola = new Geom_Parabola(aParab);
  Handle(Geom_TrimmedCurve) aTrimmedParabola = new Geom_TrimmedCurve(aGeomParabola, 20.0, -20.0);
2d抛物线
gp_Pnt2d P(2,3);
gp_Dir2d D(4,5);
gp_Ax22d A(P,D);
gp_Parab2d Para(A,6);
Handle(Geom2d_Parabola) aParabola = GCE2d_MakeParabola(Para);

多边形
BRepBuilderAPI_MakePolygon P;
P.Add(gp_Pnt(0.,0.,0.));
P.Add(gp_Pnt(200.,0.,0.));
P.Add(gp_Pnt(200.,200.,0.));
P.Add(gp_Pnt(0.,200.,0.));
P.Add(gp_Pnt(0.,0.,0.));
TopoDS_Wire W = P.Wire();

TopoDS_Wire wprof = BRepBuilderAPI_MakePolygon(gp_Pnt(0.,0.,0.),gp_Pnt(-60.,-60.,-200.));
双曲线
gp_Hypr aHypr(anAxis2.Translated(gp_Vec(0.0, 0.0, 30.0)), 20.0, 10.0);
  Handle(Geom_Hyperbola) aGeomHyperbola = new Geom_Hyperbola(aHypr);
  Handle(Geom_TrimmedCurve) aTrimmedHyperbola = new Geom_TrimmedCurve(aGeomHyperbola, 2.0, -2.0);
Bezier曲线
Standard_Real aPolesCoords[][3] = {
{0,0,0},{0,1,0},{1,1,0},{1,2,0},{2,2,0},{2,1,0},{3,1,0},{3,0,0},{2,0,0},{2,-1,0},
{3,-1,0},{3,-2,0},{4,-2,0},{4,-1,0},{5,-1,0},{5,0,0},{6,0,0},{6,-1,0},{7,-1,0},
{7,0,0},{8,0,0},{8,1,0}
};
TColgp_Array1OfPnt aPoles (1, sizeof(aPolesCoords)/(sizeof(Standard_Real)*3));

for (Standard_Integer i=1; i <= aPoles.Upper(); i++)
aPoles(i) = gp_Pnt (aPolesCoords[i-1][0]*150-500, 
aPolesCoords[i-1][1]*150, 
aPolesCoords[i-1][2]*150);

Handle(Geom_BezierCurve) aCurve = new Geom_BezierCurve (aPoles);


TColgp_Array1OfPnt aPoles(1,4);
// array of the poles' weights
TColStd_Array1OfReal aWeights(1,4);
aPoles(1) = gp_Pnt(0, 0, 0);      aWeights(1) = 1;
aPoles(2) = gp_Pnt(150, 250, 0);  aWeights(2) =75;
aPoles(3) = gp_Pnt(350, 150, 0);  aWeights(3) =120;
aPoles(4) = gp_Pnt(500, 500, 0);  aWeights(4) = 1;
Handle(Geom_Curve) aBezierCurve = new Geom_BezierCurve(aPoles, aWeights);
B样条曲线
点数组创建
TColgp_Array1OfPnt2d array (1,5);
array.SetValue(1,gp_Pnt2d (0,0));
array.SetValue(2,gp_Pnt2d (1,2));
array.SetValue(3,gp_Pnt2d (2,3));
array.SetValue(4,gp_Pnt2d (4,3));
array.SetValue(5,gp_Pnt2d (5,5));
Handle(Geom2d_BSplineCurve) SPL1 =
Geom2dAPI_PointsToBSpline(array);
插值点创建
Handle(TColgp_HArray1OfPnt2d) harray =
new TColgp_HArray1OfPnt2d (1,5); // sizing harray
harray->SetValue(1,gp_Pnt2d (7+ 0,0));
harray->SetValue(2,gp_Pnt2d (7+ 1,2));
harray->SetValue(3,gp_Pnt2d (7+ 2,3));
harray->SetValue(4,gp_Pnt2d (7+ 4,3));
harray->SetValue(5,gp_Pnt2d (7+ 5,5));
Geom2dAPI_Interpolate anInterpolation(harray,Standard_False,0.01);
anInterpolation.Perform();
Handle(Geom2d_BSplineCurve) SPL2 = anInterpolation.Curve();
全部构造
// Define points.
gp_Pnt aPnt1(0.0, 0.0, 0.0);
gp_Pnt aPnt2(5.0, 5.0, 0.0);
gp_Pnt aPnt3(10.0, 5.0, 0.0);
gp_Pnt aPnt4(15.0, 0.0, 0.0);

// Add points to the curve poles array.
TColgp_Array1OfPnt aPoles(1, 4);
aPoles.SetValue(1, aPnt1);
aPoles.SetValue(2, aPnt2);
aPoles.SetValue(3, aPnt3);
aPoles.SetValue(4, aPnt4);

// Define BSpline weights.
TColStd_Array1OfReal aBSplineWeights(1, 4);
aBSplineWeights.SetValue(1, 1.0);
aBSplineWeights.SetValue(2, 0.5);
aBSplineWeights.SetValue(3, 0.5);
aBSplineWeights.SetValue(4, 1.0);

// Define knots.
TColStd_Array1OfReal aKnots(1, 2);
aKnots.SetValue(1, 0.0);
aKnots.SetValue(2, 1.0);

// Define multiplicities.
TColStd_Array1OfInteger aMults(1, 2);
aMults.SetValue(1, 4);
aMults.SetValue(2, 4);

// Define BSpline degree and periodicity.
Standard_Integer aDegree = 3;
Standard_Boolean aPeriodic = Standard_False;

// Create a BSpline curve.
Handle(Geom_BSplineCurve) aBSplineCurve = new Geom_BSplineCurve(
aPoles, aBSplineWeights, aKnots, aMults, aDegree, aPeriodic);
边界曲线
2d偏移曲线
TColgp_Array1OfPnt2d array (1,5); // sizing array
array.SetValue(1,gp_Pnt2d (-4,0)); array.SetValue(2,gp_Pnt2d (-7,2));
array.SetValue(3,gp_Pnt2d (-6,3)); array.SetValue(4,gp_Pnt2d (-4,3));
array.SetValue(5,gp_Pnt2d (-3,5));
Handle(Geom2d_BSplineCurve) SPL1 = Geom2dAPI_PointsToBSpline(array);
Standard_Real dist = 1;
Handle(Geom2d_OffsetCurve) OC = new Geom2d_OffsetCurve(SPL1,dist);
Standard_Boolean result = OC->IsCN(2);
Standard_Real dist2 = 1.5;
Handle(Geom2d_OffsetCurve) OC2 = new Geom2d_OffsetCurve(SPL1,dist2);
Standard_Boolean result2 = OC2->IsCN(2);
偏移曲线
gp_Circ aCirc(gp::XOY(), 5.0);
Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc);
myResult << "Geom_Circle was created in yellow" << std::endl;

Standard_Real anExpandOffset = +aCirc.Radius() / 4.0;
gp_Dir anExpandDir = gp::DZ();
Handle(Geom_OffsetCurve) anExpandCircCurve = new Geom_OffsetCurve(
aCircCurve, anExpandOffset, anExpandDir);
myResult << "Geom_OffsetCurve (expanded circle) was created in red" << std::endl;

Standard_Real anCollapseOffset = -aCirc.Radius() / 2.0;
gp_Dir anCollapseDir = gp::DZ();
Handle(Geom_OffsetCurve) anCollapseCircCurve = new Geom_OffsetCurve (aCircCurve, anCollapseOffset, anCollapseDir);

偏移集合
BRepBuilderAPI_MakePolygon aTria;
TopoDS_Vertex aVertA = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0));
TopoDS_Vertex aVertB = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 0.0, +1.0));
TopoDS_Vertex aVertC = BRepBuilderAPI_MakeVertex(gp_Pnt(+0.5, 0.0, 0.0));
aTria.Add(aVertA);
aTria.Add(aVertB);
aTria.Add(aVertC);
aTria.Close();
TopoDS_Wire aWire = aTria.Wire();
BRepOffsetAPI_MakeOffset anAlgo(aWire);

Standard_Real anOffsetStep = 0.2;
Standard_Real anAltitudeStep = 0.1;
for (Standard_Integer i = 1; i <= 4; ++i)
{
    Standard_Real anOffset = anOffsetStep * i;
    Standard_Real anAltitude = anAltitudeStep * i;
    anAlgo.Perform(anOffset, anAltitude);
    if (anAlgo.IsDone())
    {
    	TopoDS_Shape aResult = anAlgo.Shape();
    }
}
裁剪曲线
Handle(Geom2d_Parabola) aParabola = GCE2d_MakeParabola(Para);
Handle(Geom2d_TrimmedCurve) aTrimmedCurve = new Geom2d_TrimmedCurve(aParabola,-100,100);

曲面

平面
gp_Ax3 theAxe(gp::XOY());
gp_Pln PL(theAxe); 
盒子
TopoDS_Shape B1 = BRepPrimAPI_MakeBox(200., 150., 100.).Shape();
TopoDS_Shape B2 = BRepPrimAPI_MakeBox (gp_Ax2(gp_Pnt(-200.,-80.,-70.),
gp_Dir(1.,2.,1.)),
80., 90., 120.).Shape();
Handle(AIS_Shape) aBox2 = new AIS_Shape(B2);
球面
Standard_Real radius = 5;
Handle(Geom_SphericalSurface) SP = new Geom_SphericalSurface(gp_Ax3(gp::XOY()),radius);

gp_Ax3 anAx(gp_Pnt(0,0,0), gp_Dir(0,0,1)); 
// creating a spherical surface with radius = 300
Handle(Geom_SphericalSurface) aSurface = new Geom_SphericalSurface(anAx,300);


TopoDS_Shape S1 = BRepPrimAPI_MakeSphere(gp_Pnt(-200., -250., 0.), 80.).Shape();
TopoDS_Shape S2 = BRepPrimAPI_MakeSphere(100., 120.*M_PI / 180).Shape();
TopoDS_Shape S3 = BRepPrimAPI_MakeSphere(gp_Pnt(200.,250.,0.),100.,
                                         -60.*M_PI / 180, 60.*M_PI / 180).Shape();

  gp_Sphere aSphere(gp_Ax3(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)), 10.0);
  Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(aSphere);
椭球面
柱面
gp_Ax3 anAx(gp_Pnt(0,0,0), gp_Dir(0,1,0));

// creating a cylindrical surface along anAx with radius = 4
Handle(Geom_CylindricalSurface) aCylSurface = new Geom_CylindricalSurface(anAx, 100);

// only finit surfaces can be converted to BSpline surfaces, 
// cylindrical surface is infinite, it must be trimmed
Handle(Geom_RectangularTrimmedSurface) aSurface = 
    new Geom_RectangularTrimmedSurface(aCylSurface, 0, 2*M_PI, -1000, 1000, Standard_True, Standard_True);


TopoDS_Shape C1 = BRepPrimAPI_MakeCylinder(50., 200.).Shape();
TopoDS_Shape C2 = BRepPrimAPI_MakeCylinder (gp_Ax2(gp_Pnt(200.,200.,0.),
                                                   gp_Dir(0.,0.,1.)),
                                            40., 110., 210.*M_PI / 180).Shape();
圆锥面
gp_Pnt P3(3,0,0);
gp_Pnt P4(3,0,10);
Standard_Real radius1 = 3;
Standard_Real radius2 = 2;
Handle(Geom_Surface) aSurface = GC_MakeConicalSurface(P3,P4,radius1,radius2).Value();


gp_Ax3 anAx(gp_Pnt(0,0,0), gp_Dir(0,0,1)); 
// creating a conical surface with base radius = 10 and angle = 20 deg
Handle(Geom_ConicalSurface) aConicalSurface = new Geom_ConicalSurface(anAx,M_PI/9., 10);

// only finit surfaces can be converted to BSpline surfaces, 
// conical surface is infinite, it must be trimmed
Handle(Geom_RectangularTrimmedSurface) aSurface = 
    new Geom_RectangularTrimmedSurface(aConicalSurface, 0, 2*M_PI, -1000, 1000, Standard_True, Standard_True);


TopoDS_Shape C1 = BRepPrimAPI_MakeCone(50., 25., 200.).Shape();
TopoDS_Shape C2 = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(100.,100.,0.),
                                              gp_Dir(0.,0.,1.)),
                                       60., 0., 150., 210.*M_PI / 180).Shape();

 gp_Cone aCone(gp_Ax3(gp_Pnt(0.0, 0.0, 30.0), gp_Dir(0.0, 0.0, 1.0)), 0.25*M_PI, 0.0);
  Handle(Geom_ConicalSurface) aConicalSurface = new Geom_ConicalSurface(aCone);
楔体
TopoDS_Shape S = BRepPrimAPI_MakeWedge (60.,100.,80.,20.).Shape();

TopoDS_Shape S1 = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape();
TopoDS_Shape S2 = BRepPrimAPI_MakeWedge(gp_Ax2(gp_Pnt(100.,100.,0.),gp_Dir(0.,0.,1.)),
                                        60., 50., 80., 25., -10., 40., 70.).Shape();


抛物面
双曲面
直纹面
线性拉伸面
TopoDS_Wire W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50.,45.,100.),
gp_Pnt(100.,45.,50.)));	
Handle(Geom_Plane) aplane = new Geom_Plane(0.,1.,0.,-45.);
BRepFeat_MakeLinearForm aform(S, W, aplane, gp_Vec(0.,10.,0.), gp_Vec(0.,0.,0.),
1, Standard_True);
aform.Perform(/*10.*/); // new in 2.0
TopoDS_Shape res = aform.Shape();


  // Create an ellipse curve in XY plane.
  Standard_Real aMinorRadius = 10.0;
  Standard_Real aMajorRadius = 20.0;
  Handle(Geom_Ellipse) anEllipseCurve = new Geom_Ellipse(gp::XOY(), aMajorRadius, aMinorRadius);
  myResult << "Geom_Ellipse was created in yellow" << std::endl;

  // Make a linear extrusion of the ellipse at 45 degrees to Z axis
  gp_Dir aDirOfExtr = gp::DZ();
  Handle(Geom_SurfaceOfLinearExtrusion) aLinExtrSurf
    = new Geom_SurfaceOfLinearExtrusion(anEllipseCurve, aDirOfExtr);
旋转面
TColgp_Array1OfPnt aPoles(1,4);
// array of the poles' weights
TColStd_Array1OfReal aWeights(1,4);

aPoles(1) = gp_Pnt(0, 0, 0);      aWeights(1) = 1;
aPoles(2) = gp_Pnt(150, 250, 0);  aWeights(2) =75;
aPoles(3) = gp_Pnt(350, 150, 0);  aWeights(3) =120;
aPoles(4) = gp_Pnt(500, 500, 0);  aWeights(4) = 1;

Handle(Geom_Curve) aBezierCurve = new Geom_BezierCurve(aPoles, aWeights);

// creating a surface of revolution of the bezier curve around Y axis
gp_Ax1 anAx(gp_Pnt(0,0,0), gp_Dir(0,1,0));
Handle(Geom_SurfaceOfRevolution) aSurface = new Geom_SurfaceOfRevolution(aBezierCurve, anAx);


TColgp_Array1OfPnt array (1,5);
array.SetValue(1,gp_Pnt (0,0,1));
array.SetValue(2,gp_Pnt (1,2,2));
array.SetValue(3,gp_Pnt (2,3,3));
array.SetValue(4,gp_Pnt (4,3,4));
array.SetValue(5,gp_Pnt (5,5,5));
Handle(Geom_BSplineCurve) aCurve =
GeomAPI_PointsToBSpline(array).Curve();
Handle(Geom_SurfaceOfRevolution) SOR =
new Geom_SurfaceOfRevolution(aCurve,gp::OX());

Standard_CString SOREntityTypeName="Not Computed";
if (!SOR.IsNull())
SOREntityTypeName = SOR->DynamicType()->Name();

渐变面
BRepBuilderAPI_MakePolygon aTria;
TopoDS_Vertex aVertA = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0));
TopoDS_Vertex aVertB = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, +1.0, 0.0));
TopoDS_Vertex aVertC = BRepBuilderAPI_MakeVertex(gp_Pnt(+0.5, 0.0, 0.0));
aTria.Add(aVertA);
aTria.Add(aVertB);
aTria.Add(aVertC);
aTria.Close();
TopoDS_Wire aSpine = aTria.Wire();

// Make a wire as a profile.
BRepBuilderAPI_MakePolygon aPoly;
TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0));
TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, -0.1, 0.5));
TopoDS_Vertex aVert3 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, -0.2, 1.0));
aPoly.Add(aVert1);
aPoly.Add(aVert2);
aPoly.Add(aVert3);
TopoDS_Wire aProfile = aPoly.Wire();

GeomAbs_JoinType aJoinType = GeomAbs_Arc;
Standard_Boolean aIsGlobalCS = Standard_False;
Standard_Boolean aIsSolid = Standard_True;
BRepOffsetAPI_MakeEvolved anAlgo(aSpine, aProfile, aJoinType, aIsGlobalCS, aIsSolid);
anAlgo.Build();
if (anAlgo.IsDone())
{
	TopoDS_Shape aResult = anAlgo.Shape();
}
平曲面
Standard_Integer i, nbPntsOnFaces=10;
Standard_Real u,First, Last, Delta, Tol=0.001, TolProj;
Plate_Plate aPlate;
gp_Vec V1,V2,W1,W2;
gp_Pnt2d P2d;
gp_Pnt P, PP;

//get the pcurve, curve and surface
BRepAdaptor_Curve   Curve3d1(THE_E1), Curve3d2(THE_E2);
BRepAdaptor_Curve2d Curve2d1(THE_E1,THE_F1), Curve2d2(THE_E2,THE_F2);
BRepAdaptor_Surface Surf1(THE_F1), Surf2(THE_F2);

//compute the average plane : initial surface
Handle(TColgp_HArray1OfPnt) theTanPoints = new
    TColgp_HArray1OfPnt (1,2*nbPntsOnFaces );

Delta = (Curve3d1.LastParameter()-Curve3d1.FirstParameter())/(nbPntsOnFaces-1);
for (u=Curve3d1.FirstParameter(),i=1;i<=nbPntsOnFaces; i++,u+=Delta)
    theTanPoints->SetValue(i,Curve3d1.Value(u));

Delta = (Curve3d2.LastParameter()-Curve3d2.FirstParameter())/(nbPntsOnFaces-1);
for (u=Curve3d2.FirstParameter(),i=1;i<=nbPntsOnFaces; i++,u+=Delta)
    theTanPoints->SetValue(nbPntsOnFaces+i,Curve3d2.Value(u));

//Building an initial plane
GeomPlate_BuildAveragePlane aMkPlane (theTanPoints,int(Tol),1,1,1);
Handle(Geom_Plane) aPlane = aMkPlane.Plane();
gp_Pln aPln = aPlane->Pln();
gp_XYZ aNormale = aPln.Axis().Direction().XYZ();
gp_Trsf aTrsf; // to compute the U and V of the points
aTrsf.SetTransformation(aPln.Position());

aPlane->D1(0,0,P,W1,W2); // extract plane DU & DV

// 1st surface tangencies constraints
Delta = (Curve3d1.LastParameter()-Curve3d1.FirstParameter())/(nbPntsOnFaces-1);
for (u=Curve3d1.FirstParameter(),i=1; i<=nbPntsOnFaces; i++,u+=Delta) {
    P = Curve3d1.Value(u).Transformed(aTrsf);
    gp_XY UV(P.X(),P.Y());
    aPlate.Load(Plate_PinpointConstraint(UV,aNormale*P.Z()));
    Curve2d1.D0(u,P2d);
    Surf1.D1(P2d.X(),P2d.Y(),P,V1,V2);  // extract surface UV of the point
    aPlate.Load(Plate_GtoCConstraint(UV,
                                     Plate_D1(W1.XYZ(),W2.XYZ()),
                                     Plate_D1(V1.XYZ(),V2.XYZ())));
}
// 2nd surface 
Delta = (Curve3d2.LastParameter()-Curve3d2.FirstParameter())/(nbPntsOnFaces-1);
for (u=Curve3d2.FirstParameter(),i=1; i<=nbPntsOnFaces; i++,u+=Delta) {
    P = Curve3d2.Value(u).Transformed(aTrsf);
    gp_XY UV(P.X(),P.Y());
    aPlate.Load(Plate_PinpointConstraint(UV,aNormale*P.Z()));

    Curve2d2.D0(u,P2d);
    Surf2.D1(P2d.X(),P2d.Y(),P,V1,V2); 
    aPlate.Load(Plate_GtoCConstraint(UV,
                                     Plate_D1(W1.XYZ(),W2.XYZ()),
                                     Plate_D1(V1.XYZ()*-1,V2.XYZ()*-1)));
}
扫掠面
环形面
gp_Ax3 anAx(gp_Pnt(0,0,0), gp_Dir(0,1,0)); 
// creating a toroidal surface with major radius = 240 and minor radius = 120
Handle(Geom_ToroidalSurface) aSurface = new Geom_ToroidalSurface(anAx, 240, 120);

TopoDS_Shape S1 = BRepPrimAPI_MakeTorus(60., 20.).Shape();
TopoDS_Shape S2 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(100.,100.,0.),gp_Dir(1.,1.,1.)),
                                        50., 20., 210.*M_PI / 180).Shape();
TopoDS_Shape S3 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(-200.,-150.,-100),gp_Dir(0.,1.,0.)),
                                        60., 20., -45.*M_PI / 180, 45.*M_PI / 180, 90.*M_PI / 180).Shape();

  gp_Torus aTorus(gp_Ax3(gp_Pnt(0.0, 0.0, 20.0), gp_Dir(0.0, 0.0, 1.0)), 40.0, 10.0);
  Handle(Geom_ToroidalSurface) aToroidalSurface = new Geom_ToroidalSurface(aTorus);
偏移曲面
TColgp_Array1OfPnt array1 (1,5);
array1.SetValue(1,gp_Pnt (-4,5,5 ));
array1.SetValue(2,gp_Pnt (-3,6,6 ));
array1.SetValue(3,gp_Pnt (-1,7,7 ));
array1.SetValue(4,gp_Pnt (0,8,8));
array1.SetValue(5,gp_Pnt (2,9,9));
Handle(Geom_BSplineCurve) SPL1 =
GeomAPI_PointsToBSpline(array1).Curve();

TColgp_Array1OfPnt array2 (1,5);
array2.SetValue(1,gp_Pnt (-4,5,2 ));
array2.SetValue(2,gp_Pnt (-3,6,3 ));
array2.SetValue(3,gp_Pnt (-1,7,4 ));
array2.SetValue(4,gp_Pnt (0,8,5));
array2.SetValue(5,gp_Pnt (2,9,6));
Handle(Geom_BSplineCurve) SPL2 =
GeomAPI_PointsToBSpline(array2).Curve();

GeomFill_FillingStyle Type = GeomFill_StretchStyle;
GeomFill_BSplineCurves aGeomFill1(SPL1,SPL2,Type);
Handle(Geom_BSplineSurface) aGeomSurface = aGeomFill1.Surface();
Standard_Real offset = 1;
Handle(Geom_OffsetSurface) GOS = new Geom_OffsetSurface(aGeomSurface, offset);
offset = 2;
Handle(Geom_OffsetSurface) GOS1 = new Geom_OffsetSurface(aGeomSurface, offset);
offset = 3;
Handle(Geom_OffsetSurface) GOS2 = new Geom_OffsetSurface(aGeomSurface, offset);
拓扑偏移
TopoDS_Shape S1 = BRepPrimAPI_MakeBox(150, 200, 110).Shape();
BRepOffsetAPI_MakeOffsetShape aShapeMaker1;
aShapeMaker1.PerformByJoin(S1,60,0.01);
TopoDS_Shape anOffsetShape1 = aShapeMaker1.Shape();

TopoDS_Shape S2 = BRepPrimAPI_MakeBox(gp_Pnt(500, 0, 0), 220, 140, 180).Shape();
BRepOffsetAPI_MakeOffsetShape aShapeMaker2;
aShapeMaker2.PerformByJoin(S2,-40,0.01,
BRepOffset_Skin,Standard_False,Standard_False,GeomAbs_Arc);
TopoDS_Shape anOffsetShape2 = aShapeMaker2.Shape();
有厚度的实体
TopoDS_Shape S1 = BRepPrimAPI_MakeBox(150, 200, 110).Shape();
TopTools_ListOfShape aList;
TopExp_Explorer Ex(S1,TopAbs_FACE);
Ex.Next();	//this is the front face
TopoDS_Shape aFace = Ex.Current();
aList.Append(aFace);

BRepOffsetAPI_MakeThickSolid aSolidMaker;
aSolidMaker.MakeThickSolidByJoin(S1,aList,10,0.01);
TopoDS_Shape aThickSolid = aSolidMaker.Shape();
边界曲面
Bezier曲面
Standard_CString aName = "BezierSurface";
// Create a BezierSurface
TColgp_Array2OfPnt aPoles(1,2,1,4); // 8 points
TColStd_Array2OfReal aWeights(1,2,1,4);
// initializing array of points
aPoles.SetValue(1,1,gp_Pnt(0,10,0));     aPoles.SetValue(1,2,gp_Pnt(3.3,6.6,3));
aPoles.SetValue(1,3,gp_Pnt(6.6,6.6,-3)); aPoles.SetValue(1,4,gp_Pnt(10,10,0));
aPoles.SetValue(2,1,gp_Pnt(0,0,0));      aPoles.SetValue(2,2,gp_Pnt(3.3,3.3,-3));
aPoles.SetValue(2,3,gp_Pnt(6.6,3.3,3));  aPoles.SetValue(2,4,gp_Pnt(10,0,0));  
// scaling poles
for (Standard_Integer i=1; i <= aPoles.ColLength(); i++)
for (Standard_Integer j=1; j <= aPoles.RowLength(); j++)
aPoles(i,j).ChangeCoord() = aPoles(i,j).Coord() * 100 + gp_XYZ(-500,-500,0);
//initializing array of weights
aWeights.SetValue(1,1,1); aWeights.SetValue(1,2,3);
aWeights.SetValue(1,3,9); aWeights.SetValue(1,4,1);
aWeights.SetValue(2,1,1); aWeights.SetValue(2,2,2);
aWeights.SetValue(2,3,5); aWeights.SetValue(2,4,1);
Handle(Geom_BezierSurface) aSurface =
new Geom_BezierSurface(aPoles, aWeights);
B样条曲面
 // Define points.
  gp_Pnt aPnt1(0.0, 0.0, 0.0);
  gp_Pnt aPnt2(5.0, 5.0, 0.0);
  gp_Pnt aPnt3(10.0, 5.0, 0.0);
  gp_Pnt aPnt4(15.0, 0.0, 0.0);

  // Add points to the curve poles array.
  TColgp_Array1OfPnt aPoles(1, 4);
  aPoles.SetValue(1, aPnt1);
  aPoles.SetValue(2, aPnt2);
  aPoles.SetValue(3, aPnt3);
  aPoles.SetValue(4, aPnt4);

  // Define BSpline weights.
  TColStd_Array1OfReal aBSplineWeights(1, 4);
  aBSplineWeights.SetValue(1, 1.0);
  aBSplineWeights.SetValue(2, 0.5);
  aBSplineWeights.SetValue(3, 0.5);
  aBSplineWeights.SetValue(4, 1.0);

  // Define knots.
  TColStd_Array1OfReal aKnots(1, 2);
  aKnots.SetValue(1, 0.0);
  aKnots.SetValue(2, 1.0);

  // Define multiplicities.
  TColStd_Array1OfInteger aMults(1, 2);
  aMults.SetValue(1, 4);
  aMults.SetValue(2, 4);

  // Define BSpline degree and periodicity.
  Standard_Integer aDegree = 3;
  Standard_Boolean aPeriodic = Standard_False;

  // Create a BSpline curve.
  Handle(Geom_BSplineCurve) aBSplineCurve = new Geom_BSplineCurve(
    aPoles, aBSplineWeights, aKnots, aMults, aDegree, aPeriodic);
线性拉伸曲面
gp_Pnt P1(0,0,1);
gp_Pnt P2(1,2,2);
gp_Pnt P3(2,3,3);
gp_Pnt P4(4,3,4);
gp_Pnt P5(5,5,5);
TColgp_Array1OfPnt array (1,5);
array.SetValue(1,P1);
array.SetValue(2,P2);
array.SetValue(3,P3);
array.SetValue(4,P4);
array.SetValue(5,P5);
Handle(Geom_BSplineCurve) aCurve =
GeomAPI_PointsToBSpline(array).Curve();
gp_Dir aDir(1,2,3);
Handle(Geom_SurfaceOfLinearExtrusion) SOLE =
new Geom_SurfaceOfLinearExtrusion(aCurve,aDir);

Handle(Geom_RectangularTrimmedSurface) aTrimmedSurface =
new Geom_RectangularTrimmedSurface(SOLE,-10,10,false);
曲面延展
TColgp_Array1OfPnt array1 (1,5);
array1.SetValue(1,gp_Pnt (-4,5,5 ));
array1.SetValue(2,gp_Pnt (-3,6,6 ));
array1.SetValue(3,gp_Pnt (-1,6,7 ));
array1.SetValue(4,gp_Pnt (0,8,8));
array1.SetValue(5,gp_Pnt (2,9,9));
Handle(Geom_BSplineCurve) SPL1 =
GeomAPI_PointsToBSpline(array1).Curve();

TColgp_Array1OfPnt array2 (1,5);
array2.SetValue(1,gp_Pnt (-4,5,2 ));
array2.SetValue(2,gp_Pnt (-3,6,3 ));
array2.SetValue(3,gp_Pnt (-1,7,4 ));
array2.SetValue(4,gp_Pnt (0,8,5));
array2.SetValue(5,gp_Pnt (2,9,6));
Handle(Geom_BSplineCurve) SPL2 =
GeomAPI_PointsToBSpline(array2).Curve();

GeomFill_FillingStyle Type = GeomFill_StretchStyle;
GeomFill_BSplineCurves aGeomFill1(SPL1,SPL2,Type);
Handle(Geom_BSplineSurface) aGeomSurface = aGeomFill1.Surface();

Handle(Geom_BoundedSurface) aTranslatedGeomSurface =
Handle(Geom_BoundedSurface)::DownCast(aGeomSurface->Copy());

Standard_Real extension = 3;
Standard_Integer continuity = 2;
Standard_Boolean Udirection = Standard_True;
Standard_Boolean after = Standard_True;
GeomLib::ExtendSurfByLength (aTranslatedGeomSurface,
extension,continuity,Udirection,after);
裁剪曲面
gp_Pnt P; 
gp_Ax3 theAxe(gp::XOY());
gp_Pln PL(theAxe); 
Handle(Geom_Plane) aPlane = GC_MakePlane(PL).Value();
Handle(Geom_RectangularTrimmedSurface) aSurface= new Geom_RectangularTrimmedSurface(aPlane,-8.,8.,-12.,12.);

特征

线性拉伸
BRepBuilderAPI_MakeWire mkw;
gp_Pnt p1 = gp_Pnt(0.,0.,0.);
gp_Pnt p2 = gp_Pnt(200.,0.,0.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
p1 = p2;
p2 = gp_Pnt(200.,0.,50.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
p1 = p2;
p2 = gp_Pnt(50.,0.,50.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
p1 = p2;
p2 = gp_Pnt(50.,0.,200.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
p1 = p2;
p2 = gp_Pnt(0.,0.,200.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
p1 = p2;
mkw.Add(BRepBuilderAPI_MakeEdge(p2,gp_Pnt(0.,0.,0.)));

TopoDS_Shape S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()), 
gp_Vec(gp_Pnt(0.,0.,0.),gp_Pnt(0.,100.,0.)));

TopoDS_Wire W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50.,45.,100.),
gp_Pnt(100.,45.,50.)));	
Handle(Geom_Plane) aplane = new Geom_Plane(0.,1.,0.,-45.);
BRepFeat_MakeLinearForm aform(S, W, aplane, gp_Vec(0.,10.,0.), gp_Vec(0.,0.,0.),
1, Standard_True);
aform.Perform(/*10.*/); // new in 2.0

TopoDS_Shape res = aform.Shape();
拉伸
TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-200.,-200.,0.));
TopoDS_Shape S1 = BRepPrimAPI_MakePrism(V1,gp_Vec(0.,0.,100.));

TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gp_Pnt(-150.,-150,0.), gp_Pnt(-50.,-50,0.));
TopoDS_Shape S2 = BRepPrimAPI_MakePrism(E,gp_Vec(0.,0.,100.));

TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,0.,0.), gp_Pnt(50.,0.,0.));
TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,0.,0.), gp_Pnt(50.,50.,0.));
TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,50.,0.), gp_Pnt(0.,0.,0.));
TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3);
TopoDS_Shape S3 = BRepPrimAPI_MakePrism(W,gp_Vec(0.,0.,100.));

gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.),gp_Dir(0.,0.,1.)), 80.);
TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);
TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()),Wc);
TopoDS_Shape S4 = BRepPrimAPI_MakePrism(F,gp_Vec(0.,0.,100.));
旋转
TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-200.,-200.,0.));
gp_Ax1 axe = gp_Ax1(gp_Pnt(-170.,-170.,0.),gp_Dir(0.,0.,1.));
Handle(Geom_Axis1Placement) Gax1 = new Geom_Axis1Placement(axe);
TopoDS_Shape S1 = BRepPrimAPI_MakeRevol(V1,axe);

TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gp_Pnt(-120.,-120,0.), gp_Pnt(-120.,-120,100.));
axe = gp_Ax1(gp_Pnt(-100.,-100.,0.),gp_Dir(0.,0.,1.));
Handle(Geom_Axis1Placement) Gax2 = new Geom_Axis1Placement(axe);
TopoDS_Shape S2 = BRepPrimAPI_MakeRevol(E,axe);


TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,0.,0.), gp_Pnt(50.,0.,0.));
TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,0.,0.), gp_Pnt(50.,50.,0.));
TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,50.,0.), gp_Pnt(0.,0.,0.));
TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3);
axe = gp_Ax1(gp_Pnt(0.,0.,30.),gp_Dir(0.,1.,0.));
Handle(Geom_Axis1Placement) Gax3 = new Geom_Axis1Placement(axe);
TopoDS_Shape S3 = BRepPrimAPI_MakeRevol(W,axe, 210.*M_PI/180);


gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.),gp_Dir(0.,0.,1.)), 80.);
TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);
TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()),Wc);
axe = gp_Ax1(gp_Pnt(290,290.,0.),gp_Dir(0.,1,0.));
Handle(Geom_Axis1Placement) Gax4 = new Geom_Axis1Placement(axe);
TopoDS_Shape S4 = BRepPrimAPI_MakeRevol(F,axe, 90.*M_PI/180);
扫掠
凹槽
管道
TopoDS_Shape S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape();

TopExp_Explorer Ex;
Ex.Init(S,TopAbs_FACE);
Ex.Next();
Ex.Next();
TopoDS_Face F1 = TopoDS::Face(Ex.Current());
Handle(Geom_Surface) surf = BRep_Tool::Surface(F1);
BRepBuilderAPI_MakeWire MW1;
gp_Pnt2d p1,p2;
p1 = gp_Pnt2d(100.,100.);
p2 = gp_Pnt2d(200.,100.);
Handle(Geom2d_Line) aline = GCE2d_MakeLine(p1,p2).Value();
MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
p1 = p2;
p2 = gp_Pnt2d(150.,200.);
aline = GCE2d_MakeLine(p1,p2).Value();
MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
p1 = p2;
p2 = gp_Pnt2d(100.,100.);
aline = GCE2d_MakeLine(p1,p2).Value();
MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
BRepBuilderAPI_MakeFace MKF1;
MKF1.Init(surf,Standard_False, Precision::Confusion());
MKF1.Add(MW1.Wire());
TopoDS_Face FP = MKF1.Face();
BRepLib::BuildCurves3d(FP);
TColgp_Array1OfPnt CurvePoles(1,3);
gp_Pnt pt = gp_Pnt(150.,0.,150.);
CurvePoles(1) = pt;
pt = gp_Pnt(200.,-100.,150.);
CurvePoles(2) = pt;
pt = gp_Pnt(150.,-200.,150.);
CurvePoles(3) = pt;
Handle(Geom_BezierCurve) curve = new Geom_BezierCurve(CurvePoles);
TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);
TopoDS_Wire W = BRepBuilderAPI_MakeWire(E);
BRepFeat_MakePipe MKPipe(S,FP,F1,W,1,Standard_True);
MKPipe.Perform();
TopoDS_Shape res1 = MKPipe.Shape();
管道偏移
TColgp_Array1OfPnt CurvePoles(1,4);
gp_Pnt pt = gp_Pnt(0.,0.,0.);
CurvePoles(1) = pt;
pt = gp_Pnt(20.,50.,0.);
CurvePoles(2) = pt;
pt = gp_Pnt(60.,100.,0.);
CurvePoles(3) = pt;
pt = gp_Pnt(150.,0.,0.);
CurvePoles(4) = pt;
Handle(Geom_BezierCurve) curve = new Geom_BezierCurve(CurvePoles);
TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);
TopoDS_Wire W = BRepBuilderAPI_MakeWire(E);

gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(0.,0.,0.),gp_Dir(0.,1.,0.)),10.);
TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);
TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::ZOX()),Wc);
TopoDS_Shape S = BRepOffsetAPI_MakePipe(W,F);
倒直角
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(60,200,70).Shape();
BRepFilletAPI_MakeChamfer MC(theBox);
// add all the edges to chamfer
TopTools_IndexedDataMapOfShapeListOfShape M;
TopExp::MapShapesAndAncestors(theBox,TopAbs_EDGE,TopAbs_FACE,M);
for (Standard_Integer i = 1;i<=M.Extent();i++) {
	TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
	TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
	MC.Add(5,5,E,F);
	}

TopoDS_Shape ChanfrenedBox = MC.Shape();
倒直角、获取生成形状、移除倒直角
Standard_Real aSizeX = 8.0;
Standard_Real aSizeY = 10.0;
Standard_Real aSizeZ = 15.0;
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
BRepFilletAPI_MakeChamfer anAlgo(aBox);
TopTools_IndexedMapOfShape anEdges;
TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges);
TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(5));
Standard_Real aDist = 4.0;
anAlgo.Add(aDist, anEdge);
anAlgo.Build();
TopoDS_Shape aBoxWithChamfer = anAlgo.Shape();
const TopTools_ListOfShape& aGenShapes = anAlgo.Generated(anEdge);
Standard_ASSERT_VOID(!aGenShapes.IsEmpty(), "Chamfer face is expected!");
for (TopTools_ListOfShape::Iterator anIt(aGenShapes); anIt.More(); anIt.Next())
{
	TopoDS_Shape aShapeGenerated = anIt.Value();
}
BRepAlgoAPI_Defeaturing aDefeatAlgo;
aDefeatAlgo.SetShape(aBoxWithChamfer);
aDefeatAlgo.AddFaceToRemove(aGenShapes.First());

// Remove the chamfer.
aDefeatAlgo.Build();
圆角
边倒圆角
TopoDS_Shape Box = BRepPrimAPI_MakeBox(gp_Pnt(-400,0,0),200,230,180).Shape();
BRepFilletAPI_MakeFillet fillet(Box);
for (TopExp_Explorer ex(Box,TopAbs_EDGE); ex.More(); ex.Next()) {
	TopoDS_Edge Edge =TopoDS::Edge(ex.Current());
	fillet.Add(20,Edge);
}
TopoDS_Shape blendedBox = fillet.Shape();

BRepFilletAPI_MakeFillet Rake(Box);
TopExp_Explorer ex(theBox,TopAbs_EDGE);
ex.Next();
ex.Next();
ex.Next();
ex.Next();
Rake.Add(8,50,TopoDS::Edge(ex.Current()));
Rake.Build();
if (Rake.IsDone() ){
	TopoDS_Shape evolvedBox = Rake.Shape();
}
点倒圆角
TopoDS_Shape theCylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(-300, 0, 0), gp::DZ()), 100, 200).Shape();
BRepFilletAPI_MakeFillet fillet(theCylinder);
TColgp_Array1OfPnt2d TabPoint2(1,20);
for (Standard_Integer i=0; i<=19; i++) {
	gp_Pnt2d Point2d(i*2*M_PI/19,60*cos(i*M_PI/19-M_PI/2)+10);
	TabPoint2.SetValue(i+1,Point2d);
}
TopExp_Explorer exp2(theCylinder,TopAbs_EDGE);
fillet.Add(TabPoint2,TopoDS::Edge(exp2.Current()));
fillet.Build();
if (fillet.IsDone() ){
	TopoDS_Shape LawEvolvedCylinder = fillet.Shape();
}


gp_Pnt P(350,0,0);
TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape();
BRepFilletAPI_MakeFillet afillet(theBox2);
TColgp_Array1OfPnt2d TabPoint(1,6);
gp_Pnt2d P1(0.,8.);
gp_Pnt2d P2(0.2,16.);
gp_Pnt2d P3(0.4,25.);
gp_Pnt2d P4(0.6,55.);
gp_Pnt2d P5(0.8,28.);
gp_Pnt2d P6(1.,20.);
TabPoint.SetValue(1,P1);
TabPoint.SetValue(2,P2);
TabPoint.SetValue(3,P3);
TabPoint.SetValue(4,P4);
TabPoint.SetValue(5,P5);
TabPoint.SetValue(6,P6);
TopExp_Explorer exp(theBox2,TopAbs_EDGE);
exp.Next();
exp.Next();
exp.Next();
exp.Next();

afillet.Add(TabPoint, TopoDS::Edge(exp.Current()));

afillet.Build();
if (afillet.IsDone() ){
	TopoDS_Shape LawevolvedBox = afillet.Shape();
}
两个半径的圆角
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 200, 200).Shape();
BRepFilletAPI_MakeFillet Rake(theBox);
TopExp_Explorer ex(theBox,TopAbs_EDGE);
ex.Next();
ex.Next();
ex.Next();
ex.Next();
Rake.Add(8,50,TopoDS::Edge(ex.Current()));
Rake.Build();
拔模
TopoDS_Shape S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape();
BRepOffsetAPI_DraftAngle adraft(S);
TopExp_Explorer Ex;
for (Ex.Init(S,TopAbs_FACE); Ex.More(); Ex.Next()) {
    TopoDS_Face F = TopoDS::Face(Ex.Current());
    Handle(Geom_Plane) surf = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(F));
    gp_Pln apln = surf->Pln();
    gp_Dir dirF = apln.Axis().Direction();
    if (dirF.IsNormal(gp_Dir(0.,0.,1.),Precision::Angular()))
    adraft.Add(F, gp_Dir(0.,0.,1.), 15.*M_PI/180, gp_Pln(gp::XOY()));
}
放样
TopoDS_Wire W1 = BRepBuilderAPI_MakeWire(E1);

gp_Circ c2 = gp_Circ(gp_Ax2(gp_Pnt(-10.,0.,-0.),gp_Dir(0.,0.,1.)),40.);
TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(c2);
TopoDS_Wire W2 = BRepBuilderAPI_MakeWire(E2);

gp_Circ c3 = gp_Circ(gp_Ax2(gp_Pnt(-75.,0.,100.),gp_Dir(0.,0.,1.)),40.);
TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(c3);
TopoDS_Wire W3 = BRepBuilderAPI_MakeWire(E3);

gp_Circ c4= gp_Circ(gp_Ax2(gp_Pnt(0.,0.,200.),gp_Dir(0.,0.,1.)),40.);
TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(c4);
TopoDS_Wire W4 = BRepBuilderAPI_MakeWire(E4);

BRepOffsetAPI_ThruSections generator(Standard_False,Standard_True)	;
generator.AddWire(W1);
generator.AddWire(W2);
generator.AddWire(W3);
generator.AddWire(W4);
generator.Build();
TopoDS_Shape S1 = generator.Shape();

gp_Circ c1b = gp_Circ(gp_Ax2(gp_Pnt(100.,0.,-100.),gp_Dir(0.,0.,1.)),40.);
TopoDS_Edge E1b = BRepBuilderAPI_MakeEdge(c1b);
TopoDS_Wire W1b = BRepBuilderAPI_MakeWire(E1b);

gp_Circ c2b = gp_Circ(gp_Ax2(gp_Pnt(210.,0.,-0.),gp_Dir(0.,0.,1.)),40.);
TopoDS_Edge E2b = BRepBuilderAPI_MakeEdge(c2b);
TopoDS_Wire W2b = BRepBuilderAPI_MakeWire(E2b);

gp_Circ c3b = gp_Circ(gp_Ax2(gp_Pnt(275.,0.,100.),gp_Dir(0.,0.,1.)),40.);
TopoDS_Edge E3b = BRepBuilderAPI_MakeEdge(c3b);
TopoDS_Wire W3b = BRepBuilderAPI_MakeWire(E3b);

gp_Circ c4b= gp_Circ(gp_Ax2(gp_Pnt(200.,0.,200.),gp_Dir(0.,0.,1.)),40.);
TopoDS_Edge E4b = BRepBuilderAPI_MakeEdge(c4b);
TopoDS_Wire W4b = BRepBuilderAPI_MakeWire(E4b);

BRepOffsetAPI_ThruSections generatorb(Standard_True,Standard_False);
generatorb.AddWire(W1b);
generatorb.AddWire(W2b);
generatorb.AddWire(W3b);
generatorb.AddWire(W4b);
generatorb.Build();
TopoDS_Shape S2 = generatorb.Shape();
螺旋线

拓扑

点、边、线、面、壳的创建
TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-200.,-200.,0.));

TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gp_Pnt(-150.,-150,0.), gp_Pnt(-50.,-50,0.));
gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.),gp_Dir(0.,0.,1.)), 80.);
TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);
TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()),Wc);

TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,0.,0.), gp_Pnt(50.,0.,0.));
TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,0.,0.), gp_Pnt(50.,50.,0.));
TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,50.,0.), gp_Pnt(0.,0.,0.));
TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3);

Handle (Geom_Surface) BSpline = ...;
TopoDS_Shell aShell = BRepBuilderAPI_MakeShell(BSpline);

TopoDS_Shell Sh;
B.MakeShell(Sh);
B.Add(Sh,FXMAX);
B.Add(Sh,FXMIN);
B.Add(Sh,FYMAX);
B.Add(Sh,FYMIN);
B.Add(Sh,FZMAX);
B.Add(Sh,FZMIN);
TopoDS_Solid Sol;
 BRep_Builder B;
B.MakeSolid(Sol);
B.Add(Sol,Sh1);
B.Add(Sol,Sh2);
组合体
BRep_Builder builder;
TopoDS_Compound Comp;
builder.MakeCompound(Comp);

TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(-20,10,-30));
builder.Add(Comp,aVertex);

gp_Lin line(gp_Ax1(gp_Pnt(10,10,10),gp_Dir(1,0,0)));
TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(line,-20,10);
builder.Add(Comp,anEdge);

gp_Sphere sphere (gp_Ax3(gp_Pnt(-80,0,0),gp_Dir(1,0,0)),150);
TopoDS_Face aFace = BRepBuilderAPI_MakeFace(sphere,0.1,0.7,0.2,0.9);
builder.Add(Comp,aFace);

TopoDS_Shape aBox = BRepPrimAPI_MakeBox(gp_Pnt(-60, 0, 0), 30, 60, 40).Shape();
builder.Add(Comp,aBox);

包围盒

AABB
Standard_Real radius = 3;
Handle(Geom2d_Circle) circle =
    new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(-7,2),gp_Dir2d(1,0)),radius);

Handle(Geom2d_TrimmedCurve) C = new Geom2d_TrimmedCurve(circle,1,5);
Bnd_Box2d aCBox;
Geom2dAdaptor_Curve GACC (C);
BndLib_Add2dCurve::Add (GACC,Precision::Approximation(),aCBox);

Bnd_Box aBox;
Standard_Real radius = 100;
gp_Ax2 anAxis(gp_Pnt(0,0,0),gp_Dir(1,2,-5));

Handle(Geom_Circle) C =
    new Geom_Circle(anAxis,radius);
GeomAdaptor_Curve GAC (C);
BndLib_Add3dCurve::Add (GAC,Precision::Approximation(),aBox);

  TColgp_Array2OfPnt aPoints(1, 4, 1, 4);
  for (Standard_Integer i = 1; i <= 4; ++i)
  {
    gp_Pnt aPnt;
    aPnt.SetX(5.0 * i);
    for (Standard_Integer j = 1; j <= 4; ++j)
    {
      aPnt.SetY(5.0 * j);
      if (1 < i && i < 4 && 1 < j && j < 4)
      {
        aPnt.SetZ(5.0);
      }
      else
      {
        aPnt.SetZ(0.0);
      }
      aPoints.SetValue(i, j, aPnt);
    }
  }

  // Make a BSpline surface from the points array.
  Handle(Geom_BSplineSurface) aBSplineSurf = GeomAPI_PointsToBSplineSurface(aPoints).Surface();
  myResult << "Geom_BSplineSurface was created" << std::endl;

  // Compute BSpline surface bounding box.
  Bnd_Box aBndBox;
  BndLib_AddSurface::AddOptimal(GeomAdaptor_Surface(aBSplineSurf), Precision::Confusion(), aBndBox);
OBB

几何属性

属性数据

椭圆的面积、离心率、焦距、焦点
gp_Elips anElips(gp_Ax2(gp_Pnt(), gp_Dir(1.0, 0.0, 0.0)), 20.0, 10.0);
Standard_Real anArea = anElips.Area();
// Returns the eccentricity of the ellipse between 0.0 and 1.0
// If f is the distance between the center of the ellipse and the Focus1 then
// the eccentricity e = f / MajorRadius. Returns 0 if MajorRadius = 0.
Standard_Real anEccentricity = anElips.Eccentricity();
// Returns the distance between the center of the ellipse and focus1 or focus2.
Standard_Real aFocal = anElips.Focal();
// Returns p = (1 - e * e) * MajorRadius where e is the eccentricity
// of the ellipse. Returns 0 if MajorRadius = 0.
Standard_Real aParameter = anElips.Parameter();
gp_Pnt aCenter = anElips.Location();
gp_Pnt aFocus1 = anElips.Focus1();
gp_Pnt aFocus2 = anElips.Focus2();
实体的质心、体积、惯性矩
TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.).Shape();
Handle(AIS_Shape) ais1 = new AIS_Shape(S);
myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False); 
myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);   
myAISContext->Display(ais1,Standard_False);
Fit();


GProp_GProps System;
BRepGProp::VolumeProperties(S,System);
gp_Pnt G = System.CentreOfMass ();
Standard_Real Volume = System.Mass();
gp_Mat I = System.MatrixOfInertia();
曲面的质心、体积、惯性矩
TColgp_Array1OfPnt Pnts1(1,3);
TColgp_Array1OfPnt Pnts2(1,3);
TColgp_Array1OfPnt Pnts3(1,3);
TColgp_Array1OfPnt Pnts4(1,3);

Pnts1(1) = gp_Pnt(0,0,0);
Pnts1(2) = gp_Pnt(5,0,0);
Pnts1(3) = gp_Pnt(10,10,0);

Pnts2(1) = gp_Pnt(10,10,0);
Pnts2(2) = gp_Pnt(5,12,4);
Pnts2(3) = gp_Pnt(0,15,10);

Pnts3(1) = gp_Pnt(0,15,10);
Pnts3(2) = gp_Pnt(-12,10,11);
Pnts3(3) = gp_Pnt(-10,5,13);

Pnts4(1) = gp_Pnt(-10,5,13);
Pnts4(2) = gp_Pnt(-2,-2,2);
Pnts4(3) = gp_Pnt(0,0,0);

GeomAPI_PointsToBSpline PTBS1(Pnts1);
GeomAPI_PointsToBSpline PTBS2(Pnts2);
GeomAPI_PointsToBSpline PTBS3(Pnts3);
GeomAPI_PointsToBSpline PTBS4(Pnts4);
Handle(Geom_BSplineCurve) C1 = PTBS1.Curve();
Handle(Geom_BSplineCurve) C2 = PTBS2.Curve();
Handle(Geom_BSplineCurve) C3 = PTBS3.Curve();
Handle(Geom_BSplineCurve) C4 = PTBS4.Curve();

GeomFill_BSplineCurves fill; 
fill.Init(C1,C2,C3,C4,GeomFill_CoonsStyle);
Handle(Geom_BSplineSurface) BSS = fill.Surface();

TopoDS_Shape S = BRepBuilderAPI_MakeFace(BSS, Precision::Confusion()).Face();

GProp_GProps System;
BRepGProp::SurfaceProperties(S,System);
gp_Pnt G = System.CentreOfMass ();
Standard_Real Area = System.Mass();
gp_Mat I = System.MatrixOfInertia();
曲线的质心、体积、惯性矩
TColgp_Array1OfPnt Points1(1,4);
Points1.SetValue(1,gp_Pnt(0,0,0));
Points1.SetValue(2,gp_Pnt(2,1,0));
Points1.SetValue(3,gp_Pnt(4,0,0));
Points1.SetValue(4,gp_Pnt(6,2,0));
GeomAPI_PointsToBSpline PTBS1(Points1);
Handle(Geom_BSplineCurve) BSC1 = PTBS1.Curve();
TopoDS_Edge S = BRepBuilderAPI_MakeEdge(BSC1).Edge();

GProp_GProps System;
BRepGProp::LinearProperties(S,System);
gp_Pnt G = System.CentreOfMass ();
Standard_Real Length = System.Mass();
gp_Mat I = System.MatrixOfInertia();
曲线的主惯性矩、主回转半径
gp_Circ aCirc(gp::XOY(), 1.0);
// Make a circular edge from the 1st quoter in the parametric space.
TopoDS_Edge aShape = BRepBuilderAPI_MakeEdge(aCirc, 0.0, M_PI);
myResult << "TopoDS_Edge on the circle's 1st quoter" << std::endl
<< "with the center at [ "
<< aCirc.Location().X() << ", " << aCirc.Location().Y() << ", " << aCirc.Location().Z()
<< " ] and R = " << aCirc.Radius() << " was created in red" << std::endl
<< std::endl;

// Retrieve linear properties from the edge.
GProp_GProps aGProps;
BRepGProp::LinearProperties(aShape, aGProps);
Standard_Real aLength = aGProps.Mass();
gp_Pnt aCOM = aGProps.CentreOfMass();
Standard_Real anIx, anIy, anIz;
aGProps.StaticMoments(anIx, anIy, anIz);
gp_Mat aMOI = aGProps.MatrixOfInertia();
myResult << "Linear properties:" << std::endl
<< "  Length            = " << aLength << std::endl
<< "  Center of mass    = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl
<< "  Static moments    = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl
<< "  Matrix of inertia = [ "
<< aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl
<< std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl
<< std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl;
GProp_PrincipalProps aPProps = aGProps.PrincipalProperties();
Standard_Real anIxx, anIyy, anIzz;
aPProps.Moments(anIxx, anIyy, anIzz);
Standard_Real aRxx, aRyy, aRzz;
aPProps.RadiusOfGyration(aRxx, aRyy, aRzz);
myResult << "Principal properties:" << std::endl
<< "  Has symmetric axis  : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl
<< "  Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl
<< "  Moments of inertia  = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl
<< "  Radius of gyration  = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl;
if (!aPProps.HasSymmetryPoint())
{
	const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia();
}
曲面的主惯性矩、主回转半径
gp_Cylinder aCyl(gp::XOY(), 1.0);
TopoDS_Face aShape = BRepBuilderAPI_MakeFace(aCyl, 0.0, M_PI, -1.0, +1.0).Face();
myResult << "TopoDS_Face on the cylinder R = " << aCyl.Radius() << std::endl
    << "with axis [ " << aCyl.Position().Direction().X() << ", " << aCyl.Position().Direction().Y() << ", " << aCyl.Position().Direction().Z() << " ]" << std::endl
    << "limited in length [-1 ... +1] was created in red" << std::endl;

// Retrieve surface properties from the face.
GProp_GProps aGProps;
BRepGProp::SurfaceProperties(aShape, aGProps);
Standard_Real aArea = aGProps.Mass();
gp_Pnt aCOM = aGProps.CentreOfMass();
Standard_Real anIx, anIy, anIz;
aGProps.StaticMoments(anIx, anIy, anIz);
gp_Mat aMOI = aGProps.MatrixOfInertia();
myResult << "Linear properties:" << std::endl
    << "  Area              = " << aArea << std::endl
    << "  Center of mass    = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl
    << "  Static moments    = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl
    << "  Matrix of inertia = [ "
    << aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl
    << std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl
    << std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl;
GProp_PrincipalProps aPProps = aGProps.PrincipalProperties();
Standard_Real anIxx, anIyy, anIzz;
aPProps.Moments(anIxx, anIyy, anIzz);
Standard_Real aRxx, aRyy, aRzz;
aPProps.RadiusOfGyration(aRxx, aRyy, aRzz);
myResult << "Principal properties:" << std::endl
    << "  Has symmetric axis  : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl
    << "  Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl
    << "  Moments of inertia  = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl
    << "  Radius of gyration  = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl;
if (!aPProps.HasSymmetryPoint())
{
    const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia();
}
体的主惯性矩、主回转半径
gp_Pnt aPnt1(-0.5, -0.6, -0.7);
gp_Pnt aPnt2(+0.8, +0.9, +1.0);
TopoDS_Shape aShape = BRepPrimAPI_MakeBox(aPnt1, aPnt2);
myResult << "Box with corners [" << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< "] and [" << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< "] was created in red" << std::endl;

// Retrieve volume properties from the face.
GProp_GProps aGProps;
BRepGProp::VolumeProperties(aShape, aGProps);
Standard_Real aVolume = aGProps.Mass();
gp_Pnt aCOM = aGProps.CentreOfMass();
Standard_Real anIx, anIy, anIz;
aGProps.StaticMoments(anIx, anIy, anIz);
gp_Mat aMOI = aGProps.MatrixOfInertia();
myResult << "Linear properties:" << std::endl
<< "  Volume            = " << aVolume << std::endl
<< "  Center of mass    = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl
<< "  Static moments    = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl
<< "  Matrix of inertia = [ "
<< aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl
<< std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl
<< std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl;
GProp_PrincipalProps aPProps = aGProps.PrincipalProperties();
Standard_Real anIxx, anIyy, anIzz;
aPProps.Moments(anIxx, anIyy, anIzz);
Standard_Real aRxx, aRyy, aRzz;
aPProps.RadiusOfGyration(aRxx, aRyy, aRzz);
myResult << "Principal properties:" << std::endl
<< "  Has symmetric axis  : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl
<< "  Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl
<< "  Moments of inertia  = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl
<< "  Radius of gyration  = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl;
if (!aPProps.HasSymmetryPoint())
{
	const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia();
}

导数

2d导数

Handle(Geom2d_Curve) C;
gp_Pnt2d P;                                             
gp_Vec2d V;                                             
C->D1(param,P,V); 

法向

计算曲面一点的法向
gp_Sphere aSphere(gp::XOY(), 4.0);
TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aSphere);

// Make a surface adaptor.
BRepAdaptor_Surface aSurfAdaptor(aFace);

Standard_Real anU = 0.0, aV = 0.0;
gp_Pnt aPnt;
gp_Vec aDU, aDV;
aSurfAdaptor.D1(anU, aV, aPnt, aDU, aDV);
gp_Vec aNorm = aDU.Crossed(aDV);
Standard_ASSERT_VOID(aNorm.Magnitude() > Precision::Confusion(), "Non zero vector is expected!");
aNorm.Normalize();

切向

Standard_Real radius = 5;                          
Handle(Geom2d_Circle) C = ...;          
Standard_Real param = 1.2*M_PI;                      
Geom2dLProp_CLProps2d CLP(C,param,2,Precision::PConfusion());           
gp_Dir2d D;                                    
CLP.Tangent(D);  

长度

曲率

梯度

挠率

连续性

TColgp_Array1OfPnt2d array (1,5); // sizing array
array.SetValue(1,gp_Pnt2d (-4,0)); array.SetValue(2,gp_Pnt2d (-7,2));
array.SetValue(3,gp_Pnt2d (-6,3)); array.SetValue(4,gp_Pnt2d (-4,3));
array.SetValue(5,gp_Pnt2d (-3,5));
Handle(Geom2d_BSplineCurve) SPL1 = Geom2dAPI_PointsToBSpline(array);
Standard_Real dist = 1;
Handle(Geom2d_OffsetCurve) OC = new Geom2d_OffsetCurve(SPL1,dist);
Standard_Boolean result = OC->IsCN(2);
Standard_Real dist2 = 1.5;
Handle(Geom2d_OffsetCurve) OC2 = new Geom2d_OffsetCurve(SPL1,dist2);
Standard_Boolean result2 = OC2->IsCN(2);

坐标

根据弧长求坐标
Standard_Real radius = 5;
Handle(Geom2d_Circle) C =  new Geom2d_Circle(gp::OX2d(),radius);                    
Geom2dAdaptor_Curve GAC (C);
Standard_Real startparam = 10*M_PI/180;
Standard_Real abscissa = 45*M_PI/180;
// abscissa is the distance along the curve from startparam
GCPnts_AbscissaPoint AP (GAC, abscissa, startparam);
gp_Pnt2d P2;
if (AP.IsDone()){C->D0(AP.Parameter(),P2);}
获取曲线上等间隔数部分的点
gp_Pnt2d P;
Standard_Real radius = 5;
Handle(Geom2d_Circle) C =
    new Geom2d_Circle(gp::OX2d(),radius);
Geom2dAdaptor_Curve GAC (C);
Standard_Real abscissa = 3;
GCPnts_UniformAbscissa UA (GAC,abscissa);
TColgp_SequenceOfPnt2d aSequence;
if (UA.IsDone())
{                                                     
    Standard_Real N = UA.NbPoints();
    Standard_Integer count = 1;
    for(;count<=N;count++)
    {                                                  
        C->D0(UA.Parameter(count),P);
        //Standard_Real Parameter = UA.Parameter(count);
        // append P in a Sequence
        aSequence.Append(P);
    }                                                   
}           
根据曲线曲面参数求坐标
Standard_Real radius = 5;
Handle(Geom_Surface) SP = new Geom_SphericalSurface(gp_Ax3(gp::XOY()),radius);
Standard_Real u = 2;
Standard_Real v = 3;
gp_Pnt P = SP->Value(u,v);   

参数

极值

曲线-曲线最短距离
//----------- Build TC1 -----------------------
gp_Pnt2d P1(0,0);  gp_Pnt2d P2(2,6);
gp_Dir2d V1 = gp::DY2d();
Handle(Geom2d_TrimmedCurve) TC1 =  GCE2d_MakeSegment(P1,V1,P2);
Standard_Real FP1 = TC1->FirstParameter();
Standard_Real LP1 = TC1->LastParameter();
//----------- Build TC2 -----------------------
gp_Pnt2d P3(-9,6.5);       gp_Dir2d V2 = gp::DX2d();
Handle(Geom2d_TrimmedCurve) TC2 = GCE2d_MakeSegment(P3,V2,P2);
Standard_Real FP2 = TC1->FirstParameter();
Standard_Real LP2 = TC1->LastParameter();
//----------- Extrema TC1 / TC2 ---------------
Geom2dAPI_ExtremaCurveCurve ECC (TC1,TC2, FP1,LP1, FP2,LP2);
Standard_Real shortestdistance =-1;
if (ECC.NbExtrema() != 0)  shortestdistance = ECC.LowerDistance();
//----------- Extrema TC1 / SPL1  -------------                       
Geom2dAPI_ExtremaCurveCurve ECC2 (TC1,SPL1, FP1,LP1, FPSPL1,LPSPL1);
Standard_Real SPL1shortestdistance =-1;
if (ECC2.NbExtrema()!=0) SPL1shortestdistance = ECC2.LowerDistance();
Standard_Integer NbExtrema = ECC2.NbExtrema();
TColgp_Array2OfPnt2d aSolutionArray(1,NbExtrema,1,2);
for(int i=1;i <= NbExtrema; i++)
{                                  
    gp_Pnt2d P1x,P2x;
    ECC2.Points(i,P1x,P2x);
    aSolutionArray(i,1) = P1x;
    aSolutionArray(i,2) = P2x;
}    

历史

几何操作

拓扑对象复制
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ);
TopoDS_Shape aBox = aBoxMake.Shape();
// Make a box copy.
TopoDS_Shape aBoxCopy = BRepBuilderAPI_Copy(aBox);

gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(15.0, 0.0, 0.0));
aBoxCopy.Move(aTrsf1);
拓扑对象平移旋转
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ);
TopoDS_Shape aBox = aBoxMake.Shape();

// Move the box.
gp_Trsf aTrMove; aTrMove.SetTranslation(gp_Vec(15.0, 20.0, 25.0));
TopoDS_Shape aMovedBox = BRepBuilderAPI_Transform(aBox, aTrMove, Standard_True);
myResult << "Moved box in green" << std::endl;

// Rotate the moved box
gp_Trsf aTrRot; aTrRot.SetRotation(gp_Ax1(gp_Pnt(15.0, 20.0, 25.0), gp::DZ()), 3.0 * M_PI_4);
TopoDS_Shape aRotatedBox = BRepBuilderAPI_Transform(aBox, aTrRot, Standard_True);
myResult << "Rotated box in red" << std::endl;

相交

圆锥曲线与二次曲线、平面相交
gp_Pnt P; 
gp_Ax3 theAxe(gp::XOY());
gp_Pln PL(theAxe);                            
Standard_Real MinorRadius = 5;
Standard_Real MajorRadius = 8; 
gp_Elips EL (gp::YOZ(),MajorRadius,MinorRadius);
IntAna_IntConicQuad ICQ                                   
(EL,PL,Precision::Angular(),Precision::Confusion());  
if (ICQ.IsDone()){
    Standard_Integer NbResults = ICQ.NbPoints();
    if (NbResults>0){                                     
        for(Standard_Integer i = 1;i<=NbResults;i++){
            P = ICQ.Point(i); 
            // do something with P here  
        }
    }
}                 
二次曲面和曲线相交
  gp_Lin aLine(gp_Pnt(0.0, 0.0, 10.0), gp_Dir(0.0, 1.0, 0.0));
  gp_Cone aCone(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 0.25*M_PI, 0.0);
  IntAna_Quadric anIntAna_Quadric(aCone);
  IntAna_IntConicQuad anIntAna_IntConicQuad(aLine, anIntAna_Quadric);
  if (anIntAna_IntConicQuad.IsDone())
  {
    for (int i = 1; i <= anIntAna_IntConicQuad.NbPoints(); i++)
    {
      const gp_Pnt& aIntersectionPnt = anIntAna_IntConicQuad.Point(i);
      DisplayPnt(aIntersectionPnt, TCollection_AsciiString(i));
    }
  }
曲线曲线相交
Handle(TColgp_HArray1OfPnt2d) harray = new TColgp_HArray1OfPnt2d (1,5); // sizing harray
harray->SetValue(1,gp_Pnt2d (0,0));
harray->SetValue(2,gp_Pnt2d (-3,1));
harray->SetValue(3,gp_Pnt2d (-2,5));
harray->SetValue(4,gp_Pnt2d (2,9));
harray->SetValue(5,gp_Pnt2d (-4,14));

Geom2dAPI_Interpolate anInterpolation(harray,Standard_False,0.01);
anInterpolation.Perform();
Handle(Geom2d_BSplineCurve) SPL = anInterpolation.Curve();

gp_Pnt2d P1(-1,-2);
gp_Pnt2d P2(0,15);
gp_Dir2d V1 = gp::DY2d();
Handle(Geom2d_TrimmedCurve) TC1 = GCE2d_MakeSegment(P1,V1,P2);

Standard_Real tolerance = Precision::Confusion();
Geom2dAPI_InterCurveCurve ICC (SPL,TC1,tolerance);
Standard_Integer NbPoints =ICC.NbPoints();
gp_Pnt2d PK;

for (Standard_Integer k = 1;k<=NbPoints;k++)
{                                                         
    PK = ICC.Point(k);                                              
    // do something with each intersection point                    
}   
两实体的相交线
TopoDS_Shape atorus = BRepPrimAPI_MakeTorus(120, 20).Shape();
gp_Vec V1(1,1,1);
Standard_Real radius = 120;
Standard_Integer i=-3;

for(i;i<=3;i++)
{
    TopoDS_Shape asphere = BRepPrimAPI_MakeSphere(gp_Pnt(26 * 3 * i, 0, 0), radius).Shape();
    BRepAlgoAPI_Section section(atorus,asphere,Standard_False);
    section.ComputePCurveOn1(Standard_True);
    section.Approximation(TopOpeBRepTool_APPROX);
    section.Build();
}

平面-实体相交
TopoDS_Shape theTorus = BRepPrimAPI_MakeTorus(35, 8).Shape();
gp_Pln aplane(1,0.25,3,4);
Handle (Geom_Plane) thePlane = new Geom_Plane(aplane);
BRepAlgoAPI_Section section(theTorus,thePlane,Standard_False);
section.ComputePCurveOn1(Standard_True);
section.Approximation(TopOpeBRepTool_APPROX);
section.Build();
粘胶
TopoDS_Shape S1 = BRepPrimAPI_MakeBox(gp_Pnt(-500., -500., 0.), gp_Pnt(-100., -250., 300.)).Shape();

TopExp_Explorer Ex1;
Ex1.Init(S1,TopAbs_FACE);
Ex1.Next();
Ex1.Next();
Ex1.Next();
Ex1.Next();
Ex1.Next();
TopoDS_Face F1 = TopoDS::Face(Ex1.Current());
TopoDS_Shape S2 = BRepPrimAPI_MakeBox(gp_Pnt(-400., -400., 300.), gp_Pnt(-200., -300., 500.)).Shape();

TopExp_Explorer Ex2;
Ex2.Init(S2,TopAbs_FACE);
Ex2.Next();
Ex2.Next();
Ex2.Next();
Ex2.Next();
TopoDS_Face F2 = TopoDS::Face(Ex2.Current());
BRepFeat_Gluer glue(S2,S1);
glue.Bind(F2,F1);
TopoDS_Shape res1 = glue.Shape();


TopoDS_Shape S3 = BRepPrimAPI_MakeBox(500., 400., 300.).Shape();

Handle(AIS_Shape) ais3 = new AIS_Shape(S3);
myAISContext->SetColor(ais3,Quantity_NOC_ORANGE,Standard_False); 
myAISContext->SetMaterial(ais3,Graphic3d_NOM_PLASTIC,Standard_False);   
myAISContext->Display(ais3,Standard_False);
const Handle(AIS_InteractiveObject)& anIO3 = ais3;
myAISContext->SetSelected (anIO3, Standard_False);
Fit();
Sleep(1000);

TopExp_Explorer Ex3;
Ex3.Init(S3,TopAbs_FACE);
Ex3.Next();
Ex3.Next();
Ex3.Next();
Ex3.Next();
Ex3.Next();
TopoDS_Face F3 = TopoDS::Face(Ex3.Current());
TopoDS_Shape S4 = BRepPrimAPI_MakeBox(gp_Pnt(0., 0., 300.), gp_Pnt(200., 200., 500.)).Shape();

TopExp_Explorer Ex4;
Ex4.Init(S4,TopAbs_FACE);
Ex4.Next();
Ex4.Next();
Ex4.Next();
Ex4.Next();
TopoDS_Face F4 = TopoDS::Face(Ex4.Current());
BRepFeat_Gluer glue2(S4,S3);
glue2.Bind(F4,F3);
LocOpe_FindEdges CommonEdges(F4,F3);
for (CommonEdges.InitIterator(); CommonEdges.More(); CommonEdges.Next()) 
    glue2.Bind(CommonEdges.EdgeFrom(),CommonEdges.EdgeTo());
TopoDS_Shape res2 = glue2.Shape();

分割

UV参数分割B样条曲面
TColgp_Array1OfPnt array1 (1,5);
array1.SetValue(1,gp_Pnt (-4,0,2 ));
array1.SetValue(2,gp_Pnt (-5,1,0 ));
array1.SetValue(3,gp_Pnt (-6,2,-2 ));
array1.SetValue(4,gp_Pnt (-5,4,-7));
array1.SetValue(5,gp_Pnt (-3,5,-12));

Handle(Geom_BSplineCurve) SPL1 =
GeomAPI_PointsToBSpline(array1).Curve();
Handle(Geom_Curve) FirstSect =
GC_MakeSegment(gp_Pnt(-4,0,2),gp_Pnt(-4,0,10)).Value();

GeomFill_Pipe aPipe(SPL1,FirstSect);
aPipe.Perform();

Handle(Geom_BSplineSurface) aPipeSurface =
Handle(Geom_BSplineSurface)::DownCast(aPipe.Surface());
Handle(Geom_BSplineSurface) anotherBSplineSurface =
GeomConvert::SplitBSplineSurface(aPipeSurface,1,2,3,6);
P曲线分割

分割平面的分割
TopoDS_Shape S = BRepPrimAPI_MakeBox(gp_Pnt(-100, -60, -80), 150, 200, 170).Shape();
BRepAlgoAPI_Section asect(S, gp_Pln(1,2,1,-15),Standard_False);
asect.ComputePCurveOn1(Standard_True);
asect.Approximation(Standard_True);
asect.Build();
TopoDS_Shape R = asect.Shape();

BRepFeat_SplitShape asplit(S);

for (TopExp_Explorer Ex(R,TopAbs_EDGE); Ex.More(); Ex.Next()) {
    TopoDS_Shape anEdge = Ex.Current();
    TopoDS_Shape aFace;
    if (asect.HasAncestorFaceOn1(anEdge,aFace)) {
        TopoDS_Face F = TopoDS::Face(aFace);
        TopoDS_Edge E = TopoDS::Edge(anEdge);
        asplit.Add(E,F);
    }
}

asplit.Build();
面切割实体
gp_Pnt aPnt1(-5.0, -7.5, -10.0);
gp_Pnt aPnt2(10.0, 15.0, 10.0);
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aPnt1, aPnt2);
myResult << "Box with corners ["
<< aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< "] and ["
<< aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< "] was created in yellow" << std::endl;

// Make a splitting tool as XY plane.
TopoDS_Shape aTool = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()));

// Create a splitter algo.
BRepAlgoAPI_Splitter aSplitter;

// Add shapes to be split.
TopTools_ListOfShape anArguments;
anArguments.Append(aBox);
aSplitter.SetArguments(anArguments);

// Add tool shapes.
TopTools_ListOfShape aTools;
aTools.Append(aTool);
aSplitter.SetTools(aTools);

// Perform splitting.
aSplitter.Build();
if (aSplitter.IsDone()) // Process results
{
    aSplitter.SimplifyResult();
    TopoDS_Shape aResult = aSplitter.Shape();
    TopoDS_Iterator anIt(aResult);
    Standard_ASSERT_VOID(anIt.More(), "Not empty result is expected!");
    TopoDS_Shape aBox1 = anIt.Value(); anIt.Next();
    Standard_ASSERT_VOID(anIt.More(), "Two shapes in the result are expected!");
    TopoDS_Shape aBox2 = anIt.Value();
    gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(0.0, 0.0, -15.0));
    aBox1.Move(aTrsf1);
    gp_Trsf aTrsf2; aTrsf2.SetTranslation(gp_Vec(0.0, 0.0, +15.0));
    aBox2.Move(aTrsf2);
}

缝合

gp_Pnt P(0,0,0);
gp_Vec V(0,0,1);
Handle(Geom_Plane) Pi=new Geom_Plane(P,V);
Handle(Geom_RectangularTrimmedSurface) GeometricSurface=new Geom_RectangularTrimmedSurface(Pi,0.,100.,0.,100.);
TopoDS_Shape FirstShape = BRepBuilderAPI_MakeFace(GeometricSurface, Precision::Confusion());

gp_Pnt P1(0,0,0);
gp_Pnt P2(50,0,0);
gp_Pnt P3(100,0,0);
gp_Pnt P4(25,12,85);
gp_Pnt P5(100,0,80);
gp_Pnt P6(135,-12,85);

TColgp_Array2OfPnt Array(1,3,1,2);
Array.SetValue(1,1,P1);
Array.SetValue(2,1,P2);
Array.SetValue(3,1,P3);
Array.SetValue(1,2,P4);
Array.SetValue(2,2,P5);
Array.SetValue(3,2,P6);
Handle (Geom_BSplineSurface) aSurf = GeomAPI_PointsToBSplineSurface(Array,3,8,GeomAbs_C2,0.00001);
TopoDS_Shape SecondShape = BRepBuilderAPI_MakeFace(aSurf, Precision::Confusion());
BRepOffsetAPI_Sewing aMethod;
aMethod.Add(FirstShape);	
aMethod.Add(SecondShape);
aMethod.Perform();
TopoDS_Shape sewedShape = aMethod.SewedShape();


gp_Sphere aSphere(gp::XOY(), 1.0);
// South hemisphere.
TopoDS_Face aFace1 = BRepBuilderAPI_MakeFace(aSphere, 0.0, 2.0 * M_PI, -M_PI_2, 0.0);
// North hemisphere.
TopoDS_Face aFace2 = BRepBuilderAPI_MakeFace(aSphere, 0.0, 2.0 * M_PI, 0.0, +M_PI_2);
// Make a default tailor.
BRepBuilderAPI_Sewing aTailor;
// Add hemisphere faces.
aTailor.Add(aFace1);
aTailor.Add(aFace2);
// Perform sewing.
aTailor.Perform();
// Get result.
const TopoDS_Shape& aSewedSphere = aTailor.SewedShape();

拼接

贝塞尔曲面拼接为B样条曲面
TColgp_Array2OfPnt array1(1,3,1,3);
TColgp_Array2OfPnt array2(1,3,1,3);
TColgp_Array2OfPnt array3(1,3,1,3);
TColgp_Array2OfPnt array4(1,3,1,3);

array1.SetValue(1,1,gp_Pnt(1,1,1));
array1.SetValue(1,2,gp_Pnt(2,1,2));
array1.SetValue(1,3,gp_Pnt(3,1,1));
array1.SetValue(2,1,gp_Pnt(1,2,1));
array1.SetValue(2,2,gp_Pnt(2,2,2));
array1.SetValue(2,3,gp_Pnt(3,2,0));
array1.SetValue(3,1,gp_Pnt(1,3,2));
array1.SetValue(3,2,gp_Pnt(2,3,1));
array1.SetValue(3,3,gp_Pnt(3,3,0));

array2.SetValue(1,1,gp_Pnt(3,1,1));
array2.SetValue(1,2,gp_Pnt(4,1,1));
array2.SetValue(1,3,gp_Pnt(5,1,2));
array2.SetValue(2,1,gp_Pnt(3,2,0));
array2.SetValue(2,2,gp_Pnt(4,2,1));
array2.SetValue(2,3,gp_Pnt(5,2,2));
array2.SetValue(3,1,gp_Pnt(3,3,0));
array2.SetValue(3,2,gp_Pnt(4,3,0));
array2.SetValue(3,3,gp_Pnt(5,3,1));

array3.SetValue(1,1,gp_Pnt(1,3,2));
array3.SetValue(1,2,gp_Pnt(2,3,1));
array3.SetValue(1,3,gp_Pnt(3,3,0));
array3.SetValue(2,1,gp_Pnt(1,4,1));
array3.SetValue(2,2,gp_Pnt(2,4,0));
array3.SetValue(2,3,gp_Pnt(3,4,1));
array3.SetValue(3,1,gp_Pnt(1,5,1));
array3.SetValue(3,2,gp_Pnt(2,5,1));
array3.SetValue(3,3,gp_Pnt(3,5,2));

array4.SetValue(1,1,gp_Pnt(3,3,0));
array4.SetValue(1,2,gp_Pnt(4,3,0));
array4.SetValue(1,3,gp_Pnt(5,3,1));
array4.SetValue(2,1,gp_Pnt(3,4,1));
array4.SetValue(2,2,gp_Pnt(4,4,1));
array4.SetValue(2,3,gp_Pnt(5,4,1));
array4.SetValue(3,1,gp_Pnt(3,5,2));
array4.SetValue(3,2,gp_Pnt(4,5,2));
array4.SetValue(3,3,gp_Pnt(5,5,1));

Handle(Geom_BezierSurface) BZ1 =
new Geom_BezierSurface(array1);
Handle(Geom_BezierSurface) BZ2 =
new Geom_BezierSurface(array2);
Handle(Geom_BezierSurface) BZ3 =
new Geom_BezierSurface(array3);
Handle(Geom_BezierSurface) BZ4 =
new Geom_BezierSurface(array4);

TColGeom_Array2OfBezierSurface bezierarray(1,2,1,2);
bezierarray.SetValue(1,1,BZ1);
bezierarray.SetValue(1,2,BZ2);
bezierarray.SetValue(2,1,BZ3);
bezierarray.SetValue(2,2,BZ4);

GeomConvert_CompBezierSurfacesToBSplineSurface BB (bezierarray);
Handle(Geom_BSplineSurface) BSPLSURF ;
if (BB.IsDone())
{
    BSPLSURF = new Geom_BSplineSurface(
    BB.Poles()->Array2(),
    BB.UKnots()->Array1(),
    BB.VKnots()->Array1(),
    BB.UMultiplicities()->Array1(),
    BB.VMultiplicities()->Array1(),
    BB.UDegree(),
    BB.VDegree() );
    BSPLSURF->Translate(gp_Vec(0,0,2));
}

布尔运算

交并差
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape();
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape();
TopoDS_Shape ShapeCut = BRepAlgoAPI_Cut(theSphere,theBox);
TopoDS_Shape FusedShape = BRepAlgoAPI_Fuse(theSphere,theBox);
TopoDS_Shape theCommonSurface = BRepAlgoAPI_Common(theSphere,theBox);

变换

gp_Pnt P1(1,2,3);    
gp_Pnt P1Copy = P1;  
gp_Pnt P2(5,4,6);    
gp_Trsf TRSF;        
TRSF.SetMirror(P2);  
P1Copy.Transform(TRSF);  
2d方向旋转
gp_Dir2d aBaseDir(1.0, 1.0);
gp_Dir2d aRotatedDir = aBaseDir.Rotated(M_PI_4);
2d轴点镜像
gp_Ax22d aBaseAx(gp_Pnt2d(10.0, 0.0), gp_Dir2d(1.0, 0.0), Standard_True);
gp_Ax22d aMirrorAx = aBaseAx.Mirrored(gp_Pnt2d());
旋转、镜像、缩放
gp_Pnt centre (5,5,0); gp_Pnt axispoint (9,9,0);
Standard_Real radius = 3;
Handle(Geom_Circle) circle = 
    GC_MakeCircle(centre,axispoint,radius);

Handle(Geom_Geometry) aRotatedEntity = circle->Rotated(gp::OZ(),M_PI/4);
Standard_CString aRotatedEntityTypeName = aRotatedEntity->DynamicType()->Name();

Handle(Geom_Geometry) aMirroredEntity = aRotatedEntity->Mirrored(gp::ZOX());
Standard_CString aMirroredEntityTypeName = aMirroredEntity->DynamicType()->Name();

gp_Pnt scalepoint (4,8,0);
Standard_Real scalefactor = 0.2;
Handle(Geom_Geometry) aScaledEntity =
    aMirroredEntity->Scaled(scalepoint, scalefactor);
Standard_CString aScaledEntityTypeName = aScaledEntity->DynamicType()->Name();

Handle (Geom_Transformation) GT = GC_MakeTranslation (centre, scalepoint);
gp_Trsf TR = GT->Trsf();

gp_Vec aTranslationVector(TR.TranslationPart ());
Handle(Geom_Geometry) aTranslatedEntity =
    aScaledEntity->Translated( aTranslationVector );


gp_Cylinder aBaseCylinder(gp_Ax3(), 10.0);
gp_Trsf aRotTrsf;
aRotTrsf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(1.0, 0.0, 0.0)), M_PI_2);
gp_Trsf aScaleTrsf;
aScaleTrsf.SetScale(gp_Pnt(), 1.5);
gp_Trsf aTranslTrsf;
aTranslTrsf.SetTranslation(gp_Vec(30.0, 0.0, 0.0));
gp_Trsf aComplexTrsf = aRotTrsf * aScaleTrsf * aTranslTrsf;
gp_Cylinder aTransfCylinder = aBaseCylinder.Transformed(aComplexTrsf);

Handle(Geom_CylindricalSurface) aBaseCylinderSurface = new Geom_CylindricalSurface(aBaseCylinder);

Handle(Geom_CylindricalSurface) aTransfCylinderSurface = new Geom_CylindricalSurface(aTransfCylinder);
点镜像
TopoDS_Shape S = BRepPrimAPI_MakeWedge (60.,100.,80.,20.).Shape();
gp_Trsf theTransformation;
gp_Pnt PntCenterOfTheTransformation(110,60,60);
theTransformation.SetMirror(PntCenterOfTheTransformation);
BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
TopoDS_Shape S2 = myBRepTransformation.Shape();
轴镜像
TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.).Shape(); 
gp_Trsf theTransformation;
gp_Ax1 axe = gp_Ax1(gp_Pnt(110,60,60),gp_Dir(0.,1.,0.));
Handle(Geom_Axis1Placement) Gax1 = new Geom_Axis1Placement(axe);
theTransformation.SetMirror(axe);
BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
TopoDS_Shape S2 = myBRepTransformation.Shape();
旋转
TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.).Shape(); 
gp_Trsf theTransformation;
gp_Ax1 axe = gp_Ax1(gp_Pnt(200,60,60),gp_Dir(0.,1.,0.));
Handle(Geom_Axis1Placement) Gax1 = new Geom_Axis1Placement(axe);
theTransformation.SetRotation(axe,30*M_PI/180);
BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
TopoDS_Shape S2 = myBRepTransformation.Shape();
缩放
TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.).Shape(); 
Handle(AIS_Shape) ais1 = new AIS_Shape(S);
myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False); 
myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);   
myAISContext->Display(ais1,Standard_False);
gp_Trsf theTransformation;
gp_Pnt theCenterOfScale(200,60,60);
Handle(AIS_Point) aispnt = new AIS_Point(new Geom_CartesianPoint(theCenterOfScale));

myAISContext->Display(aispnt,Standard_False);
theTransformation.SetScale(theCenterOfScale,0.5);
BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
TopoDS_Shape S2 = myBRepTransformation.Shape();
平移
TopoDS_Shape S = BRepPrimAPI_MakeWedge(6.,10.,8.,2.).Shape(); 
gp_Trsf theTransformation;
gp_Vec theVectorOfTranslation(-6,-6,6);
theTransformation.SetTranslation(theVectorOfTranslation);
BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
TopoDS_Shape S2 = myBRepTransformation.Shape();
位移
TopoDS_Shape S = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape();
gp_Trsf theTransformation;
gp_Ax3 ax3_1(gp_Pnt(0,0,0),gp_Dir(0,0,1));
gp_Ax3 ax3_2(gp_Pnt(60,60,60),gp_Dir(1,1,1));
theTransformation.SetDisplacement(ax3_1,ax3_2);
BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
TopoDS_Shape TransformedShape = myBRepTransformation.Shape();
变形
TopoDS_Shape S = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape();
gp_GTrsf theTransformation;
gp_Mat rot(1, 0, 0, 0, 0.5, 0, 0, 0, 1.5);
theTransformation.SetVectorialPart(rot);
theTransformation.SetTranslationPart(gp_XYZ(5,5,5));

BRepBuilderAPI_GTransform myBRepTransformation(S,theTransformation);
TopoDS_Shape S2 = myBRepTransformation.Shape();

插值

拟合

填充

TColgp_Array1OfPnt array1 (1,5); // sizing array
array1.SetValue(1,gp_Pnt (-4,0,2 )); array1.SetValue(2,gp_Pnt (-7,2,2 ));
array1.SetValue(3,gp_Pnt (-6,3,1 )); array1.SetValue(4,gp_Pnt (-4,3,-1));
array1.SetValue(5,gp_Pnt (-3,5,-2));
Handle(Geom_BSplineCurve) SPL1 = GeomAPI_PointsToBSpline(array1).Curve();

TColgp_Array1OfPnt array2 (1,5); // sizing array
array2.SetValue(1,gp_Pnt (-4,0, 2)); array2.SetValue(2,gp_Pnt (-2,2,0 ));
array2.SetValue(3,gp_Pnt (2 ,3,-1)); array2.SetValue(4,gp_Pnt (3 ,7,-2));
array2.SetValue(5,gp_Pnt (4 ,9,-1));
Handle(Geom_BSplineCurve) SPL2 = GeomAPI_PointsToBSpline(array2).Curve();

GeomFill_FillingStyle Type = GeomFill_StretchStyle;
GeomFill_BSplineCurves aGeomFill1(SPL1,SPL2,Type);
Handle(Geom_BSplineSurface) aBSplineSurface1 = aGeomFill1.Surface();

Type = GeomFill_CoonsStyle;
GeomFill_BSplineCurves aGeomFill2(
Handle(Geom_BSplineCurve)::DownCast(SPL1->Translated(gp_Vec(10,0,0))),
Handle(Geom_BSplineCurve)::DownCast(SPL2->Translated(gp_Vec(10,0,0))),Type);
Handle(Geom_BSplineSurface) aBSplineSurface2 = aGeomFill2.Surface();
Type = GeomFill_CurvedStyle;
GeomFill_BSplineCurves aGeomFill3(
Handle(Geom_BSplineCurve)::DownCast(SPL1->Translated(gp_Vec(20,0,0))),
Handle(Geom_BSplineCurve)::DownCast(SPL2->Translated(gp_Vec(20,0,0))),Type);
Handle(Geom_BSplineSurface) aBSplineSurface3 = aGeomFill3.Surface();
约束填充
TColgp_Array1OfPnt array1 (1,5); // sizing array
array1.SetValue(1,gp_Pnt (-4,0,2 ));
array1.SetValue(2,gp_Pnt (-5,1,0 ));
array1.SetValue(3,gp_Pnt (-6,2,-2 ));
array1.SetValue(4,gp_Pnt (-5,4,-7));
array1.SetValue(5,gp_Pnt (-3,5,-12));

TColgp_Array1OfPnt array2 (1,5); // sizing array
array2.SetValue(1,gp_Pnt (-4,0, 2));
array2.SetValue(2,gp_Pnt (-3,2,1 ));
array2.SetValue(3,gp_Pnt (-1,5,0));
array2.SetValue(4,gp_Pnt (2 ,7,-1));
array2.SetValue(5,gp_Pnt (4 ,9,-1));

TColgp_Array1OfPnt array3 (1,4); // sizing array
array3.SetValue(1,gp_Pnt (-3,5, -12));
array3.SetValue(2,gp_Pnt (-2,6,-7 ));
array3.SetValue(3,gp_Pnt (0 ,8,-3));
array3.SetValue(4,gp_Pnt (4 ,9,-1));

Handle(Geom_BSplineCurve) SPL1 = GeomAPI_PointsToBSpline(array1).Curve();
Handle(Geom_BSplineCurve) SPL2 = GeomAPI_PointsToBSpline(array2).Curve();
Handle(Geom_BSplineCurve) SPL3 = GeomAPI_PointsToBSpline(array3).Curve();

Handle(GeomAdaptor_Curve) SPL1Adaptor = new GeomAdaptor_Curve(SPL1);
Handle(GeomFill_SimpleBound) B1 =
new GeomFill_SimpleBound(SPL1Adaptor,Precision::Approximation(),Precision::Angular());
Handle(GeomAdaptor_Curve) SPL2Adaptor = new GeomAdaptor_Curve(SPL2);
Handle(GeomFill_SimpleBound) B2 =
new GeomFill_SimpleBound(SPL2Adaptor,Precision::Approximation(),Precision::Angular());
Handle(GeomAdaptor_Curve) SPL3Adaptor = new GeomAdaptor_Curve(SPL3);
Handle(GeomFill_SimpleBound) B3 =
new GeomFill_SimpleBound(SPL3Adaptor,Precision::Approximation(),Precision::Angular());
Standard_Boolean NoCheck= Standard_False;

Standard_Integer MaxDeg = 8;
Standard_Integer MaxSeg = 2;
GeomFill_ConstrainedFilling aConstrainedFilling(MaxDeg, MaxSeg);

aConstrainedFilling.Init(B1,B2,B3,NoCheck);

Handle(Geom_BSplineSurface) aBSplineSurface = aConstrainedFilling.Surface();
管道填充
TColgp_Array1OfPnt array1 (1,5); // sizing array
array1.SetValue(1,gp_Pnt (-4,0,2 ));
array1.SetValue(2,gp_Pnt (-5,1,0 ));
array1.SetValue(3,gp_Pnt (-6,2,-2 ));
array1.SetValue(4,gp_Pnt (-5,4,-7));
array1.SetValue(5,gp_Pnt (-3,5,-12));

Handle(Geom_Curve) SPL1 =
GeomAPI_PointsToBSpline(array1).Curve();

Handle(Geom_TrimmedCurve) TC1 =
GC_MakeSegment(gp_Pnt(1,1,1),gp_Pnt(5,5,5));
Handle(Geom_TrimmedCurve) TC2 =
GC_MakeSegment(gp_Pnt(1,1,0),gp_Pnt(4,5,6));
GeomFill_Pipe aPipe3(SPL1,TC1,TC2);
aPipe3.Perform();
Handle(Geom_Surface) aSurface3 = aPipe3.Surface();

拓扑关系映射


几何面类型判断


拓扑循环

TopoDS_Shape aShape = ...;
for (TopExp_Explorer exp (aShape,TopAbs_SOLID);exp.More();exp.Next())
{
	TopoDS_Solid aCurrent = TopoDS::Solid(exp.Current());
}
for (TopExp_Explorer exp (aShape,TopAbs_SHELL);exp.More();exp.Next())
{
	TopoDS_Shell aCurrent = TopoDS::Shell(exp.Current());
}
for (TopExp_Explorer exp (aShape,TopAbs_FACE);exp.More();exp.Next())
{
	TopoDS_Face aCurrent = TopoDS::Face(exp.Current());
}
for (TopExp_Explorer exp (aShape,TopAbs_WIRE);exp.More();exp.Next())
{
	TopoDS_Wire aCurrent = TopoDS::Wire(exp.Current());
}	
for (TopExp_Explorer exp (aShape,TopAbs_EDGE);exp.More();exp.Next())
{
	TopoDS_Edge aCurrent = TopoDS::Edge(exp.Current());
}
for (TopExp_Explorer exp (aShape,TopAbs_VERTEX);exp.More();exp.Next())
{
	TopoDS_Vertex aCurrent = TopoDS::Vertex(exp.Current());
}

修复

修复2d曲线
//1
gp_Pnt2d P1(-184, 101);
gp_Pnt2d P2(20 ,84);
Standard_Real aheight = 1;
FairCurve_Batten B (P1,P2,aheight);
B.SetAngle1(22*M_PI/180);
B.SetAngle2(44*M_PI/180);
FairCurve_AnalysisCode anAnalysisCode;
B.Compute(anAnalysisCode);
Handle(Geom2d_BSplineCurve) C = B.Curve();
//2
gp_Pnt2d P1(-184, 41);                          
gp_Pnt2d P2(20 ,24);                            
Standard_Real aheight = 1;                      
FairCurve_MinimalVariation MV (P1,P2,aheight);  
MV.SetAngle1(22*M_PI/180);                         
MV.SetAngle2(44*M_PI/180);                         
FairCurve_AnalysisCode anAnalysisCode;          
MV.Compute(anAnalysisCode);                     
Handle(Geom2d_BSplineCurve) C = MV.Curve(); 
检索退化边
	TopoDS_Edge aCurveEdge;
	for (TopExp_Explorer anExp(aFace, TopAbs_EDGE); anExp.More(); anExp.Next())
	{
		TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
		if (!BRep_Tool::Degenerated(anEdge))
		{
			aCurveEdge = anEdge;
			break;
		}
	}
检查有效性
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ);
TopoDS_Shape aBox = aBoxMake.Shape();
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow" << std::endl;

// Analyze the box.
BRepCheck_Analyzer anAnalyzer(aBox);
myResult << "Box is " << (anAnalyzer.IsValid() ? "valid" : "invalid") << std::endl;

// Make the box invalid manually.
Handle(BRepTools_ReShape) aReShape = new BRepTools_ReShape();
myResult << "Remove the top face from the box (red)" << std::endl;
aReShape->Remove(aBoxMake.TopFace());
TopoDS_Shape aBox1 = aReShape->Apply(aBox);
myResult << "The top face was removed" << std::endl;

// Analyze the modified box.
BRepCheck_Analyzer anAnalyzer1(aBox1);
myResult << "Modified box is " << (anAnalyzer1.IsValid() ? "valid" : "invalid") << std::endl;

离散

离散边
// Make a wire containing two BSpline curves.
// Define points.
gp_Pnt aPole1(0.0, 0.0, 10.0);
gp_Pnt aPole2(5.0, 5.0, 5.0);
gp_Pnt aPole3(10.0, 10.0, 15.0);
gp_Pnt aPole4(15.0, 5.0, 20.0);
gp_Pnt aPole5(25.0, 15.0, 20.0);
gp_Pnt aPole6(35.0, 15.0, 15.0);
gp_Pnt aPole7(45.0, 25.0, 10.0);
// Add points to the curve poles array.
TColgp_Array1OfPnt aPoles1(1, 4), aPoles2(1, 4);
aPoles1.SetValue(1, aPole1);
aPoles1.SetValue(2, aPole2);
aPoles1.SetValue(3, aPole3);
aPoles1.SetValue(4, aPole4);
aPoles2.SetValue(1, aPole4);
aPoles2.SetValue(2, aPole5);
aPoles2.SetValue(3, aPole6);
aPoles2.SetValue(4, aPole7);
// Make a BSpline curves from the point arrays
Handle(Geom_BSplineCurve) aBSplineCurve1 = GeomAPI_PointsToBSpline(aPoles1).Curve();
Handle(Geom_BSplineCurve) aBSplineCurve2 = GeomAPI_PointsToBSpline(aPoles2).Curve();
// Make edges
TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aBSplineCurve1);
TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(aBSplineCurve2);
// Make a wire
BRepBuilderAPI_MakeWire aMakeWire;
aMakeWire.Add(anEdge1);
aMakeWire.Add(anEdge2);
Standard_ASSERT_VOID(aMakeWire.IsDone(), "Added edge isn't connectible!");
TopoDS_Wire aWire = aMakeWire.Wire();
myResult << "Wire of two BSpline curves was created" << std::endl;

Handle(AIS_ColoredShape) anAisWire = new AIS_ColoredShape(aWire);
myObject3d.Append(anAisWire);

// Make an adaptor.
BRepAdaptor_CompCurve aCurveAdaptor(aWire);

// Use the curve adaptor for some calculations, e.g. compute
// a set of points using GCPnts_QuasiUniformDeflection algo.
Standard_Real aDeflection = 0.5;
GCPnts_QuasiUniformDeflection anAlgo(aCurveAdaptor, aDeflection);
Standard_ASSERT_VOID(anAlgo.IsDone(), "Success is expected!");
myResult << "Distribution of point on the curve with " << aDeflection
<< " deflection was performed:" << std::endl;
for (Standard_Integer i = 1; i <= anAlgo.NbPoints(); ++i)
{
    gp_Pnt aPnt = anAlgo.Value(i);
    myResult << "Point #" << i << " : [ "
    << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl;
    Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt));
    myObject3d.Append(anAisPnt);
}

几何关系

距离

计算两个曲面的最小距离
TColgp_Array1OfPnt array1 (1,5);
array1.SetValue(1,gp_Pnt (-5,1,2));
array1.SetValue(2,gp_Pnt (-5,2,2));
array1.SetValue(3,gp_Pnt (-5.3,3,1));
array1.SetValue(4,gp_Pnt (-5,4,1));
array1.SetValue(5,gp_Pnt (-5,5,2));
Handle(Geom_BSplineCurve) SPL1 = GeomAPI_PointsToBSpline(array1).Curve();

TColgp_Array1OfPnt array2 (1,5);
array2.SetValue(1,gp_Pnt (4,1,2));
array2.SetValue(2,gp_Pnt (4,2,2));
array2.SetValue(3,gp_Pnt (3.7,3,1));
array2.SetValue(4,gp_Pnt (4,4,1));
array2.SetValue(5,gp_Pnt (4,5,2));
Handle(Geom_BSplineCurve) SPL2 = GeomAPI_PointsToBSpline(array2).Curve();

GeomFill_FillingStyle Type = GeomFill_StretchStyle;

GeomFill_BSplineCurves aGeomFill1(SPL1,SPL2,Type);
Handle(Geom_BSplineSurface) aSurf1 = aGeomFill1.Surface();

TColgp_Array2OfPnt array3 (1,5,1,5);
array3.SetValue(1,1,gp_Pnt (-4,-4,5));
array3.SetValue(1,2,gp_Pnt (-4,-2,5));
array3.SetValue(1,3,gp_Pnt (-4,0,4));
array3.SetValue(1,4,gp_Pnt (-4,2,5));
array3.SetValue(1,5,gp_Pnt (-4,4,5));

array3.SetValue(2,1,gp_Pnt (-2,-4,4));
array3.SetValue(2,2,gp_Pnt (-2,-2,4));
array3.SetValue(2,3,gp_Pnt (-2,0,4));
array3.SetValue(2,4,gp_Pnt (-2,2,4));
array3.SetValue(2,5,gp_Pnt (-2,5,4));

array3.SetValue(3,1,gp_Pnt (0,-4,3.5));
array3.SetValue(3,2,gp_Pnt (0,-2,3.5));
array3.SetValue(3,3,gp_Pnt (0,0,3.5));
array3.SetValue(3,4,gp_Pnt (0,2,3.5));
array3.SetValue(3,5,gp_Pnt (0,5,3.5));

array3.SetValue(4,1,gp_Pnt (2,-4,4));
array3.SetValue(4,2,gp_Pnt (2,-2,4));
array3.SetValue(4,3,gp_Pnt (2,0,3.5));
array3.SetValue(4,4,gp_Pnt (2,2,5));
array3.SetValue(4,5,gp_Pnt (2,5,4));

array3.SetValue(5,1,gp_Pnt (4,-4,5));
array3.SetValue(5,2,gp_Pnt (4,-2,5));
array3.SetValue(5,3,gp_Pnt (4,0,5));
array3.SetValue(5,4,gp_Pnt (4,2,6));
array3.SetValue(5,5,gp_Pnt (4,5,5));

Handle(Geom_BSplineSurface) aSurf2 = GeomAPI_PointsToBSplineSurface(array3).Surface();

GeomAPI_ExtremaSurfaceSurface ESS(aSurf1,aSurf2);
//Standard_Real dist = ESS.LowerDistance();
gp_Pnt P1,P2;
ESS.NearestPoints(P1,P2);
计算线-面的距离
gp_Cylinder aCylinder(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 10.0);
gp_Lin aLine(gp_Pnt(20.0, 0.0, 5.0), gp_Dir(0.0, 1.0, 0.0));
Extrema_ExtElCS anExtrema_ExtElCS(aLine, aCylinder);
if (anExtrema_ExtElCS.IsDone())
{
    NCollection_Array1<gp_Vec> aVecArray(1, anExtrema_ExtElCS.NbExt());
    NCollection_Array1<gp_Pnt> aPntArray(1, anExtrema_ExtElCS.NbExt());
    for (Standard_Integer i = 1; i <= anExtrema_ExtElCS.NbExt(); i++)
    {
        Extrema_POnCurv aCurvPoint;
        Extrema_POnSurf aSurfPoint;
        anExtrema_ExtElCS.Points(i, aCurvPoint, aSurfPoint);
        gp_Pnt aCurvPnt = aCurvPoint.Value();
        gp_Pnt aSurfPnt = aSurfPoint.Value();

        DisplayPnt(aCurvPnt, TCollection_AsciiString(i), Aspect_TOM_O_PLUS, 2.0);
        DisplayPnt(aSurfPnt, TCollection_AsciiString(i), Aspect_TOM_O_STAR, 2.0);
        gp_Vec aVec(aCurvPnt, aSurfPnt);
        aVecArray.SetValue(i, aVec);
        aPntArray.SetValue(i, aCurvPnt);
    }
    Standard_Integer aMinDistIndex(0);
    Standard_Real aMinDistance = std::numeric_limits<Standard_Real>::max();
    for (Standard_Integer i = 1; i <= anExtrema_ExtElCS.NbExt(); i++)
    {
        if (aMinDistance > aVecArray(i).Magnitude())
        {
            aMinDistIndex = i;
            aMinDistance = aVecArray(i).Magnitude();
        }
    }
}
曲线-曲线的距离2d
gp_Lin2d aLin(gp_Pnt2d(-40.0, 0.0), gp_Dir2d(1.0, 1.0));
Handle(Geom2d_Line) aGeom_Line = new Geom2d_Line(aLin);
gp_Circ2d aCirc(gp_Ax2d(), 20.0);
Handle(Geom2d_Circle) aGeom_Circle = new Geom2d_Circle(aCirc);

Geom2dAPI_ExtremaCurveCurve anExtremaFinder(aGeom_Line, aGeom_Circle,
std::numeric_limits<Standard_Real>::min(),
std::numeric_limits<Standard_Real>::max(), 0.0, M_PI*2.0);
if (anExtremaFinder.NbExtrema())
{
    gp_Pnt2d aPnt1, aPnt2;
    anExtremaFinder.NearestPoints(aPnt1, aPnt2);
}

投影

2d点到曲线上的投影

gp_Pnt2d aPntToProject(40.0, 40.0);
gp_Circ2d aCirc(gp_Ax2d(), 20.0);
Handle(Geom2d_Circle) aGeom_Circle = new Geom2d_Circle(aCirc);
Geom2dAPI_ProjectPointOnCurve aProjector(aPntToProject, aGeom_Circle);
gp_Pnt2d aProjectionPnt = aProjector.NearestPoint();
点在曲线上的投影、并求距离
gp_Pnt N,Q,P(1,2,3);
Standard_Real distance, radius = 5;
Handle(Geom_Curve) C = new Geom_Circle(gp::XOY(),radius);
GeomAPI_ProjectPointOnCurve PPC (P,C);
N = PPC.NearestPoint();
Standard_Integer NbResults = PPC.NbPoints();
if(NbResults>0)
{
    for(Standard_Integer i = 1;i<=NbResults;i++)
    {
        Q = PPC.Point(i);
        distance = PPC.Distance(i);
        // do something with Q or distance here
    }
}        
点在曲面上的投影、并求距离
gp_Pnt N,Q,P(7,8,9);
Standard_Real distance, radius = 5;
Handle(Geom_SphericalSurface) SP =
new Geom_SphericalSurface(gp_Ax3(gp::XOY()),radius);
GeomAPI_ProjectPointOnSurf PPS(P,SP);
N = PPS.NearestPoint();
Standard_Integer NbResults = PPS.NbPoints();
if(NbResults>0)
{
    for(Standard_Integer i = 1;i<=NbResults;i++)
    {
        Q = PPS.Point(i);
        distance = PPS.Distance(i);
        // do something with Q or distance here
    }
}
点在面上的投影
gp_Sphere aSphere(gp_Ax3(), 10.0);
gp_Pnt aBasePnt(20.0, 20.0, 20.0);
// A projection point in surface coordinate
gp_Pnt2d aPrjPnt2d = ProjLib::Project(aSphere, aBasePnt);
gp_Pnt aPrjPnt = ElSLib::Value(aPrjPnt2d.X(), aPrjPnt2d.Y(), aSphere);

点集是否共点、线、面、包围盒
Standard_Real Tolerance = 8; 
GProp_PEquation PE (array,Tolerance);
PE.IsPlanar();
PE.IsLinear();
PE.IsPoint();
PE.IsSpace();
gp_Pnt P, gp_Vec V1, gp_Vec V2, gp_Vec V3;
PE.Box ();
过点的、与圆相切的直线
gp_Pnt2d P1 (2,3);
gp_Pnt2d P2 (4,4);
gp_Pnt2d P3 (6,7);
gp_Pnt2d P4 (10,10);
gp_Circ2d C = gce_MakeCirc2d (P1,P2,P3);
GccEnt_QualifiedCirc QC = GccEnt::Outside(C);
GccAna_Lin2d2Tan LT (QC,P4,Precision::Confusion());
if (LT.IsDone())
{
    Standard_Integer NbSol = LT.NbSolutions();
    for(Standard_Integer k=1; k<=NbSol; k++)
    {
        gp_Lin2d L = LT.ThisSolution(k);
        // do something with L
    }
}
与直线、圆同时相切的圆
gp_Pnt2d P1 (9,6);
gp_Pnt2d P2 (10,4);
gp_Pnt2d P3 (6,7);
gp_Circ2d C = gce_MakeCirc2d (P1,P2,P3);
GccEnt_QualifiedCirc QC = GccEnt::Outside(C);
gp_Pnt2d P4 (-2,7);
gp_Pnt2d P5 (12,-3);
gp_Lin2d L = GccAna_Lin2d2Tan(P4,P5,Precision::Confusion()).ThisSolution(1);
GccEnt_QualifiedLin QL = GccEnt::Unqualified(L);
Standard_Real radius = 2;
GccAna_Circ2d2TanRad TR (QC,QL,radius,Precision::Confusion());
Standard_Real parsol,pararg;
gp_Pnt2d tangentpoint1,tangentpoint2;
gp_Circ2d circ;
if (TR.IsDone())
{
  Standard_Integer NbSol = TR.NbSolutions();
  for (Standard_Integer k=1; k<=NbSol; k++)
  {
    circ = TR.ThisSolution(k);
    // find the solution circle
    TR.Tangency1(k,parsol,pararg,tangentpoint1);
    // find the first tangent point
    TR.Tangency2(k,parsol,pararg,tangentpoint2);
    // find the second tangent point
  }
}

线

与两个圆相切的直线
gp_Circ2d aCirc1(gp_Ax2d(gp_Pnt2d(0.0, 0.0), gp_Vec2d(1.0, 0.0)), 10.0);
gp_Circ2d aCirc2 = aCirc1.Translated(gp_Vec2d(50.0, 0.0));
aCirc2.SetRadius(20.0);

GccEnt_QualifiedCirc aQaCirc1(aCirc1, GccEnt_outside);
GccEnt_QualifiedCirc aQaCirc2(aCirc2, GccEnt_outside);

GccAna_Lin2d2Tan aLin2d2Tan(aQaCirc1, aQaCirc2, 1E-6);
if (aLin2d2Tan.IsDone())
{
    for (int i = 1; i <= aLin2d2Tan.NbSolutions(); i++)
    {
        const gp_Lin2d& aTangentLin = aLin2d2Tan.ThisSolution(i);
    }
}

几何转换

类型转换

曲线转换

转为B样条曲线
Standard_Real major = 12;
Standard_Real minor = 4; 
gp_Ax2d axis = gp::OX2d(); 
Handle(Geom2d_Ellipse) E = GCE2d_MakeEllipse (axis,major,minor);
Handle(Geom2d_TrimmedCurve) TC = new Geom2d_TrimmedCurve(E,-1,2);

// The segment goes in the direction Vfrom P1  
// to the point projected on this line by P2   
// In the example (0,6).
Handle(Geom2d_BSplineCurve) SPL =
Geom2dConvert::CurveToBSplineCurve(TC);

//
Handle(Geom_Curve) theCurve = ...;
Handle(Geom_Curve) aBSpline = GeomConvert::CurveToBSplineCurve(theCurve);
2D、3D曲线转换
Standard_Real radius = 5;
gp_Ax2d ax2d(gp_Pnt2d(2,3),gp_Dir2d(1,0));
Handle(Geom2d_Circle) circ2d = new Geom2d_Circle(ax2d,radius);
gp_Ax2d circ2dXAxis = circ2d->XAxis();
// create a 3D curve in a given plane
Handle(Geom_Curve) C3D = GeomAPI::To3d(circ2d,gp_Pln(gp_Ax3(gp::XOY())));
Handle(Geom_Circle) C3DCircle = Handle(Geom_Circle)::DownCast(C3D);
gp_Ax1 C3DCircleXAxis = C3DCircle->XAxis();
// project it to a 2D curve in another plane
gp_Pln ProjectionPlane(gp_Pnt(1,1,0),gp_Dir( 1,1,1 ));
Handle(Geom2d_Curve) C2D = GeomAPI::To2d(C3D,ProjectionPlane);
Handle(Geom2d_Circle) C2DCircle = Handle(Geom2d_Circle)::DownCast(C2D);
gp_Ax2d C2DCircleXAxis = C2DCircle->XAxis();

曲面转换

转为B样条曲面
Handle(Geom_BSplineSurface) aBSplineSurface = GeomConvert::SurfaceToBSplineSurface(theSurface);

转为Nub曲面

gp_Torus aTorus(gp::XOY(), 20.0, 7.5);
TopoDS_Shape aTorusFace = BRepBuilderAPI_MakeFace(aTorus);
myResult << "TopoDS_Solid on the torus with" << std::endl
<< "R major = " << aTorus.MajorRadius() << std::endl
<< "R minor = " << aTorus.MinorRadius() << std::endl
<< "was created in yellow" << std::endl;

// Convert faces/edges from analytic to NURBS geometry.
TopoDS_Shape aNurbsFace = BRepBuilderAPI_NurbsConvert(aTorusFace);
myResult << "Converted torus in red" << std::endl;
gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(60.0, 0.0, 0.0));
aNurbsFace.Move(aTrsf1);

几何转拓扑

几何点转为拓扑点
BRep_Builder B;
TopoDS_Vertex V000;
B.MakeVertex(V000,gp_Pnt(0,0,0),precision);
几何曲线转为拓扑边
TopoDS_Edge EX00;
BRep_Builder B;
TopoDS_Vertex V000, V100;
Handle (Geom_Curve) L = ...;
B.MakeEdge(EX00,L,precision);
V000.Orientation(TopAbs_FORWARD);
V100.Orientation(TopAbs_REVERSED);
B.Add(EX00,V000);
B.Add(EX00,V100);
B.UpdateVertex(V000,0,EX00,precision);
B.UpdateVertex(V100,200,EX00,precision);

几何曲线转为拓扑线
BRep_Builder B;
TopoDS_Edge EY10;
TopoDS_Wire W;
B.MakeWire (W);
EY10.Orientation(TopAbs_FORWARD);
B.Add(W,EY10);
几何曲面转为拓扑面
TopoDS_Face FXMAX;	
BRep_Builder B;
TopoDS_Edge EY10 = ...;
Handle (Geom_Plane) P = new Geom_Plane(gp_Ax2(gp_Pnt(200,0,0),gp_Dir(1,0,0),gp_Dir(0,1,0)));
B.MakeFace(FXMAX,P,precision);

Handle (Geom2d_Line) L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(1,0));
EY10.Orientation(TopAbs_FORWARD);
//更新面上的边
B.UpdateEdge(EY10,L2d,FXMAX,precision);

TopoDS_Wire W = ...;
TopoDS_Face FYMAX;
B.Add(FYMAX,W);

//更新面上边上的点
B.UpdateVertex(V001,0,EX01,FXMAX,precision);
B.UpdateVertex(V101,M_PI,EX01,FYMAX,precision);
拓扑面生成拓扑壳
BRep_Builder B;
TopoDS_Shell Sh;
B.MakeShell(Sh);
B.Add(Sh,FXMAX);
B.Add(Sh,FXMIN);
B.Add(Sh,FYMAX);
B.Add(Sh,FYMIN);
B.Add(Sh,FZMAX);
B.Add(Sh,FZMIN);
拓扑壳生成拓扑体
TopoDS_Solid Sol;
BRep_Builder B;
B.MakeSolid(Sol);
B.Add(Sol,Sh1);
B.Add(Sol,Sh2);

拓扑转几何

拓扑点转几何点
TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0,120,70));
gp_Pnt GeometricPoint = BRep_Tool::Pnt(aVertex);
拓扑边转几何边
TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(100,50,250),gp_Pnt(-30,-100,-50));
TopLoc_Location location;
Standard_Real first, last;
Handle (Geom_Curve) aCurve = BRep_Tool::Curve(anEdge,location,first,last);
TopoDS_Edge anEdgeDS = BRepBuilderAPI_MakeEdge(aCurve);
拓扑面转几何面
gp_Pnt P(-20,-20,-20);
gp_Vec V(0,0,1);
Handle(Geom_Plane) Pi=new Geom_Plane(P,V);
Handle(Geom_RectangularTrimmedSurface) Surface=new Geom_RectangularTrimmedSurface(Pi,0.,100.,0.,100.);
TopoDS_Face RedFace = BRepBuilderAPI_MakeFace(Surface, Precision::Confusion());
TopLoc_Location location2;
Handle (Geom_Surface) aGeometricSurface = BRep_Tool::Surface(RedFace,location2);

//几何面类型判断

几何分析

形状分析

形状重建

形状修复

数学基础

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值