Get Normal of a mesh when point.m_ci.m_type == ON_COMPONENT_INDEX::meshtop_vertex (c++)

Hi;
what is wrong with my code, Why is the point has transform going in the wrong direction ?
This is my file LVI192067P.3dm (396.0 KB)

CRhinoGetObject go;
go.SetCommandPrompt(L"SELECT POINT");
go.SetGeometryFilter(CRhinoGetObject::point_object);
go.GetObjects(1, 1);
if (go.CommandResult() != CRhinoCommand::success)
	return go.CommandResult();
CRhinoGetObject go1;
go1.SetCommandPrompt(L"SELECT MESH");
go1.SetGeometryFilter(CRhinoGetObject::mesh_object);
go1.GetObjects(1, 1);
if (go1.CommandResult() != CRhinoCommand::success)
{
	return go1.CommandResult();
}
ON_MESH_POINT point;
ON_3dVector nor = ON_UNSET_POINT;
ON_Mesh* mesh = const_cast<ON_Mesh*>(go1.Object(0).Mesh());
if (!mesh->HasFaceNormals())
	mesh->ComputeFaceNormals();
mesh->GetClosestPoint(go.Object(0).m_point, &point);
if (point.m_ci.m_type == ON_COMPONENT_INDEX::meshtop_vertex)
{
	ON_SimpleArray<int> faces;
	const ON_MeshTopology& top = mesh->Topology();
	int topvi = top.m_topv_map[point.m_ci.m_index];
	const ON_MeshTopologyVertex& topvert = top.m_topv[topvi];
	for (int i = 0; i < topvert.m_tope_count; i++)
	{
		const ON_MeshTopologyEdge& topedge = top.m_tope[topvert.m_topei[i]];
		for (int j = 0; j < topedge.m_topf_count; j++)
			faces.Append(topedge.m_topfi[j]);
	}
	faces.QuickSort(&ON_CompareIncreasing<int>);
	int fi = -1;
	for (int i = faces.Count() - 1; i >= 0; i--)
	{
		if (faces[i] == fi)
			faces.Remove(i);
		else
			fi = faces[i];
	}
	ON_3dVector ve_s = mesh->m_FN[faces[0]];
	for (int i = 1; i < faces.Count(); i++)
	{
		ON_3dVector ve_e = mesh->m_FN[faces[i]];
		ve_s = ve_s + ve_e;
	}
	ve_s.Unitize();
	ON_3dPoint point_tranform(point.m_P);
	point_tranform.Transform(ON_Xform::TranslationTransformation(ve_s));
	RhinoApp().ActiveDoc()->AddPointObject(point_tranform);
}
RhinoApp().ActiveView()->Redraw();
return success;

Hi @suc_kiet,

What is the code supposed to do? Any details you can provide might be helpful.

– Dale

HI@ dale,
I just want to add up all the vector of the faces which share the vertex, but it seam have some thing wrong in my code that return the wrong result to me, Am I getting the faces the wrong way or getting the vertex the wrong way?

Hi @suc_kiet,

Why don’t you just use the vertex normal, which is an average of the face normals?

– Dale

ON_3dVector ve_s = mesh->m_FN[faces[0]];
for (int i = 1; i < faces.Count(); i++)
{
	ON_3dVector ve_e = mesh->m_FN[faces[i]];
	ve_s = ve_s + ve_e;
}

I think I have get it by this way, but it seam wrong

HI@Dale,
In my opinion, if my code is run good, the return point should be in the direction of this red line instead of being in the purple spot

.