本帖最后由 kuaigoumanzhu 于 2011-1-18 15:31 编辑
开始没一点思路,后来在论坛看了一天的帖子。现在是先拾取一个点坐标,然后找到所有封闭区域的顶点坐标然后再计算这个点是否在封闭区域内。- BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
- Polyline p = new Polyline();
- Point3d a = new Point3d();
- PromptPointOptions opt = new PromptPointOptions("选择点");
- PromptPointResult rest = ed.GetPoint(opt);
- if (rest.Status == PromptStatus.OK)
- {
- a = rest.Value;
- }
- TypedValue[] pline ={ new TypedValue((int)DxfCode.Start, "LWPOLYLINE") };
- SelectionFilter sf = new SelectionFilter(pline);
- PromptSelectionResult res = ed.SelectAll(sf);
- SelectionSet st = res.Value;
- if (st != null)
- {
- ObjectId[] ids = st.GetObjectIds();
- Point3dCollection p3dc=new Point3dCollection();
- foreach (ObjectId id in ids)
- {
- p = trans.GetObject(id, OpenMode.ForRead) as Polyline;
- //Point3d c = new Point3d((p.c));
- int j=p.NumberOfVertices-1;
- bool result = false;
- for (int i = 0; i < p.NumberOfVertices; i++)
- {
- p3dc.Add(p.GetPoint3dAt(i));
- //nodes.Add(p.GetPoint3dAt(i));
- ed.WriteMessage(p.GetPoint3dAt(i).ToString());
-
- if (((p.GetPoint3dAt(i).Y)<=a.Y)&&(a.Y<p.GetPoint3dAt(j).Y)||((p.GetPoint3dAt(j).Y<a.Y))&&a.Y<(p.GetPoint3dAt(i).Y))
- {
- if ((a.X - p.GetPoint3dAt(i).X) < (p.GetPoint3dAt(j).X - p.GetPoint3dAt(i).X) * (a.Y - p.GetPoint3dAt(i).Y) / (p.GetPoint3dAt(j).Y - p.GetPoint3dAt(i).Y))
- {
- result = !result;
- }
- }
- j = i;
- }
- if (result)
- {
- MessageBox.Show("在封闭区域中");
- }
- }
这个是测试时候的代码。 |