Line class use to store information about line(include startPoint and endPoint) and get the value via (startPoint, endPoint)property
예제 #1
0
파일: OpeningInfo.cs 프로젝트: AMEE/revit
        /// <summary>
        /// get line from List<XYZ>(points) and add line to m_lines list
        /// </summary>
        /// <param name="points">a List<XYZ> contain points of the Curve</param>
        private void AddLine(List<XYZ> points)
        {
            if (null == points || 0 == points.Count)
            {
                return;
            }

            Autodesk.Revit.DB.XYZ previousPoint;
            previousPoint = points[0];

            for (int i = 1; i < points.Count; i++)
            {
                Autodesk.Revit.DB.XYZ point;
                point = points[i];

                Line3D line = new Line3D();
                Vector pointStart = new Vector();
                Vector pointEnd = new Vector();
                for (int j = 0; j < 3; j++)
                {
                    pointStart[j] = previousPoint[j];
                    pointEnd[j] = point[j];
                }
                line.StartPoint = pointStart;
                line.EndPoint = pointEnd;

                m_lines.Add(line);

                previousPoint = point;
            }
        }
예제 #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);
            }
        }
예제 #3
0
파일: UCS.cs 프로젝트: AMEE/revit
 /// <summary>
 /// Transform global coordinate to local coordinate
 /// </summary>
 /// <param name="line">a line which need to transform</param>
 public Line3D GC2LC(Line3D line)
 {
     Vector startPnt = GC2LC(line.StartPoint);
     Vector endPnt = GC2LC(line.EndPoint);
     return new Line3D(startPnt, endPnt);
 }