Ejemplo n.º 1
0
        public static ExtendType ParamToExtendTypeForArc(CircularArc3d arc, double param, ExtendType?coerceExtendType)
        {
            var startParam = arc.GetParameterOf(arc.StartPoint);
            var endParam   = arc.GetParameterOf(arc.EndPoint);

            var result = ExtendType.None;
            // If param is in the middle of startParam and endParam
            var val = (param - startParam) * (param - endParam);

            if (val.SmallerOrEqual(0.0))
            {
                result = ExtendType.None;
            }
            else
            {
                // If coerce extend type is not null.
                if (coerceExtendType != null)
                {
                    result = coerceExtendType.Value;
                }
                else
                {
                    // Determine which distance is shorter.
                    if (Math.Abs(param - startParam) >= Math.Abs(param - endParam))
                    {
                        result = ExtendType.ExtendEnd;
                    }
                    else
                    {
                        result = ExtendType.ExtendStart;
                    }
                }
            }
            return(result);
        }
        // Arc
        public Arc ArcToSpeckle(CircularArc3d arc)
        {
            var _arc = new Arc(PlaneToSpeckle(arc.GetPlane()), arc.Radius, arc.StartAngle, arc.EndAngle, Math.Abs(arc.EndAngle - arc.StartAngle), ModelUnits);

            _arc.startPoint = PointToSpeckle(arc.StartPoint);
            _arc.endPoint   = PointToSpeckle(arc.EndPoint);
            _arc.domain     = IntervalToSpeckle(arc.GetInterval());
            _arc.length     = arc.GetLength(arc.GetParameterOf(arc.StartPoint), arc.GetParameterOf(arc.EndPoint), tolerance);
            _arc.bbox       = BoxToSpeckle(arc.OrthoBoundBlock);
            return(_arc);
        }
Ejemplo n.º 3
0
        public static Arc CreateArcFromRadius(this Editor acCurEd, Point3d startPoint, Point3d endPoint, double radius)
        {
            Arc arc     = null;
            var ucsMat  = acCurEd.CurrentUserCoordinateSystem;
            var vNormal = ucsMat.CoordinateSystem3d.Zaxis;
            var pStart  = startPoint.TransformBy(ucsMat); // Start point in WCS
            var pEnd    = endPoint.TransformBy(ucsMat);   // End point in WCS
            //  Finding center point of arc.
            var circ1 = new CircularArc3d(pStart, vNormal, radius);
            var circ2 = new CircularArc3d(pEnd, vNormal, radius);
            var pts   = circ1.IntersectWith(circ2);

            circ1.Dispose();
            circ2.Dispose();

            try
            {
                if (pts.Length < 1)
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }

            var      pCenter = pts[0];
            Vector3d v1 = pStart - pCenter, v2 = pEnd - pCenter;

            if (v1.CrossProduct(v2).DotProduct(vNormal) < 0)
            {
                pCenter = pts[1];
            }
            var cCirc    = new CircularArc3d(pCenter, vNormal, radius);
            var parStart = cCirc.GetParameterOf(pStart);
            var parEnd   = cCirc.GetParameterOf(pEnd);
            var parMid   = (parStart + parEnd) * 0.5;
            var pMid     = cCirc.EvaluatePoint(parMid);

            cCirc.Dispose();
            var cArc  = new CircularArc3d(pStart, pMid, pEnd);
            var angle =
                cArc.ReferenceVector.AngleOnPlane(new Plane(cArc.Center, cArc.Normal));

            arc = new Arc(cArc.Center, cArc.Normal, cArc.Radius, cArc.StartAngle + angle, cArc.EndAngle + angle);
            cArc.Dispose();
            return(arc);
        }
