コード例 #1
0
        private List <Line> GetSquare(Line infLine0, Line infLine1, Line infLine2, Line infLine3)
        {
            IntersectionResultArray iresArray1;
            SetComparisonResult     result1 = infLine0.Intersect(infLine2, out iresArray1);
            IntersectionResult      ires1   = iresArray1.get_Item(0);
            XYZ point1 = ires1.XYZPoint;

            IntersectionResultArray iresArray2;
            SetComparisonResult     result2 = infLine0.Intersect(infLine3, out iresArray2);
            IntersectionResult      ires2   = iresArray2.get_Item(0);
            XYZ point2 = ires2.XYZPoint;

            IntersectionResultArray iresArray3;
            SetComparisonResult     result3 = infLine1.Intersect(infLine2, out iresArray3);
            IntersectionResult      ires3   = iresArray3.get_Item(0);
            XYZ point3 = ires3.XYZPoint;

            IntersectionResultArray iresArray4;
            SetComparisonResult     result4 = infLine1.Intersect(infLine3, out iresArray4);
            IntersectionResult      ires4   = iresArray4.get_Item(0);
            XYZ point4 = ires4.XYZPoint;

            List <Line> retLines = new List <Line>();

            retLines.Add(Line.CreateBound(point1, point2));
            retLines.Add(Line.CreateBound(point2, point4));
            retLines.Add(Line.CreateBound(point4, point3));
            retLines.Add(Line.CreateBound(point3, point1));

            return(retLines);
        }
コード例 #2
0
        public void SeparateRooms()
        {
            List <(Wall, bool[])> openWalls = GetOpenWalls(Walls);

            foreach ((Wall, bool[])openWall in openWalls)
            {
                // inital filtering
                (Wall wall, bool[] connected) = openWall;
                Line        wallLine   = GetWallLine(wall);
                List <Wall> candidates = new List <Wall>();
                foreach (Wall w in Walls)
                {
                    Line wLine = GetWallLine(w);
                    SetComparisonResult result = wallLine.Intersect(wLine);
                    if (result == SetComparisonResult.Disjoint)
                    {
                        candidates.Add(w);
                    }
                }

                XYZ p0, p1;
                if (!connected[0])
                {
                    p0 = wallLine.GetEndPoint(1);
                    p1 = wallLine.GetEndPoint(0);
                    PlaceRoomSeparatorInOpenWall(wallLine, candidates, p0, p1);
                }
                if (!connected[1])
                {
                    p0 = wallLine.GetEndPoint(0);
                    p1 = wallLine.GetEndPoint(1);
                    PlaceRoomSeparatorInOpenWall(wallLine, candidates, p0, p1);
                }
            }
        }
コード例 #3
0
        public static List <List <Curve> > GetSplitByVerticalLine(this List <Curve> profile, Line splitLine)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            if (splitLine == null)
            {
                throw new ArgumentNullException("splitLine");
            }

            if (!(splitLine.Direction.IsAlmostEqualTo(XYZ.BasisZ) || splitLine.Direction.IsAlmostEqualTo(XYZ.BasisZ.Negate())))
            {
                throw new ArgumentException("Line must be vertical");
            }

            var result = new List <List <Curve> >();

            var profile1 = new List <Curve>();
            var profile2 = new List <Curve>();

            foreach (var curve in profile)
            {
                IntersectionResultArray intersectionResultArray;
                SetComparisonResult     setComparisonResult = curve.Intersect(splitLine, out intersectionResultArray);

                //curve.
            }

            return(result);
        }
