Ejemplo n.º 1
0
        /// <summary>
        /// ремешок с перфорацие
        /// </summary>
        /// <param name="WatchData">информация о часах</param>
        /// <returns>Модель часов</returns>
        public Solid3d BuildStrapWithPerforations(WatchData WatchData)
        {
            //модель ремешка с перфор.
            Solid3d StrapWithPerforations = new Solid3d();

            StrapWithPerforations.CreateBox(Length / 2, Width, 3);

            //сглаживаем углы.
            Solid3d StrapSmoother = new Solid3d();

            StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]);
            StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(Length / 4, 0, 0)));
            StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d);

            StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]);
            StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(-Length / 4, 0, 0)));
            StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d);

            //проделываем перфорации
            Solid3d HoleMaker = new Solid3d();

            for (int i = 0; i < NumberOfPerforations; i++)
            {
                HoleMaker.CreateFrustum(3, PerforationRadius, PerforationRadius, PerforationRadius);
                HoleMaker.TransformBy(Matrix3d.Displacement(new Vector3d((Length / 4 - 10) - (Length / 3) / NumberOfPerforations * i, 0, 0)));
                StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolSubtract, HoleMaker.Clone() as Solid3d);
            }

            StrapWithPerforations.TransformBy(Matrix3d.Displacement(new Vector3d(WatchData.BodyDiameter + WatchData.BootstrapLength + (Length / 4) - 0.5, 0, 0)));


            return(StrapWithPerforations);
        }
Ejemplo n.º 2
0
        public static void FindInterferenceBetweenSolids()
        {
            // 获取当前文档和数据库,启动事务
            var acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var acCurDb = acDoc.Database;

            using (var acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 以读模式打开块表
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // 以写模式打开块表记录模型空间
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                // 创建3D箱体
                var acSol3DBox = new Solid3d();
                acSol3DBox.CreateBox(5, 7, 10);
                acSol3DBox.ColorIndex = 7;

                // 3D实体的中心点放在(5,5,0)
                acSol3DBox.TransformBy(Matrix3d.Displacement(new Point3d(5, 5, 0) -
                                                             Point3d.Origin));

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acSol3DBox);
                acTrans.AddNewlyCreatedDBObject(acSol3DBox, true);

                // 创建3D圆柱体
                // 默认构造函数的中心点为(0,0,0)
                var acSol3DCyl = new Solid3d();
                acSol3DCyl.CreateFrustum(20, 5, 5, 5);
                acSol3DCyl.ColorIndex = 4;

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acSol3DCyl);
                acTrans.AddNewlyCreatedDBObject(acSol3DCyl, true);

                // 用箱体和圆柱体的干涉创建一个3D实体
                var acSol3DCopy = acSol3DCyl.Clone() as Solid3d;

                // 检查箱体和圆柱体是否有重叠部分
                if (acSol3DCopy.CheckInterference(acSol3DBox))
                {
                    acSol3DCopy.BooleanOperation(BooleanOperationType.BoolIntersect,
                                                 acSol3DBox.Clone() as Solid3d);
                    acSol3DCopy.ColorIndex = 1;
                }

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acSol3DCopy);
                acTrans.AddNewlyCreatedDBObject(acSol3DCopy, true);

                // 提交事务
                acTrans.Commit();
            }
        }
