Hi,
You can use a MPolygon, a MAP entity which is also available in vanilla while the AcMPolygonObj##.dbx module is loaded.
In your project, you'll also have to add a reference to the AcMPolygonMGD.dll (you'll find it in the AutoCAD installation folder.
Here's a little sample with a testing command, it implements IExtensionApplication interface to load the module at startup.
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace PointInside
{
public class CommandMethods : IExtensionApplication
{
public void Initialize()
{
SystemObjects.DynamicLinker.LoadModule(
"AcMPolygonObj" + Application.Version.Major + ".dbx", false, false);
}
public void Terminate() { }
private bool IsPointInside(Point3d point, Polyline pline)
{
double tolerance = Tolerance.Global.EqualPoint;
using (MPolygon mpg = new MPolygon())
{
mpg.AppendLoopFromBoundary(pline, true, tolerance);
return mpg.IsPointInsideMPolygon(point, tolerance).Count == 1;
}
}
[CommandMethod("Test")]
public void Test()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
peo.SetRejectMessage("Only a polyline !");
peo.AddAllowedClass(typeof(Polyline), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForRead);
PromptPointOptions ppo = new PromptPointOptions("\nPick a point <quit>: ");
ppo.AllowNone = true;
while (true)
{
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
break;
Application.ShowAlertDialog(
IsPointInside(ppr.Value, pline) ? "Inside" : "Outside");
}
}
}
}
}