Пример #1
0
        public List <Line> TangentLines2d(Point point)
        {
            if (!point.IsCoplanarTo(this))
            {
                return(null);
            }
            List <Line> list     = new List <Line>();
            Vector3d    vector3d = new Vector3d(point - this.point_0);
            double      norm     = vector3d.Norm;

            if (this.double_0 - norm > Global.AbsoluteEpsilon)
            {
                return(list);
            }
            if (Global.AlmostEquals(norm, this.double_0))
            {
                Point    point2          = this.point_0 + this.double_0 / norm * vector3d.ToPoint();
                Vector3d directionVector = Vector3d.Cross(vector3d, this.NormalVector);
                list.Add(new Line(point2, directionVector));
                return(list);
            }
            double scalar = this.double_0 * this.double_0 / (norm * norm);
            Point  point3 = this.point_0 + scalar * vector3d.ToPoint();
            Plane  plane  = new Plane(point3, vector3d);
            Edge   edge   = this.method_6(plane);

            list.Add(new Line(point, edge.StartPoint));
            list.Add(new Line(point, edge.EndPoint));
            return(list);
        }
Пример #2
0
 public Edge Move(Vector3d displacementVector)
 {
     return(new Edge
     {
         startPoint = this.startPoint + displacementVector.ToPoint(),
         endPoint = this.endPoint + displacementVector.ToPoint()
     });
 }
Пример #3
0
 public Arc Move(Vector3d displacementVector)
 {
     return(new Arc
     {
         point_0 = this.point_0 + displacementVector.ToPoint(),
         point_1 = this.point_1 + displacementVector.ToPoint(),
         vector3d_0 = this.vector3d_0.DeepCopy(),
         double_0 = this.double_0
     });
 }
Пример #4
0
        public Plane Move(Vector3d displacementVector)
        {
            Plane plane = this.DeepCopy();

            plane.Point = this.point_0 + displacementVector.ToPoint();
            return(plane);
        }
Пример #5
0
        private Point method_0(Line line_0)
        {
            Vector3d vector3d = line_0.DirectionVector.Normalize();
            double   scalar   = Vector3d.Dot(new Vector3d(this - line_0.Point), vector3d);

            return(line_0.Point + scalar * vector3d.ToPoint());
        }
Пример #6
0
        public Point RandomPointInCircle()
        {
            Vector3d vector3d = this.vector3d_0.RandomOrthonormal();
            double   scalar   = this.double_0 * RandomGenerator.NextDouble_0_1();

            return(this.point_0 + scalar * vector3d.ToPoint());
        }
Пример #7
0
        private Point method_1(Plane plane_0)
        {
            Vector3d nCF_normal = plane_0.NCF_normal;
            double   num        = Vector3d.Dot(this.method_2(), nCF_normal);
            double   scalar     = plane_0.NCF_d - num;

            return(this + scalar * nCF_normal.ToPoint());
        }
Пример #8
0
 public Line Move(Vector3d displacementVector)
 {
     return(new Line
     {
         point_0 = this.point_0 + displacementVector.ToPoint(),
         vector3d_0 = this.vector3d_0.DeepCopy()
     });
 }
Пример #9
0
 public Circle Move(Vector3d displacementVector)
 {
     return(new Circle
     {
         point_0 = this.point_0 + displacementVector.ToPoint(),
         double_0 = this.double_0,
         vector3d_0 = new Vector3d(this.vector3d_0.X, this.vector3d_0.Y, this.vector3d_0.Z)
     });
 }
Пример #10
0
        public Point RandomPointInEllipse()
        {
            double   scalar           = RandomGenerator.NextDouble_1_1();
            double   tetha            = RandomGenerator.NextDouble_0_2Pi();
            Point    pointAtParameter = this.GetPointAtParameter(tetha);
            Vector3d vector3d         = scalar * new Vector3d(pointAtParameter - this.point_0);

            return(this.point_0 + vector3d.ToPoint());
        }
Пример #11
0
 public Ellipse Move(Vector3d displacementVector)
 {
     return(new Ellipse
     {
         point_0 = this.point_0 + displacementVector.ToPoint(),
         vector3d_0 = new Vector3d(this.vector3d_0.X, this.vector3d_0.Y, this.vector3d_0.Z),
         vector3d_1 = new Vector3d(this.vector3d_1.X, this.vector3d_1.Y, this.vector3d_1.Z)
     });
 }
