## Project vector onto a surface

Technical discussions
Ausmo
Posts: 1
Joined: Wed May 12, 2021 5:45 am

### Project vector onto a surface

Hi,

I need to project a 3d vector as VectDg at a fixed point and I want to project it onto a surface IUVSurface_DG or a face. I should be able to construct a tangential plane using IUVSurface_DG.GetNormal(), but I wonder whether it is necessary to do these calculations myself. Is there an interface that does that? I guess it would be more efficient

Thank you and looking forward for any answers

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

### Re: Project vector onto a surface

Hello

Projecting vector to a surface normally means projecting it to the tangential plane at some surface point. The solution depends on whether you have a fixed point on the surface or not.

The code below assumes that you have also a location point for the vector (So you have a ray) and you need to find the nearest point for the location and project the vector to the tangential plane at the nearest point.

Code: Select all

``````	    PointDg pt; // Vector location or target point on the surface
I2DPointArray_DG uvs = iSurface.GetNearestPoints(pt);
Dg_2D uv = uvs.GetPoint1(0);

PointDg ptProjected = iSurface.GetPoint(uv);
VectDg n = iSurface.GetNormal(uv);

VectDg v;  // The 3d vector to be projected
IPlane_DG plane = m_iGener.Create("IPlane_DG") as IPlane_DG;
plane.SetOrigin(ptProjected);
plane.SetNormal(n);

VectDg vProjectedResult = plane.GetVectorProjection(v);
``````
The case where you have a fixed point can be handled by this code with minor mods as well: If you have uv for the point, just remove the first three lines. Otherwise set pt and ptProjected equal to the fixed point.

The plane.GetVectorProjection(v); is available starting with the 5212 update. Otherwise you can code few lines based on IPlane_DG.GetDistance(point, out Point_DG pointNearestInPlane).

Regards