Project point to solid

Technical discussions
Post Reply
Dernbauer
Posts: 1
Joined: Wed Feb 17, 2021 9:46 pm

Project point to solid

Post 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?

Prashant Kande
Posts: 121
Joined: Mon Apr 04, 2016 4:55 am

Re: Project point to solid

Post 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;

Prashant Kande
Posts: 121
Joined: Mon Apr 04, 2016 4:55 am

Re: Project point to solid

Post 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.

Post Reply