Ejemplo n.º 3
0
        private bool CanSlice(Solid3d acSol, Surface acSurf)
        {
            var canSlice = false;

            using (var testSol = acSol.Clone() as Solid3d)
            {
                using (var testSurf = acSurf.Clone() as Surface)
                {
                    if (testSol != null && testSurf != null)
                    {
                        using (var thSol = testSurf.Thicken(-.01, false))
                        {
                            if (testSol.CheckInterference(thSol))
                            {
                                canSlice = true;
                            }

                            thSol.Dispose();
                        }

                        testSurf.Dispose();
                        testSol.Dispose();
                    }
                }
            }

            return(canSlice);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ремешок с замком
        /// </summary>
        /// <param name="WatchData">информация о часах</param>
        /// <returns>модель ремешка</returns>
        public Solid3d BuildStrapWithLocker(WatchData WatchData)
        {
            //модель ремешка с замком
            Solid3d StrapWithLocker = new Solid3d();

            StrapWithLocker.CreateBox(Length / _params[ParNames.StrapTransformByX], Width, 3);

            //сглаживания ремешка
            Solid3d StrapSmoother = new Solid3d();

            StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]);
            StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.StrapTransformByX], new Vector3d(1, 0, 0), Point3d.Origin));
            StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(Length / 4, 0, 0)));
            StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d);

            StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByX], _params[ParNames.StrapTransformByY]);
            StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.StrapTransformByX], new Vector3d(1, 0, 0), Point3d.Origin));
            StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(-Length / 4, 0, 0)));
            StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d);

            //замок ремешка
            Solid3d Locker = new Solid3d();

            Locker.CreateBox(20, Width + _params[ParNames.StrapTransformByX], 4);
            Solid3d LockerHole = new Solid3d();

            LockerHole.CreateBox(18, Width, 4);
            LockerHole.TransformBy(Matrix3d.Displacement(new Vector3d(4, 0, 0)));
            Locker.BooleanOperation(BooleanOperationType.BoolSubtract, LockerHole.Clone() as Solid3d);

            //Дерджатель на замке
            Solid3d LockerPin = new Solid3d();

            LockerPin.CreateBox(20, WatchData.StrapPerforationRadius, _params[ParNames.StrapTransformByX]);
            Locker.BooleanOperation(BooleanOperationType.BoolUnite, LockerPin.Clone() as Solid3d);

            //передвигаем ремешок
            Locker.TransformBy(Matrix3d.Displacement(new Vector3d((-Length / 4) - 5, 0, 0)));
            StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, Locker.Clone() as Solid3d);
            StrapWithLocker.TransformBy(Matrix3d.Displacement(new Vector3d(-(WatchData.BodyDiameter + WatchData.BootstrapLength + (Length / 4) - 0.5), 0, 0)));

            //возвращаем модель ремешка

            return(StrapWithLocker);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Построить 3д солид-модель
        /// </summary>
        /// <param name="WatchData">Параметры часов</param>
        /// <returns>3Д - солид модель</returns>
        public Solid3d BuildCrown(WatchData WatchData)
        {
            //заводная головка
            Solid3d CrownPart = new Solid3d();

            CrownPart.CreateFrustum(Height, Diameter, Diameter, Diameter);

            //низ заводной головки
            Solid3d CrownBottom = new Solid3d();

            CrownBottom.CreateFrustum(1, Diameter, Diameter, Diameter - _pararameters[ParNames.CrownBottomHeight]);
            CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _pararameters[ParNames.CrownTransformByZ] + _pararameters[ParNames.CrownTopHeight]) - Point3d.Origin));
            CrownPart.BooleanOperation(BooleanOperationType.BoolUnite, CrownBottom.Clone() as Solid3d);

            //вверх зав.головки
            Solid3d CrownTop = new Solid3d();

            CrownBottom.CreateFrustum(_pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter);
            CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -Height / _pararameters[ParNames.CrownTransformByZ] - 0.25) - Point3d.Origin));
            CrownPart.BooleanOperation(BooleanOperationType.BoolUnite, CrownBottom.Clone() as Solid3d);

            CrownBottom.CreateFrustum(_pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - 1);
            CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -Height / _pararameters[ParNames.CrownTransformByZ] - _pararameters[ParNames.CrownTopHeight]) - Point3d.Origin));
            CrownPart.BooleanOperation(BooleanOperationType.BoolSubtract, CrownBottom.Clone() as Solid3d);

            //вырезаем цилиндры по радиусу зав. головки
            Solid3d CrownCutter = new Solid3d();

            CrownCutter.CreateFrustum(Height + _pararameters[ParNames.CrownBottomHeight], Diameter / _pararameters[ParNames.CrownCutterCount], Diameter / _pararameters[ParNames.CrownCutterCount], Diameter / _pararameters[ParNames.CrownCutterCount]);

            for (int i = 0; i < _pararameters[ParNames.CrownCutterCylinder]; i++)
            {
                CrownCutter.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter * Math.Cos(Math.PI / 12 * i), Diameter * Math.Sin(Math.PI / 12 * i), 0)));
                CrownPart.BooleanOperation(BooleanOperationType.BoolSubtract, CrownCutter.Clone() as Solid3d);
                CrownCutter.TransformBy(Matrix3d.Displacement(new Vector3d(-Diameter * Math.Cos(Math.PI / 12 * i), -Diameter * Math.Sin(Math.PI / 12 * i), 0)));
            }

            CrownPart.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            CrownPart.TransformBy(Matrix3d.Displacement(new Vector3d(0, WatchData.BodyDiameter + Height / _pararameters[ParNames.CrownTransformByZ] + _pararameters[ParNames.CrownBottomHeight], 0)));
            return(CrownPart);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Строим стрелки
        /// </summary>
        /// <param name="WatchData">Информация о часах</param>
        /// <returns>модель стрелок</returns>
        private Solid3d BuildArrows(WatchData WatchData)
        {
            //стрелки
            Solid3d Arrows = new Solid3d();
            //база
            Solid3d Base = new Solid3d();

            //первая часть базы
            Base.CreateFrustum(_params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByZ], _params[ParNames.BodyTransformByZ], _params[ParNames.BodyTransformByZ]);
            Base.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4)));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Base.Clone() as Solid3d);

            //вторая часть бызы
            Base.CreateFrustum(_params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByY]);
            Base.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4 * 3)));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Base.Clone() as Solid3d);

            //часовая стрелка
            Solid3d Arrow = new Solid3d();

            Arrow.CreateBox(Diameter / 2, _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / 4);
            Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / 4), 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4)));
            double TrueHour = System.DateTime.Now.Hour + ((double)System.DateTime.Now.Minute / 60);

            Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 6 * TrueHour), new Vector3d(0, 0, 1), Point3d.Origin));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d);

            //минутная стрелка
            Arrow.CreateBox(Diameter / 2 + _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTransformByX] + _params[ParNames.BodyTransformByX] / 5, _params[ParNames.BodyTransformByX] / 5);
            Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / 4), 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4 * 3)));
            Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 30 * System.DateTime.Now.Minute), new Vector3d(0, 0, 1), Point3d.Origin));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d);
            //секундная стрелка
            Arrow.CreateBox(Diameter / 2 + _params[ParNames.BodyBottomHeight], _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 5);
            Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / _params[ParNames.BodyTopTransformByX]), 0, Height / 2 + _params[ParNames.BodyTransformByX] + _params[ParNames.BodyTransformByX] / 10)));
            Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 30 * System.DateTime.Now.Second), new Vector3d(0, 0, 1), Point3d.Origin));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d);

            return(Arrows);
        }