Пример #12
0
        public Arc(Point center, Vector3d startVector, Vector3d endVector, Vector3d normalVector)
        {
            this.point_0    = center;
            this.point_1    = center + startVector.ToPoint();
            this.vector3d_0 = normalVector;
            double num = Vector3d.OrientedAngle(startVector, endVector, normalVector);

            this.double_0 = num;
            if (!Global.AlmostEquals(startVector.Norm, endVector.Norm))
            {
                throw new ArgumentException("Error constructing arc: start vector length not equal end vector length.");
            }
            if (!startVector.IsOrthogonalTo(normalVector) && !endVector.IsOrthogonalTo(normalVector))
            {
                throw new ArgumentException("Error constructing arc: Normal vector not orthogonal to start and end vector.");
            }
        }
Пример #13
0
        public double DistanceTo(Circle circle)
        {
            Vector3d a        = Vector3d.Cross(this.vector3d_2, circle.NormalVector);
            Vector3d vector3d = Vector3d.Cross(a, circle.NormalVector);

            vector3d.Norm = circle.Radius;
            Vector3d vector3d2 = -1.0 * vector3d;
            Point    point     = circle.Center + vector3d.ToPoint();
            Point    point2    = circle.Center + vector3d2.ToPoint();
            double   value     = point.DistanceTo(this);
            double   value2    = point2.DistanceTo(this);

            if (Math.Sign(value) != Math.Sign(value2))
            {
                return(0.0);
            }
            return(Math.Min(Math.Abs(value), Math.Abs(value2)));
        }
Пример #14
0
        private Point method_9(Line line_0)
        {
            if (this.IsParallelTo(line_0))
            {
                throw new ArgumentException("Can not compute base point of perpendicular: lines are parallel.");
            }
            Vector3d a        = this.vector3d_0.Normalize();
            Vector3d vector3d = -1.0 * line_0.vector3d_0.Normalize();
            Vector3d b        = new Vector3d(line_0.point_0 - this.point_0);
            Vector3d c        = Vector3d.Cross(a, vector3d).Normalize();
            double   num      = Vector3d.Triple(a, vector3d, c);
            double   num2     = Vector3d.Triple(a, b, c);

            if (Math.Abs(num) <= 4.94065645841247E-324)
            {
                return(this.method_3(line_0));
            }
            double scalar = num2 / num;

            return(line_0.point_0 - scalar * vector3d.ToPoint());
        }
Пример #15
0
        public List <Line> TangentLines2d(Circle circle)
        {
            if (!circle.IsCoplanarTo(this))
            {
                return(null);
            }
            List <Line> list = new List <Line>();

            if (this.Contains(circle))
            {
                return(list);
            }
            if (circle.Contains(this))
            {
                return(list);
            }
            Vector3d vector3d = new Vector3d(circle.point_0 - this.point_0);

            if (this.Intersects2d(circle))
            {
                if (Global.AlmostEquals(this.double_0, circle.double_0))
                {
                    Vector3d b         = new Vector3d(this.point_0 - circle.point_0);
                    Vector3d vector3d2 = Vector3d.Cross(this.NormalVector, b);
                    vector3d2.Norm = this.double_0;
                    list.Add(new Line(this.point_0, circle.point_0).Move(vector3d2));
                    list.Add(new Line(this.point_0, circle.point_0).Move(-1.0 * vector3d2));
                    return(list);
                }
                double scalar = this.double_0 / (this.double_0 - circle.double_0);
                Point  point  = this.point_0 + scalar * vector3d.ToPoint();
                return(this.TangentLines2d(point));
            }
            else
            {
                if (Global.AlmostEquals(this.double_0, circle.double_0))
                {
                    Vector3d b2        = new Vector3d(this.point_0 - circle.point_0);
                    Vector3d vector3d3 = Vector3d.Cross(this.NormalVector, b2);
                    vector3d3.Norm = this.double_0;
                    list.Add(new Line(this.point_0, circle.point_0).Move(vector3d3));
                    list.Add(new Line(this.point_0, circle.point_0).Move(-1.0 * vector3d3));
                    double      scalar2 = this.double_0 / (this.double_0 + circle.double_0);
                    Point       point2  = this.point_0 + scalar2 * vector3d.ToPoint();
                    List <Line> list2   = this.TangentLines2d(point2);
                    foreach (Line current in list2)
                    {
                        list.Add(current);
                    }
                    return(list);
                }
                double      scalar3 = this.double_0 / (this.double_0 - circle.double_0);
                double      scalar4 = this.double_0 / (this.double_0 + circle.double_0);
                Point       point3  = this.point_0 + scalar3 * vector3d.ToPoint();
                Point       point4  = this.point_0 + scalar4 * vector3d.ToPoint();
                List <Line> list3   = this.TangentLines2d(point3);
                List <Line> list4   = this.TangentLines2d(point4);
                foreach (Line current2 in list3)
                {
                    list.Add(current2);
                }
                foreach (Line current3 in list4)
                {
                    list.Add(current3);
                }
                return(list);
            }
        }
