Esempio n. 1
0
        private Arc AlignmentArcToSpeckle(CivilDB.AlignmentSubEntityArc arc)
        {
            // calculate midpoint of chord as between start and end point
            Point2d chordMid = new Point2d((arc.StartPoint.X + arc.EndPoint.X) / 2, (arc.StartPoint.Y + arc.EndPoint.Y) / 2);

            // calculate sagitta as radius minus distance between arc center and chord midpoint
            var sagitta = arc.Radius - arc.CenterPoint.GetDistanceTo(chordMid);

            // get unit vector from arc center to chord mid
            var midVector     = arc.CenterPoint.GetVectorTo(chordMid);
            var unitMidVector = midVector.DivideBy(midVector.Length);

            // get midpoint of arc by moving chord mid point the length of the sagitta along mid vector
            var midPoint = chordMid.Add(unitMidVector.MultiplyBy(sagitta));

            // find arc plane (normal is in clockwise dir)
            var center3 = new Point3d(arc.CenterPoint.X, arc.CenterPoint.Y, 0);

            Acad.Plane plane = (arc.Clockwise) ? new Acad.Plane(center3, Vector3d.ZAxis.MultiplyBy(-1)) : new Acad.Plane(center3, Vector3d.ZAxis);

            // calculate start and end angles
            var startVector = new Vector3d(arc.StartPoint.X - center3.X, arc.StartPoint.Y - center3.Y, 0);
            var endVector   = new Vector3d(arc.EndPoint.X - center3.X, arc.EndPoint.Y - center3.Y, 0);
            var startAngle  = startVector.AngleOnPlane(plane);
            var endAngle    = endVector.AngleOnPlane(plane);

            // calculate total angle.
            // TODO: This needs to be improved with more research into autocad .AngleOnPlane() return values (negative angles, etc).
            var totalAngle = (arc.Clockwise) ? System.Math.Abs(endAngle - startAngle) : System.Math.Abs(endAngle - startAngle);

            // create arc
            var _arc = new Arc(PlaneToSpeckle(plane), arc.Radius, startAngle, endAngle, totalAngle, ModelUnits);

            _arc.startPoint = PointToSpeckle(arc.StartPoint);
            _arc.endPoint   = PointToSpeckle(arc.EndPoint);
            _arc.midPoint   = PointToSpeckle(midPoint);
            _arc.domain     = IntervalToSpeckle(new Acad.Interval(0, 1, tolerance));
            _arc.length     = arc.Length;

            return(_arc);
        }
 internal AlignmentArc(C3dDb.AlignmentSubEntityArc subEntityArc) : base(subEntityArc)
 {
     _pIPoint = PointData.FromPointObject
                    (ReflectionSupport.GetProperty(subEntityArc, "PIPoint", null));
 }