コード例 #4
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var crv1 = (Curve)((Value.Container)args[0]).Item;
            var crv2 = (Curve)((Value.Container)args[1]).Item;

            IntersectionResultArray xsects;
            SetComparisonResult     result = crv1.Intersect(crv2, out xsects);

            var xyz = FSharpList <Value> .Empty;
            var u   = FSharpList <Value> .Empty;
            var v   = FSharpList <Value> .Empty;

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    xyz = FSharpList <Value> .Cons(Value.NewContainer(ir.XYZPoint), xyz);

                    u = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.U), u);

                    v = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.V), v);

                    pts.Add(ir.XYZPoint);
                }
            }

            outPuts[_vPort]      = Value.NewList(v);
            outPuts[_uPort]      = Value.NewList(u);
            outPuts[_xyzPort]    = Value.NewList(xyz);
            outPuts[_resultPort] = Value.NewString(result.ToString());
        }
コード例 #5
0
ファイル: RequestHandler.cs プロジェクト: inktan/RevitApi_
        //求出轴网和基准线的相交点,以点的位置比例和轴网建立字典
        public IDictionary <double, Grid> GetInterGridDict(IList <Element> girdsElements, Line baseCurve)
        {
            IDictionary <double, Grid> dictParaGrid = new Dictionary <double, Grid>(); //创建字典,double为相交点在基准线上的比例位置, Grid为相交轴线

            foreach (Element ele in girdsElements)                                     //求出各个轴网与所画直线的关系
            {
                Grid   grid_tmep          = ele as Grid;
                Line   grid_curve         = grid_tmep.Curve as Line;
                XYZ    direction          = grid_curve.Direction;
                XYZ    middleXyz          = (grid_curve.GetEndPoint(0) + grid_curve.GetEndPoint(1)) / 2;//求出线段的中点
                double d                  = 10000;
                XYZ    startPoint         = middleXyz + direction * d;
                XYZ    endPoint           = middleXyz - direction * d;
                Line   grid_curve_newLine = Line.CreateBound(startPoint, endPoint);
                IntersectionResultArray results;
                SetComparisonResult     result = baseCurve.Intersect(grid_curve_newLine, out results);
                if (result == SetComparisonResult.Overlap)    //判断基准线是否与轴网相交
                {
                    if (results != null && results.Size == 1) //判断交点的数量是否为1
                    {
                        double             intersectPara;
                        IntersectionResult iResult    = results.get_Item(0);             //发现无法直接获取相交点在基准线上的二维比例位置
                        XYZ intersectXYZ              = iResult.XYZPoint;                //得到基准线和轴网的交点
                        IntersectionResult projectXyz = baseCurve.Project(intersectXYZ); //获得交点在基准线上的投影点
                        intersectPara = projectXyz.Parameter;                            //将投影点转化为在基准线上的一维距离比例位置
                        dictParaGrid.Add(intersectPara, grid_tmep);
                    }
                }
            }
            return(dictParaGrid);
        }
コード例 #6
0
        // Shatter a bunch of curves according to their intersections
        public static List <Curve> ExplodeCrv(List <Curve> C)
        {
            // Start by Shattering all of your input curves by intersecting them with each other
            List <Curve> shatters = new List <Curve>();

            for (int CStart = 0; CStart <= C.Count - 1; CStart++)
            {
                List <double> breakParams = new List <double>();
                for (int CCut = 0; CCut <= C.Count - 1; CCut++)
                {
                    if (CStart != CCut)
                    {
                        SetComparisonResult result = C[CStart].Intersect(C[CCut], out IntersectionResultArray results);
                        if (result != SetComparisonResult.Disjoint)
                        {
                            //XYZ breakPt = results.get_Item(0).XYZPoint;
                            //Debug.Print("The intersection point is (" + breakPt.X.ToString() + ", " + breakPt.Y.ToString() + ")");
                            //double breakParam = C[CStart].Project(breakPt).Parameter;
                            // Another way to get the intersection parameter
                            double breakParam = results.get_Item(0).UVPoint.U;
                            breakParams.Add(breakParam);
                            //Debug.Print("Projection parameter is: " + breakParam.ToString());
                            //Debug.Print("The raw parameter of the No." + CStart.ToString() + " intersection is " + breakParam.ToString());
                        }
                    }
                }
                shatters.AddRange(SplitCrv(C[CStart], breakParams));
            }
            return(shatters);
        }
