马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[C#] 纯文本查看 复制代码
public static void testPointInside(Point3d inPt, ObjectId objid)
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Polyline pPoly = tr.GetObject(objid, OpenMode.ForRead, false) as Polyline;
if (pPoly is Polyline)
{
if (!pPoly.Closed)
{
ed.WriteMessage("\n*** Curve is not closed. "); return;
}
Point3dCollection points = new Point3dCollection();
pPoly.IntersectWith(pPoly, Intersect.OnBothOperands, points, 0, 0);
if (!points.Count.Equals(pPoly.NumberOfVertices))
{
ed.WriteMessage("\n*** Curve self intersect!"); return;
}
else
{
Point3d P = new Point3d();
P = Ucs2Wcs(inPt);
Point3d ClosestPoint = pPoly.GetClosestPointTo(P, false);
if (P.IsEqualTo(ClosestPoint))
{
ed.WriteMessage("\n*** Point is on curve. "); return;
}
Double ClosestParam, EndParam;
ClosestParam = pPoly.GetParameterAtPoint(ClosestPoint);
ClosestPoint = Wcs2Ucs(ClosestPoint);
EndParam = pPoly.EndParam;
Double Param1 = 0.0, Param2 = dVal, Deflection = 0.0, a2;
Point3d StartPT = pPoly.StartPoint;
StartPT = Wcs2Ucs(StartPT);
Double a1 = Math.Atan2(StartPT.Y - inPt.Y, StartPT.X - inPt.X);
while (Param2 <= EndParam)
{
Param2 = Math.Min(Param2, EndParam);
if (Param1 < ClosestParam && ClosestParam < Param2)
{
a2 = Math.Atan2(ClosestPoint.Y - inPt.Y, ClosestPoint.X - inPt.X);
Deflection = Deflection + delta(a1, a2);
a1 = a2;
}
bool test = true;
while (test)
{
try
{
P = pPoly.GetPointAtParameter(Param2);
Param2 = Param2 + dVal;
}
catch (System.Exception ex)
{
ed.WriteMessage("\nERROR = " + ex.Message);
}
finally
{
test = false;
}
}
P = Wcs2Ucs(P);
a2 = Math.Atan2(P.Y - inPt.Y, P.X - inPt.X);
Deflection = Deflection + delta(a1, a2);
a1 = a2;
Param1 = Param2;
Param2 = Param2 + dVal;
}
if (Math.Abs(Deflection) > 4)
ed.WriteMessage("\n*** Point is inside. ");
else
ed.WriteMessage("\n*** Point is outside. ");
}
}
tr.Commit();
}
} |