Community
ObjectARX
cancel
Showing results for
Show  only  | Search instead for
Did you mean:

## Get the vertex of a polyline (curve) according to the point on curve

5 REPLIES 5
Message 1 of 6
363 Views, 5 Replies

## Get the vertex of a polyline (curve) according to the point on curve

I have a curve (eg. acdbPolyline or acdbMPolygon) and a point. I know the point is on the curve. (I used GetClosestPointTo....)

How I get a vertex of the Poly, whitch the point lies on?

5 REPLIES 5
Message 2 of 6

what do you want? all vertex on the polyline?

int num = poly->numberVertex();

for(int i = num; i < num; i++)

{

acgePoint2d pt;

poly->getpointAt(i, pt);

}

is this what you need?

Message 3 of 6

Thanks for reply and sorry for bed question.

I try to write it other way: I have a point and I know, it lies on the polyline (curve).

I need to find out, which vertex it belongs to.

Message 4 of 6

int num = poly->numberVertex();

acgepoint2d yourPt;

for(int i = num; i < num; i++)

{

acgePoint2d pt;

poly->getpointAt(i, pt);

if(pt.DistanceTo(yourPT) < 1e-3)

return i;

}

get the distance you can find out the index you need

Message 5 of 6

It does not work.

Because I have a point somewhere on vertex but getPointAt(int, pt) return begin point of vertex.

My code:

``````//pEntPol IS SELECTED BY SSGET
AcDbPolyline *pPoly = AcDbPolyline::cast(pEntPol);
if(!pPoly)
{
pEntPol->close();
return;
}

int res = RTNORM;
while(res == RTNORM)
{
res = acedGetPoint(NULL, L"\nZadej bod:", arPt);
if(res == RTNORM)
{
AcGePoint3d ptBod = asPnt3d(arPt);
AcGePoint3d ptNear;
pPoly->getClosestPointTo(ptBod, ptNear);
MajDraw::UkazBod(asPnt2d(ptNear)); //it shows point on autocad - blue
///ptNear - point somewhere on polyline

for(int i = 0; i < pPoly->numVerts(); i++)
{
AcGePoint2d pt;
pPoly->getPointAt(i, pt); //find base point of Vertex
MajDraw::UkazBod(pt); //it shows point on autocad - yellow
if(pt.distanceTo(asPnt2d(ptNear)) < 1e-3)
acutPrintf(L"\nVertex No: %i", i);
}
}
}

pEntPol->close();``````

Message 6 of 6

I have solved it.

``````			for(int i = 0; i < pPoly->numVerts(); i++)
{
double param;