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
Reply
Message 1 of 6
majklha
372 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
835700012
in reply to: majklha

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
majklha
in reply to: 835700012

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
835700012
in reply to: majklha

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
majklha
in reply to: 835700012

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)
{
	ads_point arPt;
	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();

example.png

Message 6 of 6
majklha
in reply to: majklha

I have solved it.

			for(int i = 0; i < pPoly->numVerts(); i++)
			{
				double param;
				if(pPoly->onSegAt(i, asPnt2d(ptNear), param) == Adesk::kTrue)
					acutPrintf(L"\nVertex No: %i, param %.3f", i, param);
			}

 The found method is onSegAt(..). 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Autodesk Design & Make Report