Esempio n. 1
0
        public static MText GetMText(Polyline pol, Point3d p1, bool t)
        {
            Vector3d ang = pol.GetFirstDerivative(pol.GetParameterAtPoint(p1));

            //scale the vector by 1.5
            ang = ang.GetNormal() * 1.5;
            //rotate the vector
            ang = ang.TransformBy(Matrix3d.Rotation(Math.PI / 2, pol.Normal, Point3d.Origin));
            // create a line by substracting and adding the vector to the point (displacing the point

            MText dBText = new MText();


            dBText.BackgroundFill        = true;
            dBText.BackgroundScaleFactor = 1.25;
            if (t)
            {
                if (ang.AngleOnPlane(pol.GetPlane()) > Math.PI)
                {
                    dBText.Attachment = AttachmentPoint.BottomCenter;
                }
                else
                {
                    dBText.Attachment = AttachmentPoint.TopCenter;
                }

                dBText.Location = p1 - (ang.GetNormal() * 2);
            }
            else
            {
                if (ang.AngleOnPlane(pol.GetPlane()) > Math.PI)
                {
                    dBText.Attachment = AttachmentPoint.TopCenter;
                }
                else
                {
                    dBText.Attachment = AttachmentPoint.BottomCenter;
                }

                dBText.Location = p1 + (ang.GetNormal() * 2);
            }


            if (ang.AngleOnPlane(pol.GetPlane()) > (Math.PI / 2) && (ang.AngleOnPlane(pol.GetPlane()) <= Math.PI))
            {
                dBText.Rotation = ang.AngleOnPlane(pol.GetPlane()) - (Math.PI / 2);
            }
            else if (ang.AngleOnPlane(pol.GetPlane()) > Math.PI)
            {
                dBText.Rotation = ang.AngleOnPlane(pol.GetPlane()) + (Math.PI / 2);
            }
            else
            {
                dBText.Rotation = (2 * Math.PI) - Math.Abs(ang.AngleOnPlane(pol.GetPlane()) - (Math.PI / 2));
            }

            return(dBText);
        }
Esempio n. 2
0
        /// <summary>Создание дуг</summary>
        private void CreateArcs(XElement root, Transaction tr, BlockTableRecord btr)
        {
            foreach (XElement curveXelement in root.Elements("Arc"))
            {
                XElement startPointXElement = curveXelement.Element("StartPoint");
                Point3d  startPoint         = startPointXElement.GetAsPoint();
                XElement endPointXElement   = curveXelement.Element("EndPoint");
                Point3d  endPoint           = endPointXElement.GetAsPoint();
                XElement pointOnArcXElement = curveXelement.Element("PointOnArc");
                Point3d  pointOnArc         = pointOnArcXElement.GetAsPoint();
                // create a CircularArc3d
                CircularArc3d carc = new CircularArc3d(startPoint, pointOnArc, endPoint);

                // now convert the CircularArc3d to an Arc
                Point3d  cpt    = carc.Center;
                Vector3d normal = carc.Normal;
                Vector3d refVec = carc.ReferenceVector;
                Plane    plan   = new Plane(cpt, normal);
                double   ang    = refVec.AngleOnPlane(plan);
                using (Arc arc = new Arc(cpt, normal, carc.Radius, carc.StartAngle + ang, carc.EndAngle + ang))
                {
                    btr.AppendEntity(arc);
                    tr.AddNewlyCreatedDBObject(arc, true);
                }
                // dispose CircularArc3d
                carc.Dispose();
            }
        }
        private static Arc CreateFromCircularArc(CircularArc3d circArc)
        {
            Point3d  center          = circArc.Center;
            Vector3d normal          = circArc.Normal;
            Vector3d referenceVector = circArc.ReferenceVector;
            Plane    plane           = new Plane(center, normal);
            double   num             = referenceVector.AngleOnPlane(plane);

            return(new Arc(center, normal, circArc.Radius, circArc.StartAngle + num, circArc.EndAngle + num));
        }
Esempio n. 4
0
        Matrix3d BendMatrix(Point3d origin, Point3d fromp, Point3d to)
        {
            Vector3d oldx = fromp.GetAsVector().Subtract(origin.GetAsVector());
            Vector3d newx = to.GetAsVector().Subtract(origin.GetAsVector());

            Plane xoy = new Plane(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis);

            double angle = newx.AngleOnPlane(xoy) - oldx.AngleOnPlane(xoy);

            return(Matrix3d.Rotation(angle, Vector3d.ZAxis, origin));
        }
Esempio n. 5
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);
        }