目录
1、沿方向拉伸
2、沿路径拉伸
3、变形拉伸
1、沿方向拉伸
#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepFeat_SplitShape.hxx>
#include"Viewer.h"
#include <BRepAlgoAPI_Section.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
int main(int argc, char* argv[])
{gp_Dir Z(0.0, 0.0, 1.0);gp_Dir ZX(1.0, 0.0, 1.0);gp_Pnt center(0, 0, 0.0);gp_Pnt xr(0.5, 0, 0.0);gp_Pnt yr(0.0, 1.0, 0.0);gp_Pnt zr(0.0, 0.0, 7.0);gp_Ax2 wb(center, Z);gp_Circ wbcircle(wb, 0.125 / 2);TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);BRepPrimAPI_MakeCylinder aCylinderMaker(10.0, 20.0);TopoDS_Shape aCylinder = aCylinderMaker.Shape();gp_Pln TPlane(center, ZX);TopoDS_Face tanF = BRepBuilderAPI_MakeFace(TPlane);TopoDS_Shape out = BRepPrimAPI_MakePrism(zline, 10*ZX);//TopoDS_Edge out = BRepBuilderAPI_MakeEdge(c1);Viewer vout(50, 50, 500, 500);vout << out;vout << xline;vout << yline;vout << zline;vout.StartMessageLoop();return 0;
}
2、沿路径拉伸
#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeSegment.hxx>
#include"Viewer.h"
#include <GC_MakeArcOfCircle.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
int main(int argc, char* argv[])
{gp_Dir Z(0.0, 0.0, 1.0);gp_Dir ZX(1.0, 0.0, 1.0);gp_Pnt center(0, 0, 0.0);gp_Pnt xr(0.5, 0, 0.0);gp_Pnt yr(0.0, 1.0, 0.0);gp_Pnt zr(0.0, 0.0, 7.0);gp_Ax2 wb(center, Z);gp_Circ wbcircle(wb, 0.125 / 2);TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);BRepPrimAPI_MakeCylinder aCylinderMaker(10.0, 20.0);TopoDS_Shape aCylinder = aCylinderMaker.Shape();gp_Pln TPlane(center, ZX);TopoDS_Face tanF = BRepBuilderAPI_MakeFace(TPlane);Handle(Geom_TrimmedCurve) arc = GC_MakeArcOfCircle(gp_Pnt(0, 0, 0), gp_Pnt(10, 10, 0), gp_Pnt(0, 20, 0));Handle(Geom_TrimmedCurve) arc2 = GC_MakeArcOfCircle(gp_Pnt(0, 20, 0), gp_Pnt(-10, 30, 0), gp_Pnt(0, 40, 0));Handle(Geom_TrimmedCurve) seg = GC_MakeSegment(gp_Pnt(0, 40, 0), gp_Pnt(20, 40, 0));Handle(Geom_TrimmedCurve) seg1 = GC_MakeSegment(gp_Pnt(20, 40, 0), gp_Pnt(20, 60, 0));TopoDS_Edge arcEdge = BRepBuilderAPI_MakeEdge(arc);TopoDS_Edge arcEdge1 = BRepBuilderAPI_MakeEdge(arc2);TopoDS_Edge segEdge = BRepBuilderAPI_MakeEdge(seg);TopoDS_Edge segEdge1 = BRepBuilderAPI_MakeEdge(seg1);TopoDS_Wire arcWire = BRepBuilderAPI_MakeWire(arcEdge, arcEdge1, segEdge/*, segEdge1*/); //return arcWire;TopoDS_Shape out = BRepOffsetAPI_MakePipe(arcWire,zline);//TopoDS_Edge out = BRepBuilderAPI_MakeEdge(c1);Viewer vout(50, 50, 500, 500);vout << out;vout << xline;vout << yline;vout << zline;vout.StartMessageLoop();return 0;
}
3、变形拉伸
#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <gp_Circ.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom_Plane.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <BRepOffsetAPI_DraftAngle.hxx>
#include <TopExp_Explorer.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS.hxx>
#include <gp_Pln.hxx>
#include <GC_MakeSegment.hxx>
#include"Viewer.h"
#include <GC_MakeArcOfCircle.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
int main(int argc, char* argv[])
{gp_Dir Z(0.0, 0.0, 1.0);gp_Dir ZX(1.0, 0.0, 1.0);gp_Pnt center(0, 0, 0.0);gp_Pnt xr(0.5, 0, 0.0);gp_Pnt yr(0.0, 1.0, 0.0);gp_Pnt zr(0.0, 0.0, 7.0);gp_Ax2 wb(center, Z);gp_Circ wbcircle(wb, 0.125 / 2);TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);TopoDS_Shape S = BRepPrimAPI_MakeBox(200., 300., 150.);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_Shape out = adraft.Shape();//TopoDS_Edge out = BRepBuilderAPI_MakeEdge(c1);Viewer vout(50, 50, 500, 500);vout << out;vout << xline;vout << yline;vout << zline;vout.StartMessageLoop();return 0;
}