This class stand for user coordinate system
Ejemplo n.º 1
0
        /// <summary>
        /// transform 3d point to 2d (if all points in the same plane)
        /// </summary>
        private void Frame3DTo2D(ReadOnlyCollection <Line3D> line3Ds)
        {
            const double LengthEpsilon = 0.01;
            const double AngleEpsilon  = 0.1;
            // find 3 points to form 2 lines whose length is bigger than LengthEpsilon
            // and angle between them should be bigger than AngleEpsilon
            Line3D line0   = line3Ds[0];
            Vector vector0 = new Vector();
            Vector vector1 = new Vector();
            // to find the first 2 points to form first line
            int index = 0;

            for (int i = 1; i < line3Ds.Count; i++)
            {
                vector0 = line3Ds[i].StartPoint - line0.StartPoint;
                if (vector0.GetLength() > LengthEpsilon)
                {
                    index = i;
                    break;
                }
            }
            if (index == 0)
            {
                return;
            }
            // to find the last points to form the second line
            for (int j = index + 1; j < line3Ds.Count; j++)
            {
                vector1 = line3Ds[j].StartPoint - line3Ds[index].StartPoint;
                double angle = Vector.GetAngleOf2Vectors(vector0, vector1, true);
                if (vector1.GetLength() > LengthEpsilon && angle > AngleEpsilon)
                {
                    break;
                }
            }

            // find the local coordinate system in which the profile of opening is horizontal
            Vector zAxis  = (vector0 & vector1).GetNormal();
            Vector xAxis  = zAxis & (new Vector(0.0, 1.0, 0.0));
            Vector yAxis  = zAxis & xAxis;
            Vector origin = new Vector(0.0, 0.0, 0.0);
            UCS    ucs    = new UCS(origin, xAxis, yAxis);

            // transform all the 3D lines to UCS and create accordingly 2D lines
            bool isFirst = true;

            foreach (Line3D line in line3Ds)
            {
                Line3D     tmp         = ucs.GC2LC(line);
                PointF     startPnt    = new PointF((float)tmp.StartPoint.X, (float)tmp.StartPoint.Y);
                PointF     endPnt      = new PointF((float)tmp.EndPoint.X, (float)tmp.EndPoint.Y);
                Line2D     line2D      = new Line2D(startPnt, endPnt);
                LineSketch aLineSketch = new LineSketch(line2D);
                if (isFirst)
                {
                    m_boundingBox = aLineSketch.BoundingBox;
                    isFirst       = false;
                }
                else
                {
                    m_boundingBox = RectangleF.Union(m_boundingBox, aLineSketch.BoundingBox);
                }
                m_objects.Add(aLineSketch);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// transform 3d point to 2d (if all points in the same plane)
        /// </summary>
        private void Frame3DTo2D(ReadOnlyCollection<Line3D> line3Ds)
        {
            const double LengthEpsilon = 0.01;
            const double AngleEpsilon = 0.1;
            // find 3 points to form 2 lines whose length is bigger than LengthEpsilon
            // and angle between them should be bigger than AngleEpsilon
            Line3D line0 = line3Ds[0];
            Vector vector0 = new Vector();
            Vector vector1 = new Vector();
            // to find the first 2 points to form first line
            int index = 0;
            for (int i = 1; i < line3Ds.Count; i++)
            {
                vector0 = line3Ds[i].StartPoint - line0.StartPoint;
                if (vector0.GetLength() > LengthEpsilon)
                {
                    index = i;
                    break;
                }
            }
            if (index == 0)
            {
                return;
            }
            // to find the last points to form the second line
            for (int j = index + 1; j < line3Ds.Count; j++)
            {
                vector1 = line3Ds[j].StartPoint - line3Ds[index].StartPoint;
                double angle = Vector.GetAngleOf2Vectors(vector0, vector1, true);
                if (vector1.GetLength() > LengthEpsilon && angle > AngleEpsilon)
                {
                    break;
                }
            }

            // find the local coordinate system in which the profile of opening is horizontal
            Vector zAxis = (vector0 & vector1).GetNormal();
            Vector xAxis = zAxis & (new Vector(0.0, 1.0, 0.0));
            Vector yAxis = zAxis & xAxis;
            Vector origin = new Vector(0.0, 0.0, 0.0);
            UCS ucs = new UCS(origin, xAxis, yAxis);

            // transform all the 3D lines to UCS and create accordingly 2D lines
            bool isFirst = true;
            foreach (Line3D line in line3Ds)
            {
                Line3D tmp = ucs.GC2LC(line);
                PointF startPnt = new PointF((float)tmp.StartPoint.X, (float)tmp.StartPoint.Y);
                PointF endPnt = new PointF((float)tmp.EndPoint.X, (float)tmp.EndPoint.Y);
                Line2D line2D = new Line2D(startPnt, endPnt);
                LineSketch aLineSketch = new LineSketch(line2D);
                if (isFirst)
                {
                    m_boundingBox = aLineSketch.BoundingBox;
                    isFirst = false;
                }
                else
                {
                    m_boundingBox = RectangleF.Union(m_boundingBox, aLineSketch.BoundingBox);
                }
                m_objects.Add(aLineSketch);
            }
        }