public static List <InterpolatedPoint> interp(Point3d p, Point3d p1, Point3d p2, Point3d p3)
        {
            List <InterpolatedPoint> ps = new List <InterpolatedPoint>();

            p1 = new Point3d(p.X + (p1.X - p.X) / 4, p.Y + (p1.Y - p.Y) / 4, p.Z + (p1.Z - p.Z) / 4);

            p2 = new Point3d(p.X + (p2.X - p.X) / 4, p.Y + (p2.Y - p.Y) / 4, p.Z + (p2.Z - p.Z) / 4);

            p3 = new Point3d(p.X + (p3.X - p.X) / 4, p.Y + (p3.Y - p.Y) / 4, p.Z + (p3.Z - p.Z) / 4);

            //pl.Sort(new My.Point3dComparer());
            //Point3d p1 = pl[0], p2 = pl[1], p3 = pl[2];
            Autodesk.AutoCAD.Geometry.Plane    plane1  = new Autodesk.AutoCAD.Geometry.Plane(p1, p2, p3);
            Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal);

            Point3d prjP = p.TransformBy(prjMat1);

            Autodesk.AutoCAD.Geometry.Vector3d direction = new Autodesk.AutoCAD.Geometry.Vector3d(p.X - prjP.X, p.Y - prjP.Y, p.Z - prjP.Z);

            Point3d tp = p1.TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(direction * 1 / 3));

            ps.Add(new InterpolatedPoint(direction.Length, new Point(tp.X, tp.Y, tp.Z)));
            tp = p2.TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(direction * 1 / 3));
            ps.Add(new InterpolatedPoint(direction.Length, new Point(tp.X, tp.Y, tp.Z)));
            tp = p3.TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(direction * 1 / 3));
            ps.Add(new InterpolatedPoint(direction.Length, new Point(tp.X, tp.Y, tp.Z)));

            return(ps);
        }
Beispiel #2
0
        protected override List <PathInfo> GetSweptPath()
        {
            AcadGeo.Point3d       center  = CalculateCenter();
            AcadGeo.Vector3d      ref_vec = AcadFuncs.GetVec(CalculateBranchPos(position, main_branch_position, radius), center);
            AcadGeo.CircularArc3d arc     = new AcadGeo.CircularArc3d(
                center, NormalVec(), ref_vec, radius,
                GetStartAngle(position, center, ref_vec, NormalVec()), GetEndAngle(position, center, ref_vec, NormalVec()));

            //AcadFuncs.AddNewEnt(AcadDB.Arc.CreateFromGeCurve(arc));

            List <PathInfo> ents = new List <PathInfo>();

            AcadGeo.Point3d bp = CalculateBranchPos(position,
                                                    profile.NormalVector.GetNormal().IsParallelTo(ref_vec) ? branch_position : main_branch_position,
                                                    radius);

            profile.BasePoint = new AcadGeo.Point3d(bp.X, bp.Y, bp.Z);
            ents.Add(new PathInfo(profile.GetRegions().First(), profile.GetSubRegions().First(), AcadDB.Arc.CreateFromGeCurve(arc), bp));

            {
                AcadGeo.Plane         plane   = new AcadGeo.Plane(position, AcadFuncs.GetVec(position, branch_position));
                AcadGeo.CircularArc3d tmp_arc = new AcadGeo.CircularArc3d(
                    arc.Center, arc.Normal, arc.ReferenceVector, arc.Radius, arc.StartAngle, arc.EndAngle);
                tmp_arc.Mirror(plane);

                AcadGeo.Point3d tmp_bp = new AcadGeo.Point3d(bp.X, bp.Y, bp.Z);
                if (tmp_bp.IsEqualTo(CalculateBranchPos(position, branch_position, radius)))
                {
                    tmp_bp           += AcadFuncs.GetVec(position, branch_position) * radius * 2.0;
                    profile.BasePoint = tmp_bp;
                }
                //AcadFuncs.AddNewEnt(AcadDB.Arc.CreateFromGeCurve(tmp_arc));

                ents.Add(new PathInfo(profile.GetRegions().First(), profile.GetSubRegions().First(), AcadDB.Arc.CreateFromGeCurve(tmp_arc), tmp_bp));
            }

            {
                AcadGeo.Point3d tmp_pos     = CalculateBranchPos(position, branch_position, radius);
                AcadGeo.Point3d tmp_end_pos = tmp_pos + AcadFuncs.GetVec(position, branch_position) * radius * 2.0;

                AcadGeo.Point3d tmp_bp = new AcadGeo.Point3d(bp.X, bp.Y, bp.Z);
                if (tmp_bp.IsEqualTo(CalculateBranchPos(position, branch_position, radius)))
                {
                    profile.BasePoint = CalculateBranchPos(position, branch_position, radius);
                }
                else
                {
                    profile.BasePoint = new AcadGeo.Point3d(position.X, position.Y, position.Z);
                    profile.Rotate(AcadFuncs.GetVec(position, branch_position));
                    profile.BasePoint = CalculateBranchPos(position, branch_position, radius);
                }

                ents.Add(new PathInfo(profile.GetRegions().First(), profile.GetSubRegions().First(), new AcadDB.Line(tmp_pos, tmp_end_pos), tmp_bp));
            }


            return(ents);
        }
