If you know circularFace is "circular", extract its outer edge which should be of type GeomAbs_Arc. from that u could get its center as well as radius and
compute the necessary inputs for the MakeShere API.
regards
PG
Archived discussion
I have a circular face from which I want to add a bottle cap like hemisphere.
I have the radius of the circular face but not its center point. I've used the following code but the hemisphere doesn't completely fit.
TopoDS_Face circularFace...;
double ToolRadius = 10;
gp_Dir normal(0,1,0);
GProp_GProps props;
BRepGProp::LinearProperties(circularFace, props);
gp_Pnt centerMass = props.CentreOfMass();//get the center of mass
gp_Ax2 Ax2(centerMass, normal);
TopoDS_Face S2 = BRepPrimAPI_MakeSphere(Ax2, ToolRadius, PI);I've attached an image of the shapes. How can I make the bottle cap completely fit?
Thank you.
Discussion
Posts are displayed in their archived order.
If you know circularFace is "circular", extract its outer edge which should be of type GeomAbs_Arc. from that u could get its center as well as radius and
compute the necessary inputs for the MakeShere API.
regards
PG
Thanks PG. That solution worked.
Here's the code I used.
TopoDS_Edge tnpEdge;
for(TopExp_Explorer explrV(circularFace, TopAbs_EDGE); explrV.More(); explrV.Next()){
tnpEdge = TopoDS::Edge(explrV.Current());
}
Standard_Real first,last;
gp_Pnt pntFst, pntLst,pntMdl;
Handle(Geom_Curve) Projected_Curve = BRep_Tool::Curve(tnpEdge,first,last);
Projected_Curve->D0(first,pntFst);
Projected_Curve->D0((first+last)/2,pntLst);
Projected_Curve->D0((first+ (last-first)/4),pntMdl);
gce_MakeCirc mkCirc(pntFst, pntLst, pntMdl);
gp_Circ circ = mkCirc.Value();
double rad = circ.Radius();
gp_Pnt mid = circ.Location();
gp_Ax2 Ax(mid, norm);
TopoDS_Face S2 = BRepPrimAPI_MakeSphere(Ax, rad, PI);