예제 #1
0
        protected override List <PathInfo> GetSweptPath()
        {
            AcadGeo.Point3d       center  = CalculateCenter();
            AcadGeo.Vector3d      ref_vec = AcadFuncs.GetVec(CalculateBranchPos(position, branch_positions[0], radius, angle), 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(AcadFuncs.GetVec(position, branch_positions[1])) ? branch_positions[1] : branch_positions[0],
                                                    radius, angle);

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

            //{
            //	var regs = profile.GetRegions();
            //	AcadFuncs.AddNewEnt(regs[0]);
            //}

            return(ents);
        }
예제 #2
0
        private AcadGeo.Vector3d NormalVec()
        {
            AcadGeo.Vector3d v1 = AcadFuncs.GetVec(position, main_branch_position);

            AcadGeo.Vector3d v2 = AcadFuncs.GetVec(branch_position, position);

            return(v1.CrossProduct(v2).GetNormal());
        }
예제 #3
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);
        }
예제 #4
0
        public void Draw()
        {
            List <PathInfo> swept_paths = GetSweptPath();

            AcadDB.SweepOptionsBuilder swept_options = new AcadDB.SweepOptionsBuilder();
            swept_options.Align = AcadDB.SweepOptionsAlignOption.NoAlignment;

            using (AcadDB.Transaction tr = AcadFuncs.GetActiveDB().TransactionManager.StartTransaction())
            {
                AcadDB.Solid3d union_sol3d     = null;
                AcadDB.Solid3d union_sub_sol3d = null;
                foreach (var pi in swept_paths)
                {
                    if (null != pi.sub_region)
                    {
                        AcadDB.Solid3d solid = new AcadDB.Solid3d();
                        swept_options.BasePoint = pi.start_position;
                        solid.CreateSweptSolid(pi.sub_region, pi.path, swept_options.ToSweepOptions());
                        if (null == union_sub_sol3d)
                        {
                            union_sub_sol3d = solid;
                        }
                        else
                        {
                            union_sub_sol3d.BooleanOperation(AcadDB.BooleanOperationType.BoolUnite, solid);
                        }
                    }

                    if (null != pi.region)
                    {
                        AcadDB.Solid3d solid = new AcadDB.Solid3d();
                        swept_options.BasePoint = pi.start_position;
                        solid.CreateSweptSolid(pi.region, pi.path, swept_options.ToSweepOptions());
                        if (null == union_sol3d)
                        {
                            union_sol3d = solid;
                        }
                        else
                        {
                            union_sol3d.BooleanOperation(AcadDB.BooleanOperationType.BoolUnite, solid);
                        }
                    }
                }

                union_sol3d.BooleanOperation(AcadDB.BooleanOperationType.BoolSubtract, union_sub_sol3d);

                if (!(this is Straight))
                {
                    union_sol3d.ColorIndex = 1;
                }

                AcadFuncs.AddNewEnt(union_sol3d);

                tr.Commit();
            }
        }
예제 #5
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));
        }
예제 #6
0
        public void CalculateAngle()
        {
            AcadGeo.Vector3d vec1 = AcadFuncs.GetVec(branch_positions[0], position);
            AcadGeo.Vector3d vec2 = AcadFuncs.GetVec(branch_positions[1], position);

            if (vec1.IsParallelTo(vec2))
            {
                throw new Exception("Failed parse elbow");
            }
            angle = vec1.GetAngleTo(vec2);
        }
예제 #7
0
        private AcadGeo.Point3d CalculateCenter()
        {
            //AcadGeo.Vector3d vec = AcadFuncs.GetVec(
            //	CalculateBranchPos(position, branch_positions[0], radius, angle),
            //	CalculateBranchPos(position, branch_positions[1], radius, angle));
            //AcadGeo.Point3d pos = position + AcadFuncs.GetVec(branch_positions[0], position) * (radius / Math.Sin(angle * 0.5));
            //AcadGeo.Plane plane = new AcadGeo.Plane(pos, NormalVec().CrossProduct(vec));

            //return position.Mirror(plane);
            AcadGeo.Vector3d vec1    = AcadFuncs.GetVec(branch_positions[0], position);
            AcadGeo.Vector3d vec2    = AcadFuncs.GetVec(branch_positions[1], position);
            AcadGeo.Vector3d tmp_vec = new AcadGeo.Vector3d(
                vec1.X + vec2.X, vec1.Y + vec2.Y, vec1.Z + vec2.Z);
            tmp_vec = tmp_vec.GetNormal();
            return(position + tmp_vec * (radius / Math.Sin(angle * 0.5)));
        }
예제 #8
0
        private double GetEndAngle(AcadGeo.Point3d pos, AcadGeo.Point3d center, AcadGeo.Vector3d ref_vec, AcadGeo.Vector3d up_vec)
        {
            AcadGeo.Vector3d vec = AcadFuncs.GetVec(CalculateBranchPos(pos, branch_position, radius), center);

            return(ref_vec.GetAngleTo(vec, up_vec));
        }
예제 #9
0
 private static AcadGeo.Point3d CalculateBranchPos(AcadGeo.Point3d pos, AcadGeo.Point3d tmp_bp, double radius)
 {
     return(pos + AcadFuncs.GetVec(tmp_bp, pos) * radius);
 }
예제 #10
0
        private static AcadGeo.Point3d CalculateBranchPos(AcadGeo.Point3d pos, AcadGeo.Point3d tmp_bp, double radius, double angle)
        {
            double len = radius / Math.Tan(angle * 0.5);

            return(pos + AcadFuncs.GetVec(tmp_bp, pos) * len);
        }