Beispiel #3
0
        private AcadGeo.Point3d CalculateCenter()
        {
            AcadGeo.Vector3d vec = AcadFuncs.GetVec(
                CalculateBranchPos(position, main_branch_position, radius),
                CalculateBranchPos(position, branch_position, radius));
            AcadGeo.Point3d pos   = position + AcadFuncs.GetVec(main_branch_position, position) * radius;
            AcadGeo.Plane   plane = new AcadGeo.Plane(pos, NormalVec().CrossProduct(vec));

            return(position.Mirror(plane));
        }
Beispiel #4
0
        public static PointSet __interp(Point3d p, List <LineSegment3d> ll)
        {
            if (ll.Count < 3)
            {
                return(null);
            }
            PointSet       ps = new PointSet();
            List <Point3d> pl = new List <Point3d>();
            Point3d        ortherP;

            for (int i = 0; i < ll.Count; i++)
            {
                if (p == ll[0].EndPoint)
                {
                    ortherP = ll[0].StartPoint;
                }
                else
                {
                    ortherP = ll[i].EndPoint;
                }
                Point3d tp = new Point3d(p.X + (ortherP.X - p.X) / 3, p.Y + (ortherP.Y - p.Y) / 3, p.Z + (ortherP.Z - p.Z) / 3);
                pl.Add(tp);
            }
            Point3d p1 = pl[0], p2 = pl[1], p3 = pl[2];

            Autodesk.AutoCAD.Geometry.Plane    plane1  = new Autodesk.AutoCAD.Geometry.Plane(p1, p2, p3);
            Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal);


            Point3d prjP = p.TransformBy(prjMat1);

            Autodesk.AutoCAD.Geometry.Vector3d direction = new Autodesk.AutoCAD.Geometry.Vector3d(p.X - prjP.X, p.Y - prjP.Y, p.Z - prjP.Z);
            for (int i = 0; i < pl.Count; i++)
            {
                //double d = p.DistanceTo(prjP);
                ;
                Point3d tp = pl[i].TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(direction * 2 / 3));
                ps.Add(new Point(tp.X, tp.Y, tp.Z));
            }

            return(ps);
        }
Beispiel #5
0
        public AcadDB.Polyline PolycurveToNativeDB(Polycurve polycurve) //polylines can only support curve segments of type circular arc
        {
            AcadDB.Polyline polyline = new AcadDB.Polyline()
            {
                Closed = polycurve.closed
            };
            var plane = new Autodesk.AutoCAD.Geometry.Plane(Point3d.Origin, Vector3d.ZAxis.TransformBy(Doc.Editor.CurrentUserCoordinateSystem)); // TODO: check this

            // add all vertices
            for (int i = 0; i < polycurve.segments.Count; i++)
            {
                var segment = polycurve.segments[i];
                switch (segment)
                {
                case Line o:
                    polyline.AddVertexAt(i, PointToNative(o.start).Convert2d(plane), 0, 0, 0);
                    if (!polycurve.closed && i == polycurve.segments.Count - 1)
                    {
                        polyline.AddVertexAt(i + 1, PointToNative(o.end).Convert2d(plane), 0, 0, 0);
                    }
                    break;

                case Arc o:
                    var bulge = Math.Tan((double)(o.endAngle - o.startAngle) / 4); // bulge
                    polyline.AddVertexAt(i, PointToNative(o.startPoint).Convert2d(plane), bulge, 0, 0);
                    if (!polycurve.closed && i == polycurve.segments.Count - 1)
                    {
                        polyline.AddVertexAt(i + 1, PointToNative(o.endPoint).Convert2d(plane), 0, 0, 0);
                    }
                    break;

                default:
                    throw new Speckle.Core.Logging.SpeckleException("Polycurve segment is not a line or arc!");
                }
            }

            return(polyline);
        }
Beispiel #6
0
        internal static ProjectClass getMovement(Point3d p, Point3d p1, Point3d p2, Point3d p3)
        {
            List <InterpolatedPoint> ps = new List <InterpolatedPoint>();

            //p1 = new Point3d(p.X + (p1.X - p.X) / 4, p.Y + (p1.Y - p.Y) / 4, p.Z + (p1.Z - p.Z) / 4);

            //p2 = new Point3d(p.X + (p2.X - p.X) / 4, p.Y + (p2.Y - p.Y) / 4, p.Z + (p2.Z - p.Z) / 4);

            //p3= new Point3d(p.X + (p3.X - p.X) /4, p.Y + (p3.Y - p.Y) / 4, p.Z + (p3.Z - p.Z) / 4);

            //pl.Sort(new My.Point3dComparer());
            //Point3d p1 = pl[0], p2 = pl[1], p3 = pl[2];
            Autodesk.AutoCAD.Geometry.Plane    plane1  = new Autodesk.AutoCAD.Geometry.Plane(p1, p2, p3);
            Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal);

            Point3d prjP = p.TransformBy(prjMat1);

            Autodesk.AutoCAD.Geometry.Vector3d direction = new Autodesk.AutoCAD.Geometry.Vector3d(p.X - prjP.X, p.Y - prjP.Y, p.Z - prjP.Z);
            List <Point3d> pl = new List <Point3d>();

            pl.Add(p1); pl.Add(p2); pl.Add(p3);
            return(new ProjectClass(plane1, prjMat1, direction, pl));
        }
Beispiel #7
0
 internal ProjectClass(Autodesk.AutoCAD.Geometry.Plane p, Autodesk.AutoCAD.Geometry.Matrix3d m, Autodesk.AutoCAD.Geometry.Vector3d d, List <Point3d> pl)
 {
     plane = p; prjMat = m; direction = d; points = pl;
 }