Ejemplo n.º 4
0
        public static IEnumerable <IntersectionInfo> IntersectArcs(Arc source, ExtendType?coerceSourceExtendType, Arc target, ExtendType?coerceTargetExtendType)
        {
            var points = new Point3dCollection();

            source.IntersectWith(target, Intersect.ExtendBoth, points, IntPtr.Zero, IntPtr.Zero);
            if (points.Count <= 0)
            {
                return(new IntersectionInfo[0]);
            }

            // NOTE: Use Arc's GetParameterAtPoint will throw exception if the intersect point is
            // on the Arc's extension, but CircularArc3d.GetParameterOf is available, so I convert
            // the Arc to CircularArc3d here.
            var sourceArc = new CircularArc3d(source.Center, source.Normal, source.Normal.GetPerpendicularVector(),
                                              source.Radius, source.StartAngle, source.EndAngle);
            var targetArc = new CircularArc3d(target.Center, target.Normal, target.Normal.GetPerpendicularVector(),
                                              target.Radius, target.StartAngle, target.EndAngle);

            var result = new List <IntersectionInfo>();

            foreach (Point3d point in points)
            {
                var sourceParam      = sourceArc.GetParameterOf(point);
                var sourceExtendType = ParamToExtendTypeForArc(sourceArc, sourceParam, coerceSourceExtendType);
                var targetParam      = targetArc.GetParameterOf(point);
                var targetExtendType = ParamToExtendTypeForArc(targetArc, targetParam, coerceTargetExtendType);
            }
            return(result);
        }
Ejemplo n.º 5
0
        public static IEnumerable <IntersectionInfo> IntersectLineArc(Line line, Arc arc, ExtendType?coerceArcExtendType)
        {
            var points = new Point3dCollection();

            line.IntersectWith(arc, Intersect.ExtendBoth, points, IntPtr.Zero, IntPtr.Zero);
            if (points.Count <= 0)
            {
                return(new IntersectionInfo[0]);
            }

            // NOTE: Use Line's GetParameterAtPoint will throw exception if the intersect point is
            // on the line's extension, but LineSegment3d.GetParameterOf is available, so I convert
            // the Line to LineSegment3d here.
            var lineSegment = new LineSegment3d(line.StartPoint, line.EndPoint);
            var circularArc = new CircularArc3d(arc.Center, arc.Normal, arc.Normal.GetPerpendicularVector(), arc.Radius,
                                                arc.StartAngle, arc.EndAngle);

            var result = new List <IntersectionInfo>();

            foreach (Point3d point in points)
            {
                var lineParam      = lineSegment.GetParameterOf(point);
                var lineExtendType = ParamToExtendTypeForLine(lineParam);

                var arcParam      = circularArc.GetParameterOf(point);
                var arcExtendType = ParamToExtendTypeForArc(circularArc, arcParam, coerceArcExtendType);
                result.Add(new IntersectionInfo(lineExtendType, arcExtendType, point));
            }

            return(result);
        }
Ejemplo n.º 6
0
        Coordinate[] GetTessellatedCurveCoordinates(CircularArc3d curve)
        {
            var coordinateList = new CoordinateList();

            if (curve.StartPoint != curve.EndPoint)
            {
                switch (this.CurveTessellationMethod)
                {
                case CurveTessellation.None:
                    coordinateList.Add(this.ReadCoordinate(curve.StartPoint));
                    coordinateList.Add(this.ReadCoordinate(curve.EndPoint));
                    break;

                case CurveTessellation.Linear:
                {
                    var samplePoints = curve.GetSamplePoints((int)Math.Round(this.CurveTessellationValue));
                    for (int i = 0; i < samplePoints.Length; i++)
                    {
                        Point3d point3D = samplePoints[i].Point;
                        coordinateList.Add(this.ReadCoordinate(point3D));
                    }
                    break;
                }

                case CurveTessellation.Scaled:
                {
                    double num  = curve.GetArea(curve.GetParameterOf(curve.StartPoint), curve.GetParameterOf(curve.EndPoint)) * this.CurveTessellationValue;
                    double num2 = Math.Acos((curve.Radius - 1.0 / (num / 2.0)) / curve.Radius);
                    int    num3 = (int)Math.Round(6.2831853071795862 / num2);
                    if (num3 < 8)
                    {
                        num3 = 8;
                    }
                    if (num3 > 128)
                    {
                        num3 = 128;
                    }

                    var samplePoints2 = curve.GetSamplePoints(num3);
                    for (int j = 0; j < samplePoints2.Length; j++)
                    {
                        var point3d2 = samplePoints2[j].Point;
                        coordinateList.Add(this.ReadCoordinate(point3d2));
                    }
                    break;
                }
                }
            }
            return(coordinateList.ToCoordinateArray());
        }
