Assistance with Projections

Forums: 

I am having some issues with performing projections. Currently, I am importing a step file and drawing it to the screen using an MFC CDC pointer. This is working just fine. Next, I'm wanting to project an object (i.e. a line, a circle, text, etc.) onto a surface of the step solid so that that object can be drawn correctly on the step file. After performing a nearest neighbor search on a kd-tree, I'm able to get the face whose center point (calculated from a bounding box) is closest to the point that I'm trying to project. Below is the code snippet where I'm performing the projection.

// Get the face
TopoDS_Face face = m_pCurrentBest->face;

// Calcuate a bounding box for the face
Bnd_OBB box;
BRepBndLib::AddOBB(face, box);

// Determine if the given point is inside the box
if (!box.IsOut(ptLoc))
{
// Create a surface from the face
Handle(Geom_Surface) pSurface = BRep_Tool::Surface(face);

// Project the point onto the surface
ptProj = GeomAPI_ProjectPointOnSurf(ptLoc, pSurface);

// Populate the location
_projLoc.Set(ptProj.X(), ptProj.Y());

// Indicate the process is complete
bDone = TRUE;
}

if I understand the documentation correctly, then ptProj should be the closest point on the surface normal to ptLoc. What i'm seeing is shown in the attached screenshot. This doesn't look like what I expect. What process should I use to accomplish what I want to do?

Thank you all for your time

Attachments: 
Thomas Hafemann's picture

Hi,
I've been there. The only hint someone gave me, was that you want to use ShapeAnalysis_Surface instead of GeomAPI_ProjectPointOnSurf.
It seems the GeomAPI_ProjectPointOnSurf is not always reliable.