Ejemplo n.º 7
0
        public static void CreatePlane()
        {
            // Get the current document and database, and start a transaction
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table record for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                // Create a 3D solid box
                using (Solid3d acSol3D = new Solid3d())
                {
                    acSol3D.CreateBox(5, 7, 10);

                    // Position the center of the 3D solid at (5,5,0)
                    acSol3D.TransformBy(Matrix3d.Displacement(new Point3d(5, 5, 0) -
                                                              Point3d.Origin));

                    // Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acSol3D);
                    acTrans.AddNewlyCreatedDBObject(acSol3D, true);

                    // Create a copy of the original 3D solid and change the color of the copy
                    Solid3d acSol3DCopy = acSol3D.Clone() as Solid3d;
                    acSol3DCopy.ColorIndex = 1;

                    // Define the mirror plane
                    Plane acPlane = new Plane(new Point3d(1.25, 0, 0),
                                              new Point3d(1.25, 2, 0),
                                              new Point3d(1.25, 2, 2));

                    // Mirror the 3D solid across the plane
                    acSol3DCopy.TransformBy(Matrix3d.Mirroring(acPlane));

                    // Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acSol3DCopy);
                    acTrans.AddNewlyCreatedDBObject(acSol3DCopy, true);
                }

                // Save the new objects to the database
                acTrans.Commit();
            }
        }
Ejemplo n.º 8
0
        public static void MirrorABox3D()
        {
            // 获取当前文档和数据库,启动事务
            var acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var acCurDb = acDoc.Database;

            using (var acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 以读模式打开块表
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // 以写模式打开块表记录模型空间
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                // 创建3D箱体
                var acSol3D = new Solid3d();
                acSol3D.CreateBox(5, 7, 10);

                // 3D实体的中心点放在(5,5,0)
                acSol3D.TransformBy(Matrix3d.Displacement(new Point3d(5, 5, 0) -
                                                          Point3d.Origin));

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acSol3D);
                acTrans.AddNewlyCreatedDBObject(acSol3D, true);

                // 创建原3D箱体的拷贝并修改颜色
                var acSol3DCopy = acSol3D.Clone() as Solid3d;
                acSol3DCopy.ColorIndex = 1;

                // 定义镜像平面
                var acPlane = new Plane(new Point3d(1.25, 0, 0),
                                        new Point3d(1.25, 2, 0),
                                        new Point3d(1.25, 2, 2));

                // 沿平面镜像3D实体
                acSol3DCopy.TransformBy(Matrix3d.Mirroring(acPlane));

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acSol3DCopy);
                acTrans.AddNewlyCreatedDBObject(acSol3DCopy, true);

                // 提交事务
                acTrans.Commit();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     TODO
        /// </summary>
        /// <param name="acSol"></param>
        private void ReadEntity(Solid3d acSol, Database acCurDb, Transaction acTrans)
        {
            RcName       = acSol.GetPartName();
            ParentHandle = acSol.GetParent();
            ChildHandles = acSol.GetChildren();
            IsSweep      = acSol.GetIsSweep();
            IsMirror     = acSol.GetIsMirror();
            RcInfo       = acSol.GetPartInfo();
            RcQtyOf      = acSol.GetQtyOf();
            RcQtyTotal   = acSol.GetQtyTotal();
            TxDirection  = acSol.GetTextureDirection();

            GetRotationMatrices(acSol);
            GetLayMatrix(acSol);

            if (LayMatrix == new Matrix3d())
            {
                LayMatrix = GetAbstractMatrix(acSol);
            }

            using (var solCopy = acSol.Clone() as Solid3d)
            {
                if (solCopy != null)
                {
                    if (LayMatrix != Matrix3d.Identity)
                    {
                        solCopy.TransformBy(LayMatrix);
                    }

                    //Get Volume & Extents
                    Extents  = solCopy.GetBounds();
                    MinExt   = Extents.MinPoint;
                    MaxExt   = Extents.MaxPoint;
                    Centroid = solCopy.MassProperties.Centroid;
                    Box      = Extents.Volume();
                    Volume   = acSol.Volume();
                }
            }

            var identity = Matrix3d.Identity;

            if ((MaxExt.Z + MinExt.Z) / 2 < 0)
            {
                var vector3D = new Vector3d(0, 1, 0);
                identity   = Matrix3d.Rotation(3.14159265358979, vector3D, new Point3d());
                LayMatrix *= identity;
            }

            if (IsBox)
            {
                Asymmetry = 0;
            }
            else
            {
                var boxCen = GetBoxCenter(MinExt, MaxExt).RoundToTolerance();

                AsymmetryVector = boxCen.GetVectorTo(Centroid.RoundToTolerance());
                AsymmetryVector = AsymmetryVector.TransformBy(identity);
                Asymmetry       = AsymmetryVector.Length;

                if (!Asymmetry.IsLessThanTol())
                {
                    Asymmetry = Asymmetry.RoundToTolerance();
                }
                else
                {
                    Asymmetry = 0;
                }

                AsymmetryVector = AsymmetryVector.RoundToTolerance();

                if (Asymmetry > 0)
                {
                    FixMatrix(boxCen);
                }

                AsymString = AsymVStr(AsymmetryVector);
            }

            //Get length, width, thickness

            if (IsSweep)
            {
                //TODO
            }
            else
            {
                var measures = new List <double>(3)
                {
                    MaxExt.X - MinExt.X,
                    MaxExt.Y - MinExt.Y,
                    MaxExt.Z - MinExt.Z
                };

                measures.Sort();

                if (TxDirection == TextureDirection.Across)
                {
                    Width  = measures[2].RoundToTolerance();
                    Length = measures[1].RoundToTolerance();
                }
                else
                {
                    Length = measures[2].RoundToTolerance();
                    Width  = measures[1].RoundToTolerance();
                }

                Thickness = measures[0].RoundToTolerance();
            }

            //Add the XData
            acSol.AddXData(this, acCurDb, acTrans);
        }