Ejemplo n.º 7
0
        private IntersectionInfo IntersectArcAndCurve(Arc arc, Curve curve, Point3d point, ExtendType?coerceArcExtendType)
        {
            var points = new Point3dCollection();

            arc.IntersectWith(curve, Intersect.ExtendThis, points, IntPtr.Zero, IntPtr.Zero);
            if (points.Count <= 0)
            {
                return(null);
            }

            // Get the nearest point
            var nearsetPoint = points[0];
            var dist         = (point - nearsetPoint).LengthSqrd;

            for (int i = 1; i < points.Count; i++)
            {
                var newDist = (points[i] - point).LengthSqrd;
                if (newDist < dist)
                {
                    nearsetPoint = points[i];
                    dist         = newDist;
                }
            }

            // Calculate extend type
            if (coerceArcExtendType == null)
            {
                var circularArc = new CircularArc3d(arc.Center, arc.Normal, arc.Normal.GetPerpendicularVector(), arc.Radius,
                                                    arc.StartAngle, arc.EndAngle);
                var arcParam = circularArc.GetParameterOf(nearsetPoint);
                coerceArcExtendType = CurveIntersectUtils.ParamToExtendTypeForArc(circularArc, arcParam, null);
            }

            var result = new IntersectionInfo(coerceArcExtendType.Value, ExtendType.None, nearsetPoint);

            return(result);
        }
Ejemplo n.º 8
0
        void HatchPerimeter(ObjectId entId)
        {
            Document activeDoc = Application.DocumentManager.MdiActiveDocument;

            Database db = activeDoc.Database;

            Editor ed = activeDoc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Hatch hatch = tr.GetObject(entId, OpenMode.ForRead) as Hatch;

                int    nLoops = hatch.NumberOfLoops;
                double totalExternalPerimeter = 0.0;
                double totalInternalPerimeter = 0.0;

                for (int i = 0; i < nLoops; i++)
                {
                    double loopLength = 0.0;

                    HatchLoopTypes hlt = hatch.LoopTypeAt(i);

                    HatchLoop hatchLoop = hatch.GetLoopAt(i);

                    if ((hatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) == HatchLoopTypes.Polyline)
                    {
                        BulgeVertexCollection bulges = hatchLoop.Polyline;
                        int nVertices = bulges.Count;

                        Polyline testPoly = new Polyline(nVertices);

                        for (int vx = 0; vx < bulges.Count; vx++)
                        {
                            BulgeVertex bv = bulges[vx];

                            testPoly.AddVertexAt(vx, bv.Vertex, bv.Bulge, 1.0, 1.0);
                        }

                        LineSegment3d ls = new LineSegment3d();

                        CircularArc3d cs = new CircularArc3d();

                        double d = 0.0, p1 = 0.0, p2 = 1.0;

                        for (int ver = 0; ver < nVertices - 1; ver++)
                        {
                            d = testPoly.GetBulgeAt(ver);

                            if (d <= 1e-5)
                            {
                                ls = testPoly.GetLineSegmentAt(ver);

                                loopLength += ls.Length;
                            }

                            else
                            {
                                Point2d v1 = new Point2d(bulges[ver].Vertex.X, bulges[ver].Vertex.Y);

                                Point2d v2 = new Point2d(bulges[ver + 1].Vertex.X, bulges[ver + 1].Vertex.Y);

                                if (v1.IsEqualTo(v2) == false)
                                {
                                    cs = testPoly.GetArcSegmentAt(ver);

                                    p1 = cs.GetParameterOf(cs.StartPoint);

                                    p2 = cs.GetParameterOf(cs.EndPoint);

                                    loopLength += cs.GetLength
                                                      (p1, p2, Tolerance.Global.EqualPoint);
                                }
                            }
                        }
                    }

                    else
                    {
                        Curve2dCollection curves = hatchLoop.Curves;

                        if (curves != null)
                        {
                            foreach (Curve2d curve in curves)
                            {
                                if (hatchLoop.LoopType == HatchLoopTypes.External)
                                {
                                    totalExternalPerimeter += curve.GetLength(0.0, 1.0);
                                }

                                else
                                {
                                    totalInternalPerimeter += curve.GetLength(0.0, 1.0);
                                }
                            }
                        }
                    }

                    if (nLoops > 1 &&

                        ((hlt & HatchLoopTypes.External) != HatchLoopTypes.External))
                    {
                        totalInternalPerimeter += loopLength;
                    }
                    else
                    {
                        totalExternalPerimeter += loopLength;
                    }
                }
                ed.WriteMessage(string.Format("\nExternal Perimeter : {0}", totalExternalPerimeter));

                ed.WriteMessage(string.Format("\nInternal Perimeter : {0}", totalInternalPerimeter));

                tr.Commit();
            }
        }