Пример #16
0
        public Point RandomPointOnCircle()
        {
            Vector3d vector3d = this.vector3d_0.RandomOrthonormal();

            return(this.point_0 + this.double_0 * vector3d.ToPoint());
        }
Пример #17
0
        public List <Point> DevelopPolyline(ObjectId plineID, bool reverse, double startBGL, double endBGL)
        {
            Database workingDatabase = HostApplicationServices.WorkingDatabase;
            PointSet pointSet        = new PointSet();

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                DBObject @object = transaction.GetObject(plineID, (OpenMode)0, true);
                pointSet = PointGeneration.SubdividePolyline(@object, transaction, 0.0);
            }
            if (reverse)
            {
                pointSet.Reverse();
            }
            PointSet pointSet2 = new PointSet();
            double   num       = 0.0;
            double   num2      = 0.0;
            double   num3      = 0.0;

            for (int i = 0; i < pointSet.Count - 1; i++)
            {
                double num4 = pointSet[i].DistanceTo(pointSet[i + 1]);
                double num5 = pointSet[i].DistanceXY(pointSet[i + 1]);
                if (startBGL >= num && startBGL < num + num4)
                {
                    ngeometry.VectorGeometry.Vector3d vector3d = new ngeometry.VectorGeometry.Vector3d(pointSet[i + 1] - pointSet[i]);
                    vector3d.Norm = Math.Abs(startBGL - num);
                    pointSet2.Add(pointSet[i] + vector3d.ToPoint());
                    num3 = num2 + pointSet[i].DistanceXY(pointSet[i] + vector3d.ToPoint());
                }
                if (num > startBGL && num < endBGL)
                {
                    pointSet2.Add(pointSet[i]);
                }
                if (endBGL > num && endBGL <= num + num4)
                {
                    ngeometry.VectorGeometry.Vector3d vector3d2 = new ngeometry.VectorGeometry.Vector3d(pointSet[i + 1] - pointSet[i]);
                    vector3d2.Norm = Math.Abs(endBGL - num);
                    pointSet2.Add(pointSet[i] + vector3d2.ToPoint());
                }
                num  += num4;
                num2 += num5;
            }
            if (endBGL > num)
            {
                pointSet2.Add(pointSet[pointSet.Count - 1]);
            }
            PointSet pointSet3 = new PointSet();
            double   num6      = num3;

            for (int j = 0; j < pointSet2.Count; j++)
            {
                pointSet3.Add(new Point(num6, CMD_Development.double_2 * pointSet2[j].Z, 0.0));
                if (j == pointSet2.Count - 1)
                {
                    break;
                }
                num6 += pointSet2[j].DistanceXY(pointSet2[j + 1]);
            }
            return(pointSet3.ToList());
        }
