Author Topic: Work with Polyline  (Read 2105 times)

0 Members and 1 Guest are viewing this topic.

Integer

  • Guest
Work with Polyline
« on: March 16, 2007, 09:58:57 AM »
 Hi
 I have one question.
 First I draw one AcDb3dPolyline with for example 5 vertex. Then draw second polyline. How to find is first (or last point, not matter) of second polyline on first polyline? I have a AcGePoint3d but how to check if is on polyline?
  :|

 

Chuck Gabriel

  • Guest
Re: Work with Polyline
« Reply #1 on: March 16, 2007, 10:11:36 AM »
You could try using AcDbPolyline::getClosestPointTo() with the vertex in question as the givenPoint argument, and then checking to see if the  value returned in pointOnCurve is equal to givenPoint.  Of course "equal" is kind of a fuzzy definition in this case.

By the way, welcome to the swamp.

Integer

  • Guest
Re: Work with Polyline
« Reply #2 on: March 16, 2007, 11:00:29 AM »
Thx for welcome.  :-)

Ok, if I understended. I need to do something like this:
Code: [Select]
int point_in_poly(AcGePoint3d p, AcDb3dPolyline *pPolyline)
{
double fuzz = AcGeContext::gTol.equalPoint();
AcGePoint3d pointOnCurve;
pPolyline->getClosestPointTo(p,pointOnCurve);

if (p.distanceTo(pointOnCurve) <= fuzz)
return 0;
return 1;
}
   First parameter(AcGePoint3d p) is point we are checking and second parameter(AcDb3dPolyline *pPolyline)
   is first polyline we draw? In getClosestPointTo() function we get value of closest point on that polyline and it will be stored in pointOnCurve.
   Then we are checking distance from our point and that point on polygon. If is smaller then fuzz our point is on that polygon.
   Hm... thats how I understand is that TRUE or i miss something?
   
   All this doing because I need to do that if some polyline is drawn over another(only first and last point checking) I need to split that polyline to two parts shown in pictures:
   1. First situation, just before ending drawing second polyline:
   
   2. Result when we end drawing second polyline:
   
   
   Sry for bad english.
« Last Edit: March 16, 2007, 11:03:11 AM by Integer »

Chuck Gabriel

  • Guest
Re: Work with Polyline
« Reply #3 on: March 16, 2007, 11:28:24 AM »
The code you have there looks right to me.  In fact I would say it is quite good.  I might be inclined to have it return a bool instead of an int, but that is just an issue of preference.