Ejemplo n.º 10
0
        public static void DrawSolidDescription(ObjectIdCollection OuterContours, Point3d origin, Point3d Xaxe, Point3d Yaxe, PromptPointResult target, bool bds)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;  

            Vector3d vX, vY, vZ;
            ObjectId ID = OuterContours[OuterContours.Count - 1];
            Point3d centroid = new Point3d();
            string layer;
            ObjectId[] solids = { ID, ID, ID, ID, ID, ID, ID };
            using (Transaction acTrans = db.TransactionManager.StartTransaction())
            {
                BlockTable acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Entity ent = acTrans.GetObject(ID, OpenMode.ForRead) as Entity;

                #region check selection
                String[] str = ent.GetType().ToString().Split('.');
                if (str[str.Length - 1] != "Solid3d")//check for solid
                {
                    MessageBox.Show("No selected Solid !");
                    return;
                }

                Quaternion q1 = new Quaternion(Xaxe.X - origin.X, Xaxe.Y - origin.Y, Xaxe.Z - origin.Z, 0);
                Quaternion q2 = new Quaternion(Yaxe.X - origin.X, Yaxe.Y - origin.Y, Yaxe.Z - origin.Z, 0);

                if (q1.abs() < 10E-11)
                {
                    MessageBox.Show("origin = Xaxe !");
                    return;
                }

                if (q2.abs() < 10E-11)
                {
                    MessageBox.Show("origin = Xaxe !");
                    return;
                }


                q1 /= q1.abs();
                q2 /= q2.abs();

                Quaternion q = q2 / q1;
                q = new Quaternion(0, q.GetX(), q.GetY(), q.GetZ());
                if (q.norm() < 10E-14)
                {
                    MessageBox.Show("three points in one line !");
                    return;
                }
                #endregion

                Solid3d solid = acTrans.GetObject(ID, OpenMode.ForWrite) as Solid3d;
                layer = solid.Layer;
                solids[0] = solid.ObjectId;

                centroid = solid.MassProperties.Centroid;

                UCS UCS = new UCS(new Quaternion(0, origin.X, origin.Y, origin.Z), new Quaternion(0, Xaxe.X, Xaxe.Y, Xaxe.Z), new Quaternion(0, Yaxe.X, Yaxe.Y, Yaxe.Z));
                Quaternion ucsX = UCS.ToACS(new Quaternion(0, 1, 0, 0));
                Quaternion ucsY = UCS.ToACS(new Quaternion(0, 0, 1, 0));
                Quaternion ucsZ = UCS.ToACS(new Quaternion(0, 0, 0, 1));
                vX = origin.GetVectorTo(new Point3d(ucsX.GetX(), ucsX.GetY(), ucsX.GetZ()));
                vY = origin.GetVectorTo(new Point3d(ucsY.GetX(), ucsY.GetY(), ucsY.GetZ()));
                vZ = origin.GetVectorTo(new Point3d(ucsZ.GetX(), ucsZ.GetY(), ucsZ.GetZ()));

                _centroid = centroid;
                vO[0] = vX; vO[1] = vY; vO[2] = vZ;
                _target = target.Value;

                Matrix3d newMatrix = new Matrix3d();
                newMatrix = Matrix3d.AlignCoordinateSystem(centroid, vX, vY, vZ, centroid, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis);
                solid.TransformBy(newMatrix);


                Point3d MIN = new Point3d(solid.GeometricExtents.MinPoint.X - centroid.X, solid.GeometricExtents.MinPoint.Y - centroid.Y, solid.GeometricExtents.MinPoint.Z - centroid.Z);
                Point3d MAX = new Point3d(solid.GeometricExtents.MaxPoint.X - centroid.X, solid.GeometricExtents.MaxPoint.Y - centroid.Y, solid.GeometricExtents.MaxPoint.Z - centroid.Z);

                double MaxX = (Math.Abs(MIN.X) > Math.Abs(MAX.X)) ? Math.Abs(MIN.X) : Math.Abs(MAX.X);
                double MaxY = (Math.Abs(MIN.Y) > Math.Abs(MAX.Y)) ? Math.Abs(MIN.Y) : Math.Abs(MAX.Y);
                double MaxZ = (Math.Abs(MIN.Z) > Math.Abs(MAX.Z)) ? Math.Abs(MIN.Z) : Math.Abs(MAX.Z);


                Solid3d[] solidARR = { solid.Clone() as Solid3d, solid.Clone() as Solid3d, solid.Clone() as Solid3d, solid.Clone() as Solid3d, solid.Clone() as Solid3d };

                for (int i = 0; i < 5; i++)
                {
                    modelSpace.AppendEntity(solidARR[i]);
                    acTrans.AddNewlyCreatedDBObject(solidARR[i], true);
                }

                Vector3d vRot1 = centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y + 2.5 * Math.Abs(MAX.X), centroid.Z));
                Vector3d vRot2 = centroid.GetVectorTo(new Point3d(centroid.X + 2.5 * Math.Abs(MAX.X), centroid.Y, centroid.Z));
                Vector3d vRot3 = centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y, centroid.Z + 2.5 * Math.Abs(MAX.Z)));


                if (bds)
                {
                    solidARR[0].TransformBy(Matrix3d.Rotation(-Math.PI / 2.0, vRot1, centroid));
                    solidARR[0].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X - MaxZ - 1.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[1] = solidARR[0].ObjectId;
                    solidARR[1].TransformBy(Matrix3d.Rotation(Math.PI / 2.0, vRot1, centroid));
                    solidARR[1].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + MaxZ + 1.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[2] = solidARR[1].ObjectId;
                    solidARR[2].TransformBy(Matrix3d.Rotation(Math.PI, vRot1, centroid));
                    solidARR[2].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + 3 * MaxZ + 2.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[3] = solidARR[2].ObjectId;
                    solidARR[3].TransformBy(Matrix3d.Rotation(Math.PI / 2, vRot2, centroid));
                    solidARR[3].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y - MaxZ - 1.5 * MaxY, centroid.Z))));
                    solids[4] = solidARR[3].ObjectId;
                    solidARR[4].TransformBy(Matrix3d.Rotation(-Math.PI / 2, vRot2, centroid));
                    solidARR[4].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y + MaxZ + 1.5 * MaxY, centroid.Z))));
                    solids[5] = solidARR[4].ObjectId;
                }
                else
                {
                    solidARR[0].TransformBy(Matrix3d.Rotation(-Math.PI / 2.0, vRot1, centroid));
                    solidARR[0].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + MaxZ + 1.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[1] = solidARR[0].ObjectId;

                    solidARR[1].TransformBy(Matrix3d.Rotation(Math.PI / 2.0, vRot1, centroid));
                    solidARR[1].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X - MaxZ - 1.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[2] = solidARR[1].ObjectId;

                    solidARR[2].TransformBy(Matrix3d.Rotation(Math.PI, vRot1, centroid));
                    solidARR[2].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + 3 * MaxZ + 2.5 * MaxX, centroid.Y, centroid.Z))));
                    solids[3] = solidARR[2].ObjectId;
                    solidARR[3].TransformBy(Matrix3d.Rotation(Math.PI / 2, vRot2, centroid));
                    solidARR[3].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y + MaxZ + 1.5 * MaxY, centroid.Z))));
                    solids[4] = solidARR[3].ObjectId;
                    solidARR[4].TransformBy(Matrix3d.Rotation(-Math.PI / 2, vRot2, centroid));
                    solidARR[4].TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X, centroid.Y - MaxZ - 1.5 * MaxY, centroid.Z))));
                    solids[5] = solidARR[4].ObjectId;
                }

                Solid3d solid1 = solid.Clone() as Solid3d;
                modelSpace.AppendEntity(solid1);
                acTrans.AddNewlyCreatedDBObject(solid1, true);

                solids[6] = solid1.ObjectId;

                solid1.TransformBy(Matrix3d.Rotation(Math.PI / 4, vRot3, centroid));
                solid1.TransformBy(Matrix3d.Rotation(-Math.PI / 3.28854, vRot2, centroid));

                double dX = Math.Abs(solid1.GeometricExtents.MinPoint.X - centroid.X) + Math.Abs(solid.GeometricExtents.MaxPoint.X - centroid.X);
                double dY = Math.Abs(solid1.GeometricExtents.MinPoint.Y - centroid.Y) + Math.Abs(solid.GeometricExtents.MaxPoint.Y - centroid.Y);
                solid1.TransformBy(Matrix3d.Displacement(centroid.GetVectorTo(new Point3d(centroid.X + dX + 1.5 * MaxX, centroid.Y + dY + 1.5 * MaxY, 0))));

                acTrans.Commit();
            }

            for (int i = 0; i < 7; i++)
            {
                solids_buff[i] = solids[i];
            }


            doc.SendStringToExecute("-view\rO\rT\r", false, false, false);
            doc.SendStringToExecute("TILEMODE\r0\r", false, false, false);
            // Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", 0);
            // Doc.Editor.SwitchToPaperSpace();
            doc.SendStringToExecute("MSPACE\r", false, false, false);
            doc.SendStringToExecute("SOLPROF\rall\r\rY\rY\rY\r", false, false, false);
            doc.SendStringToExecute("PSPACE\r", false, false, false);
            doc.SendStringToExecute("TILEMODE\r1\r", false, false, false);
            //Doc.SendStringToExecute("ZOOM\rE\r" , false , false , false);
            doc.SendStringToExecute("hideflat\r", false, false, false);

            if (target.Status == PromptStatus.OK)
            {
                string bs = centroid.X.ToString() + "," + centroid.Y.ToString();
                string ts = target.Value.X.ToString() + "," + target.Value.Y.ToString();

                doc.SendStringToExecute("move\rlast\r\r" + bs + "\r" + ts + "\r", false, false, false);
                doc.SendStringToExecute("ZOOM\rE\r", false, false, false);

            }

            doc.SendStringToExecute("eraseflat\r", false, false, false);
            doc.SendStringToExecute("finalflat\r", false, false, false);
            doc.SendStringToExecute("ZOOM\rE\r", false, false, false);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Построить модель корпуса
        /// </summary>
        /// <param name="WatchData">параметры часов</param>
        /// <returns>3д модель корпуса</returns>
        private Solid3d BuildBody(WatchData WatchData)
        {
            //корпус часов
            Solid3d Body = new Solid3d();

            Body.CreateFrustum(Height, Diameter, Diameter, Diameter);

            //Верхняя часть корпуса
            Solid3d BodyTop = new Solid3d();

            BodyTop.CreateFrustum(_params[ParNames.BodyTransformByY], Diameter, Diameter, Diameter - _params[ParNames.BodyTransformByZ]);
            BodyTop.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByX]) - Point3d.Origin));
            Body.BooleanOperation(BooleanOperationType.BoolUnite, BodyTop.Clone() as Solid3d);


            //Нижняя часть корпуса
            Solid3d BodyBottom = new Solid3d();

            BodyBottom.CreateFrustum(_params[ParNames.BodyTransformByX], Diameter - _params[ParNames.BodyTopTransformByY], Diameter - _params[ParNames.BodyTopTransformByY], Diameter - _params[ParNames.BodyTransformByY]);
            BodyBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -(Height / 2 + _params[ParNames.BodyTransformByX] / 2)) - Point3d.Origin));
            Body.BooleanOperation(BooleanOperationType.BoolUnite, BodyBottom.Clone() as Solid3d);

            //Вырез на корпусе, сверху
            BodyTop = new Solid3d();
            BodyTop.CreateFrustum(_params[ParNames.BodyTransformByY], Diameter - _params[ParNames.BodyBottomTransformByX], Diameter - _params[ParNames.BodyBottomTransformByX], Diameter - _params[ParNames.BodyTopTransformByY]);
            BodyTop.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByX]) - Point3d.Origin));
            Body.BooleanOperation(BooleanOperationType.BoolSubtract, BodyTop.Clone() as Solid3d);


            //ушки на корпусе
            Solid3d Bootstrap = new Solid3d();

            Bootstrap.CreateBox(BootstrapLength * _params[ParNames.BodyTransformByY] + Diameter * _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]);
            Vector3d BootsrapPosition;
            Solid3d  ArcPart = new Solid3d();

            ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2);
            ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, 0, 0)));

            //Держатели на ушках
            Solid3d StrapHolder = new Solid3d();

            StrapHolder.CreateFrustum(WatchData.StrapWidth + _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY]);
            StrapHolder.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin));
            StrapHolder.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, -WatchData.StrapWidth / 2 - _params[ParNames.BodyTransformByY], 0)));
            ArcPart.BooleanOperation(BooleanOperationType.BoolUnite, StrapHolder.Clone() as Solid3d);
            Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d);

            //сглаженные углы на ушках
            ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2);
            ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin));
            ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), 0, 0)));

            StrapHolder.CreateFrustum(WatchData.StrapWidth + _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 2);
            StrapHolder.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            StrapHolder.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), -WatchData.StrapWidth / 2 - _params[ParNames.BodyTransformByY], 0)));
            ArcPart.BooleanOperation(BooleanOperationType.BoolUnite, StrapHolder.Clone() as Solid3d);

            Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d);
            BootsrapPosition = new Vector3d(0, WatchData.StrapWidth / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByZ], 0);
            Bootstrap.TransformBy(Matrix3d.Displacement(BootsrapPosition));

            Body.BooleanOperation(BooleanOperationType.BoolUnite, Bootstrap.Clone() as Solid3d);
            Bootstrap = new Solid3d();
            Bootstrap.CreateBox(BootstrapLength * _params[ParNames.BodyTransformByY] + Diameter * _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]);

            ArcPart = new Solid3d();
            ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY]);
            ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin));
            ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, 0, 0)));
            Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d);
            ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY]);
            ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin));
            ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), 0, 0)));
            Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d);
            BootsrapPosition = new Vector3d(0, -(WatchData.StrapWidth / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByZ]), 0);
            Bootstrap.TransformBy(Matrix3d.Displacement(BootsrapPosition));


            //соеденяем все вместе
            Body.BooleanOperation(BooleanOperationType.BoolUnite, Bootstrap.Clone() as Solid3d);

            //если есть хронограф, то выполняем
            if (HasChronograph)
            {
                //первая кнопка хронографа
                Solid3d ChronoButtonTop = new Solid3d();
                ChronoButtonTop.CreateFrustum(_params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX]);

                ChronoButtonTop.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
                ChronoButtonTop.TransformBy(Matrix3d.Displacement(new Vector3d(0, Diameter, 0)));
                ChronoButtonTop.TransformBy(Matrix3d.Rotation(Math.PI / 6, new Vector3d(0, 0, 1), Point3d.Origin));
                Body.BooleanOperation(BooleanOperationType.BoolUnite, ChronoButtonTop.Clone() as Solid3d);

                //вторая кнопка хронографа
                Solid3d ChronoButtonBottom = new Solid3d();
                ChronoButtonBottom.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]);
                ChronoButtonBottom.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
                ChronoButtonBottom.TransformBy(Matrix3d.Displacement(new Vector3d(0, Diameter, 0)));
                ChronoButtonBottom.TransformBy(Matrix3d.Rotation(-Math.PI / 6, new Vector3d(0, 0, 1), Point3d.Origin));
                Body.BooleanOperation(BooleanOperationType.BoolUnite, ChronoButtonBottom.Clone() as Solid3d);
            }

            return(Body);
        }