コード例 #7
0
        public static bool CheckIsIntersectsRebarAndElement(Document doc, Autodesk.Revit.DB.Structure.Rebar rebar, Element elem, View view, Transform linkTransform)
        {
            GeometryElement geoElem = elem.get_Geometry(new Options());
            List <Solid>    solids  = GetSolidsOfElement(geoElem);

#if R2017
            List <Curve> rebarCurves = rebar.ComputeDrivingCurves().ToList();
#else
            List <Curve> rebarCurves = rebar.GetShapeDrivenAccessor().ComputeDrivingCurves().ToList();
#endif
            for (int i = 0; i < solids.Count; i++)
            {
                Solid s = solids[i];
                if (!linkTransform.IsIdentity)
                {
                    s = SolidUtils.CreateTransformed(s, linkTransform.Inverse);
                }
                foreach (Face face in s.Faces)
                {
                    foreach (Curve rebarCurve in rebarCurves)
                    {
                        SetComparisonResult result = face.Intersect(rebarCurve);
                        if (result == SetComparisonResult.Overlap)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #8
0
        private XYZ GetPointIntersecWithWall(Wall wall, Line cuttingLine, out bool isOvelapWithAnotherWindown)
        {
            isOvelapWithAnotherWindown = false;
            List <Solid> solids = GetSolidFromWall(wall);

            foreach (Solid solid in solids)
            {
                if (solid.Faces != null && solid.Faces.Size > 0)
                {
                    foreach (Face face in solid.Faces)
                    {
                        SetComparisonResult result = face.Intersect(cuttingLine, out IntersectionResultArray intersectionResultArray);
                        if (result == SetComparisonResult.Overlap || result == SetComparisonResult.Subset)
                        {
                            if (intersectionResultArray != null)
                            {
                                for (int i = 0; i < intersectionResultArray.Size; i++)
                                {
                                    IntersectionResult intersectionResult = intersectionResultArray.get_Item(i);
                                    if (intersectionResult.XYZPoint != null)
                                    {
                                        return(intersectionResult.XYZPoint);
                                    }
                                }
                            }
                            else
                            {
                                isOvelapWithAnotherWindown = true;
                            }
                        }
                    }
                }
            }
            return(null);
        }
コード例 #9
0
        private void GetIntersectionPoints()
        {
            IntersectionResultArray iresArray1;
            SetComparisonResult     result1 = Line1.Intersect(Line3, out iresArray1);
            IntersectionResult      ires1   = iresArray1.get_Item(0);

            Point1 = ires1.XYZPoint;

            IntersectionResultArray iresArray2;
            SetComparisonResult     result2 = Line1.Intersect(Line4, out iresArray2);
            IntersectionResult      ires2   = iresArray2.get_Item(0);

            Point2 = ires2.XYZPoint;

            IntersectionResultArray iresArray3;
            SetComparisonResult     result3 = Line2.Intersect(Line3, out iresArray3);
            IntersectionResult      ires3   = iresArray3.get_Item(0);

            Point3 = ires3.XYZPoint;

            IntersectionResultArray iresArray4;
            SetComparisonResult     result4 = Line2.Intersect(Line4, out iresArray4);
            IntersectionResult      ires4   = iresArray4.get_Item(0);

            Point4 = ires4.XYZPoint;
        }
コード例 #10
0
        public List <CurveArray> DividePolygonInHalf(XYZ divisionDirection, out Line cutLine)
        {
            Normalize();

            CircularLinkedList <UV>             points    = GetPoints();
            List <CircularLinkedListNode <UV> > newPoints = new List <CircularLinkedListNode <UV> >();

            UV centroid = CalculatePolygonCentroid(points);

            cutLine = Line.CreateUnbound(VectorManipulator.TransformUVinXYZ(centroid), divisionDirection);

            foreach (Curve curve in curveArray)
            {
                SetComparisonResult result = cutLine.Intersect(curve, out IntersectionResultArray resultArray);
                if (result == SetComparisonResult.Overlap)
                {
                    UV  newPoint = VectorManipulator.ProjectInPlaneXY(resultArray.get_Item(0).XYZPoint);
                    XYZ p0       = curve.GetEndPoint(0);
                    XYZ p1       = curve.GetEndPoint(1);
                    newPoints.Add(AddPointBetween(points, VectorManipulator.ProjectInPlaneXY(p0), VectorManipulator.ProjectInPlaneXY(p1), newPoint));
                }
            }

            CircularLinkedList <UV> newPolygon0 = CreatePolygonBetweenVertices(newPoints[0], newPoints[1]);
            CircularLinkedList <UV> newPolygon1 = CreatePolygonBetweenVertices(newPoints[1], newPoints[0]);

            List <CurveArray> dividedCurveArrays = new List <CurveArray>
            {
                CreateCurveArrayFromPoints(newPolygon0),
                CreateCurveArrayFromPoints(newPolygon1)
            };

            cutLine = Line.CreateBound(VectorManipulator.TransformUVinXYZ(newPoints[0].Value), VectorManipulator.TransformUVinXYZ(newPoints[1].Value));
            return(dividedCurveArrays);
        }
コード例 #11
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uiDoc.Document;
            FilteredElementCollector coll       = new FilteredElementCollector(doc);
            ElementClassFilter       gridFilter = new ElementClassFilter(typeof(Grid));
            List <Element>           grid       = coll.WherePasses(gridFilter).ToElements().ToList();
            List <Line> gridLines = new List <Line>();
            List <XYZ>  intXyzs   = new List <XYZ>();

            foreach (Grid g in grid)
            {
                gridLines.Add(g.Curve as Line);
            }

            foreach (Line line1 in gridLines)
            {
                foreach (Line line2 in gridLines)
                {
                    XYZ normal1 = line1.Direction;
                    XYZ normal2 = line2.Direction;
                    if (normal1.IsAlmostEqualTo(normal2))
                    {
                        continue;//如果平行,执行下一条
                    }

                    SetComparisonResult intRst = line1.Intersect(line2, out IntersectionResultArray results);
                    if (intRst == SetComparisonResult.Overlap && results.Size == 1)
                    {
                        XYZ tp = results.get_Item(0).XYZPoint;
                        if (intXyzs.Where(m => m.IsAlmostEqualTo(tp)).Count() == 0)
                        {
                            intXyzs.Add(tp);//如果不重复,则添加该交点
                        }
                    }
                }
            }

            Level        level        = doc.GetElement(new ElementId(311)) as Level;
            FamilySymbol familySymbol = doc.GetElement(new ElementId(338370)) as FamilySymbol;

            using (Transaction tr = new Transaction(doc)) {
                tr.Start("Clomn");
                if (!familySymbol.IsActive)
                {
                    familySymbol.Activate();
                }

                foreach (XYZ xyz in intXyzs)
                {
                    FamilyInstance familyInstance =
                        doc.Create.NewFamilyInstance(xyz, familySymbol, level, StructuralType.NonStructural);
                }

                tr.Commit();
            }

            return(Result.Succeeded);
        }
コード例 #12
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc                    = commandData.Application.ActiveUIDocument;           //定义用户文件夹
            Document   revitDoc                 = uidoc.Document;                                     //将uidoc转换为Document
            FilteredElementCollector coll       = new FilteredElementCollector(revitDoc);             //创建元素过滤收集器
            ElementClassFilter       gridFilter = new ElementClassFilter(typeof(Grid));               //过滤类型为轴网的元素
            List <Element>           grid       = coll.WherePasses(gridFilter).ToElements().ToList(); //创建轴网
            List <Line> gridLines               = new List <Line>();                                  //创建轴线
            List <XYZ>  intPos                  = new List <XYZ>();                                   //创建交点

            //找到轴网交点
            foreach (Grid gri in grid)
            {
                gridLines.Add(gri.Curve as Line); //将轴网转换为线
            }
            foreach (Line ln1 in gridLines)       //找到第一根线
            {
                foreach (Line ln2 in gridLines)   //找到第二根线
                {
                    XYZ normal1 = ln1.Direction;  //得到的是直线的方向向量
                    XYZ normal2 = ln2.Direction;
                    if (normal1.IsAlmostEqualTo(normal2))
                    {
                        continue;                                                     //如果两根轴线方向相同,则遍历下一组
                    }
                    IntersectionResultArray results;                                  //交点数组
                    SetComparisonResult     intRst = ln1.Intersect(ln2, out results); //枚举,判断相交类型;如果两根轴线相交,则输出交点
                    if (intRst == SetComparisonResult.Overlap && results.Size == 1)   //除去重复的交点
                    {
                        XYZ tp = results.get_Item(0).XYZPoint;                        //获取不重复的点
                        if (intPos.Where(m => m.IsAlmostEqualTo(tp)).Count() == 0)    //比较得到的交点和intPos数组里面的元素是否相同,不同才Add到intPos数组中,作用是排除重复的点
                        {
                            intPos.Add(tp);                                           //收集所有的交点
                        }
                    }
                }
            }

            Level        level        = revitDoc.GetElement(new ElementId(13071)) as Level;        //ID为放置层标高ID
            FamilySymbol familysymbol = revitDoc.GetElement(new ElementId(72254)) as FamilySymbol; //ID为放置族类型的ID,不是族实例ID,不是具体的柱子

            using (Transaction trans = new Transaction(revitDoc))
            {
                trans.Start("dfs");
                if (!familysymbol.IsActive)
                {
                    familysymbol.Activate();                        //判断familysymbol是否为active,不是则设为Active状态
                }
                foreach (XYZ p in intPos)
                {
                    FamilyInstance familyInstance = revitDoc.Create.NewFamilyInstance(p, familysymbol, level, StructuralType.NonStructural);
                }
                trans.Commit();
            }
            return(Result.Succeeded);
        }
コード例 #13
0
        //method to find the intersection of planarface with a line from the point passed
        public static double ReturnLeastZ_Value(Document doc, IList <PlanarFace> pf, XYZ xyz, Transform trans)
        {
            try
            {
                List <XYZ> intersectionPoints = new List <XYZ>();

                Line line = doc.Application.Create.NewLineBound(trans.OfPoint(xyz), new XYZ(trans.OfPoint(xyz).X, trans.OfPoint(xyz).Y, trans.OfPoint(xyz).Z + 10));

                IntersectionResultArray resultArray = null;

                foreach (PlanarFace face in pf)
                {
                    IntersectionResult  iResult = null;
                    SetComparisonResult result  = new SetComparisonResult();

                    try
                    {
                        result = face.Intersect(line, out resultArray);
                    }
                    catch
                    {
                        continue;
                    }

                    if (result != SetComparisonResult.Disjoint)
                    {
                        try
                        {
                            iResult = resultArray.get_Item(0);
                            intersectionPoints.Add(iResult.XYZPoint);
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }

                XYZ minPoint = intersectionPoints.First();

                foreach (XYZ point in intersectionPoints)
                {
                    if (minPoint.Z > point.Z)
                    {
                        minPoint = point;
                    }
                }

                return(minPoint.Z - trans.OfPoint(xyz).Z);
            }
            catch
            {
                return(-1);
            }
        }
コード例 #14
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            Solid thisSolid  = (Solid)((FScheme.Value.Container)args[0]).Item;
            Line  selectLine = (Line)((FScheme.Value.Container)args[1]).Item;

            FaceArray faceArr  = thisSolid.Faces;
            var       thisEnum = faceArr.GetEnumerator();

            SortedList <double, Autodesk.Revit.DB.Face> intersectingFaces = new SortedList <double, Autodesk.Revit.DB.Face>();

            for (; thisEnum.MoveNext();)
            {
                Autodesk.Revit.DB.Face  thisFace    = (Autodesk.Revit.DB.Face)thisEnum.Current;
                IntersectionResultArray resultArray = null;

                SetComparisonResult resultIntersect = thisFace.Intersect(selectLine, out resultArray);
                if (resultIntersect != SetComparisonResult.Overlap)
                {
                    continue;
                }
                bool   first   = true;
                double linePar = -1.0;
                foreach (IntersectionResult ir in resultArray)
                {
                    double irPar = ir.Parameter;
                    if (first == true)
                    {
                        linePar = irPar;
                        first   = false;
                    }
                    else if (irPar < linePar)
                    {
                        linePar = irPar;
                    }
                }
                intersectingFaces.Add(linePar, thisFace);
            }

            var result = FSharpList <FScheme.Value> .Empty;

            var intersectingFacesEnum = intersectingFaces.Reverse().GetEnumerator();

            for (; intersectingFacesEnum.MoveNext();)
            {
                Autodesk.Revit.DB.Face faceObj = intersectingFacesEnum.Current.Value;
                result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(faceObj), result);
            }

            return(FScheme.Value.NewList(result));
        }
コード例 #15
0
        //
        public static bool IsOverlapped(Curve crv1, Curve crv2)
        {
            SetComparisonResult result = crv1.Intersect(crv2, out IntersectionResultArray results);

            if (result == SetComparisonResult.Subset ||
                result == SetComparisonResult.Equal)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #16
0
        private XYZ GetCentroid()
        {
            Line line1 = Line.CreateBound(Line.CreateBound(Point1, Point2).Evaluate(0.5, true),
                                          Line.CreateBound(Point3, Point4).Evaluate(0.5, true));
            Line line2 = Line.CreateBound(Line.CreateBound(Point1, Point3).Evaluate(0.5, true),
                                          Line.CreateBound(Point2, Point4).Evaluate(0.5, true));

            //CreateCurve(line1); CreateCurve(line2);
            IntersectionResultArray iresArray;
            SetComparisonResult     result = line1.Intersect(line2, out iresArray);
            IntersectionResult      ires   = iresArray.get_Item(0);

            return(ires.XYZPoint);
        }
コード例 #17
0
        /// <summary>
        /// Finds a point that
        /// </summary>
        /// <param name="points"></param>
        /// <param name="line1"></param>
        /// <param name="posibleCurves"></param>
        /// <returns></returns>
        private static CircularLinkedListNode <UV> FindNewNode(ref CircularLinkedList <UV> points, Line line, CurveArray posibleCurves, UV notch)
        {
            // iterate for each possible curve, and if
            // a intersection is found, the point will
            // be added in the linked list
            CircularLinkedListNode <UV> newNode = null;

            // get the closest point
            UV     newPoint = null, previousPoint = null;
            double minDistance = double.MaxValue;

            foreach (Curve curve in posibleCurves)
            {
                SetComparisonResult intersection = curve.Intersect(line, out IntersectionResultArray resultArray);
                if (intersection == SetComparisonResult.Overlap)
                {
                    IntersectionResultArrayIterator iterator = resultArray.ForwardIterator();
                    iterator.Reset();
                    while (iterator.MoveNext())
                    {
                        IntersectionResult result = iterator.Current as IntersectionResult;
                        UV     point    = VectorManipulator.ProjectInPlaneXY(result.XYZPoint);
                        double distance = point.DistanceTo(notch);
                        if (distance < minDistance)
                        {
                            minDistance   = distance;
                            newPoint      = point;
                            previousPoint = VectorManipulator.ProjectInPlaneXY(curve.GetEndPoint(0));
                        }
                    }
                }
            }

            // insert the new point in the list
            CircularLinkedListNode <UV> node = FindPoint(points, previousPoint);

            newNode = points.AddAfter(node, newPoint);
            if (newNode.Next.Value.IsAlmostEqualTo(newNode.Value))
            {
                points.Remove(newNode.Next.Value);
            }
            else if (newNode.Previous.Value.IsAlmostEqualTo(newNode.Value))
            {
                points.Remove(newNode.Previous.Value);
            }

            return(newNode);
        }
コード例 #18
0
        private static PlanarFace GetTopFace(Instance element, Solid solid)
        {
            XYZ  origin          = element.GetTransform().Origin;
            XYZ  originOffsetZ   = new XYZ(origin.X, origin.Y, (origin.Z + 50));
            Line originIntersect = Line.CreateBound(origin, originOffsetZ);

            foreach (PlanarFace f in solid.Faces.OfType <PlanarFace>())
            {
                SetComparisonResult result = f.Intersect(originIntersect, out var results);
                if (result == SetComparisonResult.Overlap)
                {
                    return(f);
                }
            }

            return(null);
        }
コード例 #19
0
        /// <summary>
        /// Check if two curves are strictly intersected
        /// </summary>
        /// <param name="crv1"></param>
        /// <param name="crv2"></param>
        /// <returns></returns>
        public static bool IsIntersected(Curve crv1, Curve crv2)
        {
            // Can be safely apply to lines
            // Line segment can only have 4 comparison results: Disjoint, subset, overlap, equal
            SetComparisonResult result = crv1.Intersect(crv2, out IntersectionResultArray results);

            if (result == SetComparisonResult.Overlap ||
                result == SetComparisonResult.Subset ||
                result == SetComparisonResult.Superset ||
                result == SetComparisonResult.Equal)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #20
0
        /// <summary>
        /// Extend the line to a boundary line. If the line has already surpassed it, trim the line instead.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="terminal"></param>
        /// <returns></returns>
        public static Curve ExtendLine(Curve line, Curve terminal)
        {
            Line line_unbound     = line.Clone() as Line;
            Line terminal_unbound = terminal.Clone() as Line;

            line_unbound.MakeUnbound();
            terminal_unbound.MakeUnbound();
            SetComparisonResult result = line_unbound.Intersect(terminal_unbound, out IntersectionResultArray results);

            if (result == SetComparisonResult.Overlap)
            {
                XYZ sectPt       = results.get_Item(0).XYZPoint;
                XYZ extensionVec = (sectPt - line.GetEndPoint(0)).Normalize();
                if (Algorithm.IsPtOnLine(sectPt, line as Line))
                {
                    double distance1 = sectPt.DistanceTo(line.GetEndPoint(0));
                    double distance2 = sectPt.DistanceTo(line.GetEndPoint(1));
                    if (distance1 > distance2)
                    {
                        return(Line.CreateBound(line.GetEndPoint(0), sectPt));
                    }
                    else
                    {
                        return(Line.CreateBound(line.GetEndPoint(1), sectPt));
                    }
                }
                else
                {
                    if (extensionVec.IsAlmostEqualTo(line_unbound.Direction))
                    {
                        return(Line.CreateBound(line.GetEndPoint(0), sectPt));
                    }
                    else
                    {
                        return(Line.CreateBound(sectPt, line.GetEndPoint(1)));
                    }
                }
            }
            else
            {
                Debug.Print("Cannot locate the intersection point.");
                return(null);
            }
        }
コード例 #21
0
        private Wall FindIntersectionWall(List <Wall> walls, Wall comparisonWall)
        {
            LocationCurve locationCurve = comparisonWall.Location as LocationCurve;
            Curve         wallCurve     = locationCurve.Curve as Line;

            foreach (Wall wall in walls)
            {
                LocationCurve lc = wall.Location as LocationCurve;
                Curve         c  = lc.Curve;

                SetComparisonResult intersection = wallCurve.Intersect(c, out IntersectionResultArray resultArray);
                if (intersection == SetComparisonResult.Equal || intersection == SetComparisonResult.Overlap ||
                    intersection == SetComparisonResult.Subset || intersection == SetComparisonResult.Superset)
                {
                    return(wall);
                }
            }
            return(null);
        }