/// <summary> /// Get the bound of a face /// </summary> /// <returns>points array stores the bound of the face</returns> public override PointF[] GetFaceBounds() { Matrix4 matrix = m_to2DMatrix; Matrix4 inverseMatrix = matrix.Inverse(); float minX = 0, maxX = 0, minY = 0, maxY = 0; bool bFirstPoint = true; //get the max and min point on the face for (int i = 0; i < m_points.Count; i++) { List <XYZ> points = m_points[i]; foreach (Autodesk.Revit.DB.XYZ point in points) { Vector4 v = new Vector4(point); Vector4 v1 = inverseMatrix.Transform(v); if (bFirstPoint) { minX = maxX = v1.X; minY = maxY = v1.Y; bFirstPoint = false; } else { if (v1.X < minX) { minX = v1.X; } else if (v1.X > maxX) { maxX = v1.X; } if (v1.Y < minY) { minY = v1.Y; } else if (v1.Y > maxY) { maxY = v1.Y; } } } } //return an array with max and min value of face PointF[] resultPoints = new PointF[2] { new PointF(minX, minY), new PointF(maxX, maxY) }; return(resultPoints); }
/// <summary> /// transform the point on Form to 3d world coordinate of revit /// </summary> /// <param name="ps">contain the points to be transformed</param> /// <returns>Vector list contains points being transformed</returns> public virtual List <Vector4> Transform2DTo3D(Point[] ps) { List <Vector4> result = new List <Vector4>(); TransformPoints(ps); Matrix4 transformMatrix = Matrix4.Multiply( m_scaleMatrix.Inverse(), m_moveToCenterMatrix); transformMatrix = Matrix4.Multiply(transformMatrix, m_to2DMatrix); foreach (Point point in ps) { Vector4 v = new Vector4(point.X, point.Y, 0); v = transformMatrix.Transform(v); result.Add(v); } return(result); }
/// <summary> /// draw profile of wall or floor in 2D /// </summary> /// <param name="graphics">form graphic</param> /// <param name="pen">pen used to draw line in pictureBox</param> /// <param name="matrix4">Matrix used to transform 3d to 2d /// and make picture in right scale </param> public virtual void Draw2D(Graphics graphics, Pen pen, Matrix4 matrix4) { //move the gdi origin to the picture center graphics.Transform = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, m_sizePictureBox.Width / 2, m_sizePictureBox.Height / 2); //draw profile for (int i = 0; i < m_points.Count; i++) { List<XYZ> points = m_points[i]; for (int j = 0; j < points.Count - 1; j++) { Autodesk.Revit.DB.XYZ point1 = points[j]; Autodesk.Revit.DB.XYZ point2 = points[j + 1]; Vector4 v1 = new Vector4(point1); Vector4 v2 = new Vector4(point2); v1 = matrix4.Transform(v1); v2 = matrix4.Transform(v2); graphics.DrawLine(pen, new Point((int)v1.X, (int)v1.Y), new Point((int)v2.X, (int)v2.Y)); } } }