Sun, 10/08/2023 - 16:31
Forums:
Hi I use the hyperbolic parametric equation to generate a sequence of hyperboloid points and store it in TColgp_Array2OfPnt. This is then fitted to a hyperboloid using GeomAPI_PointsToBSplineSurface and converted to TopoDS_Shape. Finally, the intersection with another individual of type TopoDS_Shape gives FocalMirrorShape, but strangely FocalMirrorShape is wrong, which can be observed by the figure.
I am not sure whether the surface fitted by GeomAPI_PointsToBSplineSurface cannot be properly intersect, or I am missing some modeling step?
// Create a parametric equation for the hyperboloid
TopoDS_Shape Hyp_surface;
double U, V; double uMin = -1.0; double uMax = 1.0; double vMin = 0.0; double vMax = 2 * M_PI;
double numUPoints = 90; double numVPoints = 90;
double uStep = (uMax - uMin) / numUPoints; double vStep = (vMax - vMin) / numVPoints;
// A TColgp_HArray2OfPnt is created to hold the point set
TColgp_Array2OfPnt points(1, numUPoints + 1, 1, numVPoints + 1);
for (double i = 1; i <= numUPoints + 1; i++) {
U = uMin + uStep * (i - 1);
for (double j = 1; j <= numVPoints + 1; j++) {
V = vMin + vStep * (j - 1);
double x = m_pHYPParA * cosh(U);
double y = m_pHYPParB * sinh(U) * sin(V);
double z = m_pHYPParC * sinh(U) * cos(V);
points(i, j) = gp_Pnt(x, y, z);
}
}
// Fit the points to a B-spline surface using GeomAPI_PointsToBSplineSurface
GeomAPI_PointsToBSplineSurface surfaceFitter(points);
Handle_Geom_BSplineSurface bsplineSurface = surfaceFitter.Surface();
BRepBuilderAPI_MakeFace makeFace(bsplineSurface, Precision::Confusion());
makeFace.Build();
if (makeFace.IsDone()) {
Hyp_surface = makeFace.Shape();
}
// Create a cuboid
BRepPrimAPI_MakeBox makeBox(m_Point, m_HYPlength, m_HYPwith, m_HYPhigh); // These are some coordinates and size parameters about the cuboid
TopoDS_Shape box = makeBox.Shape();
// Calculate the face obtained by intersecting the ellipsoid with the cuboid
BRepAlgoAPI_Common section(Hyp_surface, box);
section.Build();
TopoDS_Face newFace;
std::vector<TopoDS_Face> test_Face;
if (section.IsDone()) {
TopExp_Explorer explorer;
for (explorer.Init(section.Shape(), TopAbs_FACE); explorer.More(); explorer.Next()) {
test_Face.push_back(TopoDS::Face(explorer.Current()));
}
}
if (section.IsDone()) {
// Extract the local faces obtained by the intersection
TopExp_Explorer explorer(section.Shape(), TopAbs_FACE);
if (explorer.More()) {
TopoDS_Face Hyp_IntersectionFace = TopoDS::Face(explorer.Current());
// The parameter range of the local face is obtained
Standard_Real uMin, uMax, vMin, vMax;
BRepTools::UVBounds(Hyp_IntersectionFace, uMin, uMax, vMin, vMax);
// The parameter range is used to intercept the geometric data of the local face
Handle(Geom_Surface) surface = BRep_Tool::Surface(Hyp_IntersectionFace);
Handle(Geom_Surface) trimmedSurface = new Geom_RectangularTrimmedSurface(surface, uMin, uMax, vMin, vMax);
BRepBuilderAPI_MakeFace newFaceMaker(trimmedSurface, Precision::Confusion());
newFace = newFaceMaker.Face();
}
}
TopoDS_Shape FocalMirrorShape = newFace;
Attachments: