For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

pick a point on a shape

trillion's picture

hi all:
I'm trying to pick a point on a shape, I use the following code, but I can't get the correct result. Thanks for any tips.
V3d_Coordinate EyeX,EyeY,EyeZ,AtX,AtY,AtZ;
gp_Pnt EyePoint(EyeX, EyeY, EyeZ);
gp_Pnt AtPoint(AtX, AtY, AtZ);

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

gp_Pln PlaneOfView = gp_Pln(AtPoint, EyeDir);

Standard_Real theX, theY, theZ;
aView->Convert(int(x), int(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(ResultPoint, EyeDir);

TopExp_Explorer exp;
int iii = 0;
for (exp.Init(S, 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);

//IntCurvesFace_Intersector ii;

if (inCS.IsDone())
if (inCS.NbPoints()>0)
ResultPoint = gp_Pnt(inCS.Point(1).XYZ());


return ResultPoint;


void C3DUIDoc::OnInserttestpointAddtestpoint()
if (myAISContext->MoreSelected())
TopoDS_Shape S = myAISContext->SelectedShape();

gp_Pnt r = getClickPointOnShape(mouseX,mouseY,S,currentView);

Handle_AIS_Shape myBox;
BRepPrimAPI_MakeBox B(r, 2000.,1500.,1000.);

myBox = new AIS_Shape(B.Shape());