u,v-coordinates of 3d-points

Hello,
has anyone a solution for the following problem?
I have a shape, tooked all edges and discretized them with a number of equidistant 3d-points. Now I need the u,v-coordinates of this points in the parametric space of the faces belonging to the edge. I tried GeomAPI_ProjectPointOnSurf, but it is slow and very often does not found a projection. Besides this I dont need a real projection, because I know that the 3d-points are on the faces.
Has anyone an idea?
Thanks for any hints,
Gernot Knieling

Rob Bachrach's picture

I could be wrong about this, but I believe you could use:
Standard_Real first, last;
Handle(Geom2d_Curve) curve = BRep_Tool::CurveOnSurface(edge, face, first, last);

The returned curve is in the parametric space of the surface. So, if you know where your point is in the parametric space of the edge, you can get the corresponding u,v point on the surface by querying the curve at that point. Of course, to use this, you need to know the point location in the parametric space of the edge.

Gernot Knieling's picture

Hello Rob,
I thought about this idea too, but there is one problem: there is no connection between the 3d-curve-parameter and the 2d-curve-parameter. When I discretize the 3d-curve with GCPnts_UniformAbscissa, I have the parameters to all points on the 3d-curve. When I use this parameters to calculate 2d-points on the 2d-curve and with this 3d-points on the face, the resulting 3d-points on the face are often different from the 3d-points on the edge.
Regards,
Gernot Knieling

Rob Bachrach's picture

If I'm reading the OCC documentation correctly...
- Take the parameters of the points on the 3d curve and get the parameter range for that curve.
- For each point, scale the parameter on the 3d curve within its range.
- Use the scaled parameter to find the corresponding parameter within the range of the curve on the surface.
- Get the UV location from the curve on the surface based on the new parameter.

Note that you may have to reverse your parameter within the range of the 3d curve if the edge is reversed.

If this doesn't help, I'm at a loss.

Rob

Gernot Knieling's picture

Hm, this sounds as if I should give it a try.
I will tell you wether it was successful.
Thank you,
Gernot Knieling

CloneX's picture

This might do the trick:

gp_Pnt2d FaceParameters(const TopoDS_Face &face,const gp_Pnt &pt)
{
// get face as surface
const Handle(Geom_Surface) &surface = BRep_Tool::Surface(face);
// create shape analysis object
ShapeAnalysis_Surface sas(surface);
// get UV of point on surface
gp_Pnt2d uv = sas.ValueOfUV(pt, 0.01);
// return parameters of point on face
return uv;
}

Cheers,

Chris

Gernot Knieling's picture

Ok,
I tried ShapeAnalysis_Surface and it works. If I use the Method NextValueOfUV, it is much more faster then GeomAPI_ProjectPointOnSurf.

But Rob suggested another Method that I interpreted as an reparametrisation, and this method is still faster than ShapaAnalysis_Surface. I used BRep_Tool::CurveOnSurface to get the 2d-parametric curve of the edge on the face. Then I used GCPnts_UniformAbscissa to compute 2d-points with uniform distances, about ten times more then the 3d-points on the edge. Then I calculated the 3d-points according to the 2d-points and used their distances to calculate new parameter values for the 2d-curve. With this new parameters I calculated again 2d-points on the 2d-curve, with uniform parameter value distribution, number of points as number of 3d-points on the edge. The distance of the resulting 3d-points on the face to the 3d-edge-points is very small, the tolerance depends on the number of reparametrisation points.

Regards,
Gernot Knieling