在运用的时候,会遇到想找收集相链接的墙,用API提供的方法的话,总是会出错。会漏掉一些自己需要的墙,因此,下面封装了一个可以计算墙的是否连接的方法,先上代码后讲解Just Do It!!!
public bool IsConnected(Wall judgeWall, Wall proWall)
{
bool result = false;
Line judgeLocationLine = ((judgeWall.Location as LocationCurve).Curve as Line).SetZ();
Line proLocationLine = ((proWall.Location as LocationCurve).Curve as Line).SetZ();
//只对平行的处理
if (!judgeLocationLine.Direction.IsParallel(proLocationLine.Direction)) return result;
var judgeGeo = judgeWall.get_Geometry(new Options());
Face jugeDownFace = GeoEx.GetGeoEleDownFace(judgeGeo);
var proGeo = proWall.get_Geometry(new Options());
Face proDownFace = GeoEx.GetGeoEleDownFace(proGeo);
List<Solid> solidList = new List<Solid>();
//收集几何体
double judgeSolidSurfaceArea = 0;
double prosolidSurfaceArea = 0;
List<Solid> judgeSolids = GeoEx.GetSolids(judgeGeo);
List<Solid> proSolids = GeoEx.GetSolids(proGeo);
foreach (var judgeSolid in judgeSolids)
{
judgeSolidSurfaceArea += judgeSolid.SurfaceArea;
solidList.Add(judgeSolid);
}
foreach (var proSolid in proSolids)
{
prosolidSurfaceArea += proSolid.SurfaceArea;
solidList.Add(proSolid);
}
Solid fuseSolid = SolidBatchBoolean(solidList,BooleanOperationsType.Union);
if (judgeSolidSurfaceArea + prosolidSurfaceArea - fuseSolid.SurfaceArea > 0)
{
result = true;
}
return result;
}
public Solid SolidBatchBoolean(List<Solid> solids, BooleanOperationsType booleanOperationsType)
{
Solid firstSolid = solids[0];
solids.RemoveAt(0);
//对所有的几何体进行融合
foreach (var oneSoild in solids)
{
try
{
firstSolid = GeoEx.SolidBooleanOperation(firstSolid, oneSoild, booleanOperationsType);
}
catch
{
}
}
return firstSolid;
}
案例中是只对当前状况下
思路:
取两个墙的Solid,进行布尔运算的并集运算,然后计算新的solid的表面积,最后对表面积进行数值上的比较。如果表面积大于两个solid的话说明是相连接的。
这次分享就这些了,关注我,日常更新小技巧