/// <summary> /// 拿到一条线到一个楼板上的投影,此处针对的是某一个楼板 /// </summary> /// <param name="line"></param> /// <param name="floor"></param> /// <returns></returns> public Curve FindFloorcurve(Curve line, Floor floor) { var floorgeom = floor.get_Geometry(GetgeometryOptions()); var geomobj = floorgeom.First <GeometryObject>(); Solid floorobj = geomobj as Solid; double facearea = 0; PlanarFace pf = null; PlanarFace pf_target = null; foreach (Face face in floorobj.Faces) { pf = face as PlanarFace; if (pf.Area > facearea && pf.FaceNormal.Z >= 0) { //拿到楼板上面的一个面 facearea = pf.Area; pf_target = pf; } } TaskDialog.Show("ss", pf_target.Area.ToString()); XYZ point_start = pf_target.Project(line.GetEndPoint(0)).XYZPoint; XYZ point_end = pf_target.Project(line.GetEndPoint(1)).XYZPoint; Curve curve = Line.CreateBound(point_start, point_end); return(curve); }
/// <summary> /// 拿到一条线投影到一个面上面 /// </summary> /// <param name="line"></param> /// <param name="face_refer"></param> /// <returns></returns> public Curve FindFacecurve(Curve line, PlanarFace face) { XYZ point_start = face.Project(line.GetEndPoint(0)).XYZPoint; XYZ point_end = face.Project(line.GetEndPoint(1)).XYZPoint; Curve curve = Line.CreateBound(point_start, point_end); return(curve); }
/// <summary> /// Compute the distance between two planar faces. /// </summary> /// <param name="face1">Face 1</param> /// <param name="face2">Face 2</param> /// <returns>Distance of the two planar faces</returns> private static double GetDistance(PlanarFace face1, PlanarFace face2) { BoundingBoxUV boxUV = face2.GetBoundingBox(); UV center = (boxUV.Max + boxUV.Min) * 0.5; XYZ centerPt = face2.Evaluate(center); IntersectionResult result = face1.Project(centerPt); return(face1.Project(centerPt).Distance); }
/// <summary> /// 获得与UV点相交的面 /// </summary> /// <param name="geometryElement"></param> /// <param name="point"></param> /// <returns></returns> PlanarFace getTarFace(GeometryElement geometryElement, XYZ point) { PlanarFace face = null; //遍历几何元素里的几何object foreach (GeometryObject geometryObject in geometryElement) { //将 geometryObject强转为 solid Solid solid = geometryObject as Solid; //遍历solid的面 if (solid != null && solid.Faces.Size > 0) { foreach (Face f in solid.Faces) { PlanarFace pFace = f as PlanarFace; if (pFace != null) { try { //获取点到面的距离为0的点 if (Math.Abs(pFace.Project(point).Distance) < 1e-4) { face = pFace; break; } } catch { continue; } } } } if (face != null) { break; } } // if (face == null) { foreach (GeometryObject geometryObject in geometryElement) { GeometryInstance geoIns = geometryObject as GeometryInstance; if (geoIns != null) { face = getTarFace(geoIns.GetInstanceGeometry(), point); } } } return(face); }
/// <summary> ///获得与UV点相交的面 /// </summary> /// <param name="geometryElement"></param> /// <param name="point"></param> /// <returns></returns> PlanarFace getTarFace(GeometryElement geometryElement, XYZ point) { PlanarFace face = null; foreach (GeometryObject geometryObject in geometryElement) { Solid solid = geometryObject as Solid; if (solid != null && solid.Faces.Size > 0) { foreach (Face f in solid.Faces) { PlanarFace pFace = f as PlanarFace; if (pFace != null) { try { if (Math.Abs(Math.Round(pFace.Project(point).Distance, 2)) < 1e-6)// { face = pFace; break; } } catch { continue; } } } } if (face != null) { break; } } if (face == null) { foreach (GeometryObject geometryObject in geometryElement) { GeometryInstance geomIns = geometryObject as GeometryInstance; if (geomIns != null) { face = getTarFace(geomIns.GetInstanceGeometry(), point); } } } return(face); }
static internal XYZ AdjustTopPointToRoofAngle(XYZ targetTopPoint, IList <XYZ> supportPoints, EdgeInfo currentRidgeInfo) { if (currentRidgeInfo.RelatedPanelFaces == null || currentRidgeInfo.RelatedPanelFaces.Count < 1) { currentRidgeInfo.RelatedPanelFaces = currentRidgeInfo.GetRelatedPanels(); } if (currentRidgeInfo.RelatedPanelFaces == null || currentRidgeInfo.RelatedPanelFaces.Count < 1) { return(targetTopPoint); } PlanarFace relatedFace = currentRidgeInfo.RelatedPanelFaces[0] as PlanarFace; if (relatedFace == null) { return(targetTopPoint); } Line ridgeLine = currentRidgeInfo.Curve as Line; if (ridgeLine == null) { return(targetTopPoint); } XYZ ridgeDirection = ridgeLine.Direction; XYZ ridgeDirectionCrossed = ridgeDirection.CrossProduct(XYZ.BasisZ); XYZ projectedPoint = targetTopPoint.Add(ridgeDirectionCrossed.Multiply(0.1)); IntersectionResult iResult = relatedFace.Project(projectedPoint); if (iResult == null) { projectedPoint = targetTopPoint.Add(ridgeDirectionCrossed.Negate().Multiply(0.1)); iResult = relatedFace.Project(projectedPoint); if (iResult == null) { return(targetTopPoint); } } //Just to make sure that the targetTopPoint is located on Ridge IntersectionResult ridgeProjected = ridgeLine.Project(targetTopPoint); if (ridgeProjected != null) { targetTopPoint = ridgeProjected.XYZPoint; } XYZ roofSlopeLineDirection = Line.CreateBound(iResult.XYZPoint, targetTopPoint).Direction; if (supportPoints == null || supportPoints.Count < 1) { return(targetTopPoint); } //This code assumes that there are 1 or 2 supportPoints XYZ supportPoint = supportPoints[0]; if (supportPoints.Count == 2) { XYZ supportPoints1 = supportPoints[1]; if (supportPoints1.DistanceTo(projectedPoint) < supportPoint.DistanceTo(projectedPoint)) { supportPoint = supportPoints1; } } Line roofSlopeLine = Line.CreateUnbound(supportPoint, roofSlopeLineDirection); Line roofRidgeLine = Line.CreateUnbound(targetTopPoint, XYZ.BasisZ); IntersectionResultArray iResultArrCurves = null; roofSlopeLine.Intersect(roofRidgeLine, out iResultArrCurves); if (iResultArrCurves != null && iResultArrCurves.Size == 1) { return(iResultArrCurves.get_Item(0).XYZPoint); } return(targetTopPoint); }
/// <summary> /// Compute the distance between two planar faces. /// </summary> /// <param name="face1">Face 1</param> /// <param name="face2">Face 2</param> /// <returns>Distance of the two planar faces</returns> private static double GetDistance(PlanarFace face1, PlanarFace face2) { BoundingBoxUV boxUV = face2.GetBoundingBox(); UV center = (boxUV.Max + boxUV.Min) * 0.5; XYZ centerPt = face2.Evaluate(center); IntersectionResult result = face1.Project(centerPt); return face1.Project(centerPt).Distance; }