Ejemplo n.º 12
0
        public void interferenceSolids()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTable blkTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    if (blkTable == null)
                    {
                        trans.Abort();
                        return;
                    }

                    BlockTableRecord blkTableRecord = trans.GetObject(blkTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                    if (blkTableRecord == null)
                    {
                        return;
                    }

                    using (Solid3d solid3DBox = new Solid3d())
                    {
                        // 3D Solid Box.
                        solid3DBox.CreateBox(5, 7, 10);
                        solid3DBox.ColorIndex = 7;

                        // Position of the center of solid3DBox at (5, 5, 0)
                        solid3DBox.TransformBy(Matrix3d.Displacement(new Point3d(5, 5, 0) - Point3d.Origin));

                        //blkTableRecord.AppendEntity(solid3DBox);
                        //trans.AddNewlyCreatedDBObject(solid3DBox, true);

                        // 3D Solid Cylinder.
                        using (Solid3d solid3DCylinder = new Solid3d())
                        {
                            solid3DCylinder.CreateFrustum(20, 5, 5, 5);
                            solid3DCylinder.ColorIndex = 4;

                            //blkTableRecord.AppendEntity(solid3DCylinder);
                            //trans.AddNewlyCreatedDBObject(solid3DCylinder, true);

                            // Create 3D solid from the interference of the box and cylinder.
                            //Solid3d solid3dCopy = solid3DCylinder.Clone() as Solid3d;

                            //if (solid3dCopy.CheckInterference(solid3DBox) == true)
                            //{
                            //    solid3dCopy.BooleanOperation(BooleanOperationType.BoolSubtract, solid3DBox.Clone() as Solid3d);
                            //    solid3dCopy.ColorIndex = 1;
                            //}

                            //// add solid3dCopy to the block table record.
                            //blkTableRecord.AppendEntity(solid3dCopy);
                            //trans.AddNewlyCreatedDBObject(solid3dCopy, true);

                            Solid3d solid3dCopyCylinder = solid3DCylinder.Clone() as Solid3d;

                            if (solid3dCopyCylinder.CheckInterference(solid3DBox) == true)
                            {
                                solid3dCopyCylinder.BooleanOperation(BooleanOperationType.BoolIntersect, solid3DBox);
                                solid3dCopyCylinder.ColorIndex = 3;
                            }

                            blkTableRecord.AppendEntity(solid3dCopyCylinder);
                            trans.AddNewlyCreatedDBObject(solid3dCopyCylinder, true);
                        }
                    }

                    trans.Commit();
                }
                catch (System.Exception)
                {
                    trans.Abort();
                    throw;
                }
            }
        }
