Thanks, kdub. I mean I should know one point is lie on one linesegment. I enclosed my working video.
As you can see in my video I moved two points to one Polyline. But my code returns two polylines are not touched eachother. Followings are my code.
BlockTable acBlkTbl;
acBlkTbl = acCurrTrans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = acCurrTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;
Point3d acPt3d = new Point3d(right1.X, 0, 0);
Vector3d acVec3d = acPt3d.GetVectorTo(new Point3d(left2.X, 0, 0));
for (int i = 0; i < pln1.NumberOfVertices; i++)
{
Point3d pt = pln1.GetPoint3dAt(i);
if (pt.X == right1.X)
{
pln1.SetPointAt(i, new Point2d(left2.X, pt.Y));
}
}
bool istch = NBCrelate.checkTwoPlineTouch(pln2, pln1);
if (istch)
Application.ShowAlertDialog("Two Polyline touched");
public static bool checkTwoPlineTouch(Polyline pl1, Polyline pl2) // this checks two polyline is close.
{
bool btch = false;
int tchcnt = 0;
for (int i = 0; i < pl2.NumberOfVertices; i++)
{
if (IsPointOnPolyline(pl1, pl2.GetPoint3dAt(i)))
{
tchcnt++;
}
}
if (tchcnt >= 2)
btch = true;
tchcnt = 0;
if (!btch)
{
for (int i = 0; i < pl1.NumberOfVertices; i++)
{
if (IsPointOnPolyline(pl2, pl1.GetPoint3dAt(i)))
{
tchcnt++;
}
}
if (tchcnt >= 2)
btch = true;
}
return btch;
}
public static bool IsPointOnPolyline(Polyline pl, Point3d pt) // this returns point is on polyline or not.
{
bool isOn = false;
for (int i = 0; i < pl.NumberOfVertices; i++)
{
Curve3d seg = null;
Curve seg1 = null;
SegmentType segType = pl.GetSegmentType(i);
if (segType == SegmentType.Arc)
seg = pl.GetArcSegmentAt(i);
else
if (segType == SegmentType.Line)
seg = pl.GetLineSegmentAt(i);
//seg1 = pl.GetLineSegment2dAt(i);
if (seg != null)
{
//isOn = seg.IsOn(pt);
isOn= IsPointOnCurveGDAP(seg, pt);
if (isOn)
break;
}
}
return isOn;
}
I saw moved Polyline's Point is equal to target polylines's left vertex X coordinate.
But IsPointOnPolyline function does not return true. I dont know cause. Could you tell me?