Пример #18
0
        public static PointSet SubdividePolyline3d(Polyline3d p3d, Transaction trans, double d)
        {
            PointSet result;

            try
            {
                PointSet pointSet = new PointSet();
                if (d <= 0.0)
                {
                    //using (IEnumerator enumerator = p3d.GetEnumerator())
                    {
                        IEnumerator enumerator = p3d.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            ObjectId         objectId         = (ObjectId)enumerator.Current;
                            PolylineVertex3d polylineVertex3d = (PolylineVertex3d)trans.GetObject(objectId, (OpenMode)0);
                            Point            point            = new Point(polylineVertex3d.Position.X, polylineVertex3d.Position.Y, polylineVertex3d.Position.Z);
                            if (pointSet.Count > 1)
                            {
                                if (pointSet[pointSet.Count - 1] != point)
                                {
                                    pointSet.Add(point);
                                }
                            }
                            else
                            {
                                pointSet.Add(point);
                            }
                        }
                        goto IL_233;
                    }
                }
                List <Point> list = new List <Point>();
                foreach (ObjectId objectId2 in p3d)
                {
                    PolylineVertex3d polylineVertex3d2 = (PolylineVertex3d)trans.GetObject(objectId2, (OpenMode)0);
                    list.Add(new Point(polylineVertex3d2.Position.X, polylineVertex3d2.Position.Y, polylineVertex3d2.Position.Z));
                }
                if (p3d.Closed)
                {
                    list.Add(list[0]);
                }
                for (int i = 0; i < list.Count - 1; i++)
                {
                    Point point2 = list[i];
                    Point point3 = list[i + 1];
                    ngeometry.VectorGeometry.Vector3d vector3d = new ngeometry.VectorGeometry.Vector3d(point3 - point2);
                    double num  = point2.DistanceTo(point3);
                    double num2 = (double)((int)Math.Max(Math.Ceiling(num / d), 1.0));
                    double norm = num / num2;
                    vector3d.Norm = norm;
                    int num3 = 0;
                    while ((double)num3 < num2)
                    {
                        pointSet.Add(point2 + (double)num3 * vector3d.ToPoint());
                        num3++;
                    }
                }
                if (!p3d.Closed)
                {
                    pointSet.Add(list[list.Count - 1]);
                }
IL_233:
                result = pointSet;
            }
            catch (System.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Can not subdivide polyline3d (handle: " + p3d.Handle.ToString() + ")\n");
                result = null;
            }
            return(result);
        }
Пример #19
0
        public Point RandomPointOnLine()
        {
            Vector3d vector3d = RandomGenerator.NextDouble_mr_mr() * this.DirectionVector.Normalize();

            return(this.point_0 + vector3d.ToPoint());
        }
Пример #20
0
 public Point Move(Vector3d displacementVector)
 {
     return(this + displacementVector.ToPoint());
 }
Пример #21
0
        public static PointSet SubdivideLWPolyline(Polyline lwp, double d)
        {
            PointSet result;

            try
            {
                PointSet pointSet         = new PointSet();
                int      numberOfVertices = lwp.NumberOfVertices;
                if (d <= 0.0)
                {
                    for (int i = 0; i < numberOfVertices; i++)
                    {
                        Point3d point3dAt = lwp.GetPoint3dAt(i);
                        Point   point     = new Point(point3dAt.X, point3dAt.Y, point3dAt.Z);
                        if (pointSet.Count > 1)
                        {
                            if (pointSet[pointSet.Count - 1] != point)
                            {
                                pointSet.Add(point);
                            }
                        }
                        else
                        {
                            pointSet.Add(point);
                        }
                    }
                }
                else
                {
                    List <Point> list = new List <Point>();
                    for (int j = 0; j < numberOfVertices; j++)
                    {
                        Point3d point3dAt2 = lwp.GetPoint3dAt(j);
                        list.Add(new Point(point3dAt2.X, point3dAt2.Y, point3dAt2.Z));
                    }
                    if (lwp.Closed)
                    {
                        list.Add(list[0]);
                    }
                    for (int k = 0; k < list.Count - 1; k++)
                    {
                        Point point2 = list[k];
                        Point point3 = list[k + 1];
                        ngeometry.VectorGeometry.Vector3d vector3d = new ngeometry.VectorGeometry.Vector3d(point3 - point2);
                        double num  = point2.DistanceTo(point3);
                        int    num2 = (int)Math.Max(Math.Ceiling(num / d), 1.0);
                        double norm = num / (double)num2;
                        vector3d.Norm = norm;
                        for (int l = 0; l < num2; l++)
                        {
                            pointSet.Add(point2 + (double)l * vector3d.ToPoint());
                        }
                    }
                    if (!lwp.Closed)
                    {
                        pointSet.Add(list[list.Count - 1]);
                    }
                }
                result = pointSet;
            }
            catch (System.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Can not subdivide polyline (handle: " + lwp.Handle.ToString() + ")\n");
                result = null;
            }
            return(result);
        }