Ejemplo n.º 13
0
        public static Point3d DistFromPointToSolid(
            ref Document doc, ref Solid3d solid, Point3d point, double start, double step, ref double off, bool line)
        {
            var rez = new Point3d();

            using (var acTrans = doc.Database.TransactionManager.StartTransaction())
            {
                var acBlkTbl = (BlockTable)acTrans.GetObject(doc.Database.BlockTableId, OpenMode.ForWrite);

                var acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                var SOLID = (Solid3d)solid.Clone();
                SOLID.SetDatabaseDefaults();
                acBlkTblRec.AppendEntity(SOLID);
                acTrans.AddNewlyCreatedDBObject(SOLID, true);


                var startR = start <= 0 ? step : start;

                var sphere = new Solid3d();
                sphere.SetDatabaseDefaults();
                sphere.CreateSphere(startR);
                sphere.TransformBy(Matrix3d.Displacement(Point3d.Origin.GetVectorTo(point)));
                sphere.SetDatabaseDefaults();
                acBlkTblRec.AppendEntity(sphere);
                acTrans.AddNewlyCreatedDBObject(sphere, true);


                while (sphere.CheckInterference(solid) == false)
                {
                    try
                    {
                        sphere.OffsetBody(step);
                        off += step;
                    }
                    catch
                    {
                    }
                }

                if (line)
                {
                    var counter = 0;

                    sphere.BooleanOperation(BooleanOperationType.BoolIntersect, SOLID);
                    var dbo = new DBObjectCollection();
                    sphere.Explode(dbo);

                    var coll       = new Point3dCollection();
                    var curvesColl = new DBObjectCollection();

                    var ent = dbo[0] as Entity;
                    if (ent.GetType().ToString().IndexOf("Surface") > 0)
                    {
                        var surf =
                            ent as Surface;
                        var ns = surf.ConvertToNurbSurface();
                        foreach (var nurb in ns)
                        {
                            double ustart   = nurb.UKnots.StartParameter,
                                     uend   = nurb.UKnots.EndParameter,
                                     uinc   = (uend - ustart) / nurb.UKnots.Count,
                                     vstart = nurb.VKnots.StartParameter,
                                     vend   = nurb.VKnots.EndParameter,
                                     vinc   = (vend - vstart) / nurb.VKnots.Count;

                            for (var u = ustart; u <= uend; u += uinc)
                            {
                                for (var v = vstart; v <= vend; v += vinc)
                                {
                                    coll.Add(nurb.Evaluate(u, v));
                                    counter++;
                                }
                            }
                        }
                        if (counter < 1)
                        {
                            var sub = new DBObjectCollection();
                            surf.Explode(sub);
                            foreach (Entity entt in sub)
                            {
                                acBlkTblRec.AppendEntity(entt);
                                acTrans.AddNewlyCreatedDBObject(entt, true);
                                curvesColl.Add(entt);
                            }
                        }
                    }
                    else
                    {
                        var surf = (Region)ent;
                        var p1   = surf.GeometricExtents.MaxPoint;
                        var p2   = surf.GeometricExtents.MinPoint;
                        var p    = new Point3d((p1.X + p2.X) / 2.0, (p1.Y + p2.Y) / 2.0, (p1.Z + p2.Z) / 2.0);
                        coll.Add(p);
                        coll.Add(p);
                        var sub = new DBObjectCollection();
                        surf.Explode(sub);
                        foreach (Entity entt in sub)
                        {
                            acBlkTblRec.AppendEntity(entt);
                            acTrans.AddNewlyCreatedDBObject(entt, true);
                            curvesColl.Add(entt);
                        }
                    }

                    foreach (DBObject ob in curvesColl)
                    {
                        var curve = (Curve)acTrans.GetObject(ob.Id, OpenMode.ForRead);
                        var p1    = curve.StartPoint;
                        var p2    = curve.EndPoint;
                        var p     = new Point3d((p1.X + p2.X) / 2.0, (p1.Y + p2.Y) / 2.0, (p1.Z + p2.Z) / 2.0);

                        coll.Add(p);
                        coll.Add(p1);
                        coll.Add(p2);
                    }

                    if (coll.Count > 0)
                    {
                        rez = coll[0];
                        foreach (Point3d p in coll)
                        {
                            if (p.DistanceTo(point) < rez.DistanceTo(point))
                            {
                                rez = p;
                            }
                        }
                    }
                    else
                    {
                        rez = point;
                    }
                }
                // acTrans.Commit();
            }
            return(rez);
        }