Page 1 of 1

Project point to solid

Posted: Wed Feb 17, 2021 9:53 pm
by Dernbauer
Hi,
I have a solid imported via STEP. For an arbitrary 3d point I need to find its orthogonal projection to the surface. What is the right way to do this in dgkernel?

Re: Project point to solid

Posted: Tue Feb 23, 2021 4:56 am
by Prashant Kande
Hello, Dernbauer
Sorry for the late answer

You need to make a BRep vertex, which represents your point:

Code: Select all

	IBRepVertex_DG iVtx = iGener.Create("BRepVertex_DG") as IBRepVertex_DG;
	 iVtx.SetPosition(x, y, z);
Make an entity for it:

Code: Select all

	IEntity_DG iEntityPoint = iGener.Create("IEntity_DG") as IEntity_DG;
	IBRepGeometry_DG iGeom = iEntityPoint.SetGeometryType("BRep") as IBRepGeometry_DG;
	iGeom.SetShape(iVtx as IBRepShape_DG);
Query IMetrics from the entity of your solid and from iEntityPoint. Use
IMetrics.Dist() to get the distance and the nearest points

Code: Select all

double d;
            MetrDistContext context = new MetrDistContext();
            context.precision = 0.0000000001;
            context.tolerance = 0.0000000001;	//...
	    IRelation iRel;
            double d = iMetricsFrom.dist(iMetricsTo, context, out iRel);
The iRel will be a list of nearest points. See CompileNearestData() in Metrics sample about accessing it

As usual, the generator here is:

Code: Select all

	iModel = dgk.GetModel() as IModel_DG;
        IObjectGenerator_DG iGener = iModel as IObjectGenerator_DG;

Re: Project point to solid

Posted: Thu Jun 16, 2022 7:48 am
by Prashant Kande
Since v7.0 IMetrics has been deprecated and replaced with IMetrics_DG.
IMetrics_DG.DistPoint() is a nice shortcut for the job.