拾取一个点坐标,找到包围这个坐标的最小封闭区域问题
本帖最后由 kuaigoumanzhu 于 2011-1-18 15:31 编辑开始没一点思路,后来在论坛看了一天的帖子。现在是先拾取一个点坐标,然后找到所有封闭区域的顶点坐标然后再计算这个点是否在封闭区域内。BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = trans.GetObject(bt, 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("在封闭区域中");
}
}
这个是测试时候的代码。 这种方法需要比较的太多,还有那个算点是否在封闭区域内的算法,也不明白。有什么更好的没有大家多多指点啊。 http://bbs.mjtd.com/thread-84681-1-1.html 本帖最后由 dafeilang 于 2011-3-13 19:31 编辑
(bpoly (getpoint "ss"))找输入点周围的封闭图形并创建多段线
然后可以求创建的面域的面积 (也是在网上学的,这个命令)
不好意思,搜求坐标点的方法的时候进错版了,我以为是Lisp版
新手学习!
页:
[1]