problem with GeomAPI_IntCS??

I'm trying to pick a point on a shape.
I've read alot of good methods on the forum and have applied two methods one found on:
and the other found on:

I've used an algorithm that gets a 3D point (ResultPoint) on a plane orthogonal to the point of view.
From there I've decomposed the shape into faces (then surfaces) to use the GeomAPI_IntCS class to find the intersection between a "line" (from EyePoint to ResultPoint) and the given face.

The final ResultPoint I get is incorrect. It too seems to lies on a plane (it seems to be a plane that one of the faces is on).
Furthermore, "line" intersects with all of the faces in my shape. (currently I'm playing with a cube (12 triangles)).
Can somebody let me know where I'm going wrong here.

I've supplied the code that I'm using:

Thanks in advance

aView->Eye(xEye, yEye, zEye);
aView->At(xAt, yAt, zAt);
gp_Pnt EyePoint(xEye, yEye, zEye);
gp_Pnt AtPoint(xAt, yAt, zAt);

gp_Vec EyeVector(EyePoint, AtPoint);
gp_Dir EyeDir(EyeVector);

gp_Pln PlaneOfView = gp_Pln(AtPoint, EyeDir);

Standard_Real theX, theY, theZ;
aView->Convert(x, y, theX, theY, theZ);
gp_Pnt ConvertedPoint (theX, theY, theZ);

gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfView, ConvertedPoint);

gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfView);

GC_MakeLine line(EyePoint, ResultPoint);
TopExp_Explorer exp;
int iii = 0;
for (exp.Init(myShape, TopAbs_FACE); exp.More(); exp.Next())
TopoDS_Face face = TopoDS::Face(exp.Current());
BRepAdaptor_Surface surface(face);
const GeomAdaptor_Surface& geomAdapSurf = surface.Surface();
const Handle(Geom_Surface)& geomSurf = geomAdapSurf.Surface();

GeomAPI_IntCS inCS;
inCS.Perform(line, geomSurf);
if (inCS.IsDone())
if (inCS.NbPoints()!=0)
ResultPoint = gp_Pnt(inCS.Point(1).XYZ());
a3dPoint = ResultPoint;

Jonathan Hill's picture

Hi Sinisa Stokic,

Firtly thanks for the posting, I trying to do something simular by picking point of a surface.

I and think I've got it fully working now, which just one simple change to the code.

//xGC_MakeLine line(EyePoint, ResultPoint); <--- change this line to
GC_MakeLine line(ResultPoint, EyeDir);

I've include the complete function, sorry about the C# code :), if you have any problems just send me an e-mail.

private global::Core.Geometry.Interfaces.ICoordinate ConvertClickToPoint2(
System.Drawing.Point position,
IView view,
global::OpenCASCADE52.Geom.Interfaces.IPlane geomSurface)
double xEye = 0.0;
double yEye = 0.0;
double zEye = 0.0;
double xAt = 0.0;
double yAt = 0.0;
double zAt = 0.0;

view.Eye(&xEye, &yEye, &zEye);
view.At(&xAt, &yAt, &zAt);

IPnt eyePoint = new Pnt(xEye, yEye, zEye);
IPnt atPoint = new Pnt(xAt, yAt, zAt);
//DrawLine(eyePoint, atPoint);

Debug.WriteLine(string.Format("EyePoint: {0} {1} {2}", xEye, yEye, zEye));
Debug.WriteLine(string.Format("AtPoint: {0} {1} {2}", xAt, yAt, zAt));

IVec eyeVector = new Vec(eyePoint, atPoint);
IDir eyeDir = new Dir(eyeVector);

IPln planeOfTheView = new Pln(atPoint, eyeDir);

double x, y, z;

view.Convert(position.X, position.Y, &x, &y, &z);

Debug.WriteLine(string.Format("XYZ: {0} {1} {2}", x, y, z));

IPnt convertedPoint = new Pnt(x, y, z);
IPnt2d convertedPointOnPlane = ProjLib.Project(planeOfTheView, convertedPoint);

IPnt resultPoint = ElSLib.Value(convertedPointOnPlane.X, convertedPointOnPlane.Y, planeOfTheView);

//DrawLine(eyePoint, resultPoint);
//IMakeLine makeLine = new MakeLine(eyePoint, resultPoint); //x
IMakeLine makeLine = new MakeLine(resultPoint, eyeDir); // project backwards from the result point using the viewing plane

IIntCS intCS = new IntCS();
intCS.Perform(makeLine.Value, geomSurface);

if( intCS.IsDone() )
if( intCS.NbPoints() > 0 )
resultPoint = new Pnt(intCS.Point(1).XYZ); // one-based

return new global::Core.Geometry.Coordinate(resultPoint.X, resultPoint.Y, resultPoint.Z);

return null;

Many thanks

trillion's picture

I had changed the line, but I can't get the correct result, are you sure the result is true? I use iges import model.

trillion's picture

have the problem been solved?

Stephen Leary's picture

No the problem still exists.