/// <summary> /// Get a matrix which can transform points to 2D /// </summary> /// <returns>matrix which can transform points to 2D</returns> public override Matrix4 GetTo2DMatrix() { //get transform used to transform points to plane whose normal is Zaxis of beam Vector4 xAxis = new Vector4(m_data.HandOrientation); xAxis.Normalize(); //Because Y axis in windows UI is downward, so we should Multiply(-1) here Vector4 yAxis = new Vector4(m_data.FacingOrientation.Multiply(-1)); yAxis.Normalize(); Vector4 zAxis = yAxis.CrossProduct(xAxis); zAxis.Normalize(); Vector4 vOrigin = new Vector4(m_points[0][0]); Matrix4 result = new Matrix4(xAxis, yAxis, zAxis, vOrigin); m_MatrixZaxis = result; //get transform used to transform points to plane whose normal is Yaxis of beam xAxis = new Vector4(m_data.HandOrientation); xAxis.Normalize(); zAxis = new Vector4(m_data.FacingOrientation); zAxis.Normalize(); yAxis = (xAxis.CrossProduct(zAxis)) * (-1); yAxis.Normalize(); result = new Matrix4(xAxis, yAxis, zAxis, vOrigin); m_MatrixYaxis = result; return(m_MatrixZaxis); }
/// <summary> /// Get normal of face /// </summary> /// <param name="face">edges in a face</param> /// <returns>vector stands for normal of the face</returns> public Vector4 GetFaceNormal(List <Edge> face) { Edge eg0 = face[0]; Edge eg1 = face[1]; //get two lines from the face List <XYZ> points = eg0.Tessellate() as List <XYZ>; Autodesk.Revit.DB.XYZ start = points[0]; Autodesk.Revit.DB.XYZ end = points[1]; Vector4 vStart = new Vector4((float)start.X, (float)start.Y, (float)start.Z); Vector4 vEnd = new Vector4((float)end.X, (float)end.Y, (float)end.Z); Vector4 vSub = vEnd - vStart; points = eg1.Tessellate() as List <XYZ>; start = points[0]; end = points[1]; vStart = new Vector4((float)start.X, (float)start.Y, (float)start.Z); vEnd = new Vector4((float)end.X, (float)end.Y, (float)end.Z); Vector4 vSub2 = vEnd - vStart; //get the normal with two lines got from face Vector4 result = vSub.CrossProduct(vSub2); result.Normalize(); return(result); }
/// <summary> /// Get points of first face /// </summary> /// <param name="faces">edges in all faces</param> /// <returns>points of first face</returns> public override List <List <XYZ> > GetNeedPoints(List <List <Edge> > faces) { List <Edge> needFace = new List <Edge>(); List <List <XYZ> > needPoints = new List <List <XYZ> >(); LocationCurve location = m_data.Location as LocationCurve; Curve curve = location.Curve; List <XYZ> xyzs = curve.Tessellate() as List <XYZ>; Vector4 zAxis = new Vector4(0, 0, 1); //if Location curve of wall is line, then return first face if (xyzs.Count == 2) { needFace = faces[0]; } //else we return the face whose normal is Z axis foreach (List <Edge> face in faces) { foreach (Edge edge in face) { List <XYZ> edgexyzs = edge.Tessellate() as List <XYZ>; if (xyzs.Count == edgexyzs.Count) { //get the normal of face Vector4 normal = GetFaceNormal(face); Vector4 cross = Vector4.CrossProduct(zAxis, normal); cross.Normalize(); if (cross.Length() == 1) { needFace = face; } } } } needFace = faces[0]; //get points array in edges foreach (Edge edge in needFace) { List <XYZ> edgexyzs = edge.Tessellate() as List <XYZ>; needPoints.Add(edgexyzs); } return(needPoints); }
/// <summary> /// Get a matrix which can transform points to 2D /// </summary> /// <returns>matrix which can transform points to 2D</returns> public override Matrix4 GetTo2DMatrix() { //get the location curve LocationCurve location = m_data.Location as LocationCurve; Vector4 xAxis = new Vector4(1, 0, 0); Vector4 yAxis = new Vector4(0, 1, 0); Vector4 zAxis = new Vector4(0, 0, 1); Vector4 origin = new Vector4(0, 0, 0); if (location != null) { Curve curve = location.Curve; if (!(curve is Autodesk.Revit.DB.Line)) { throw new Exception("Opening cannot build on this Wall"); } Autodesk.Revit.DB.XYZ start = curve.GetEndPoint(0); Autodesk.Revit.DB.XYZ end = curve.GetEndPoint(1); xAxis = new Vector4((float)(end.X - start.X), (float)(end.Y - start.Y), (float)(end.Z - start.Z)); xAxis.Normalize(); //because in the windows UI, Y axis is downward yAxis = new Vector4(0, 0, -1); zAxis = Vector4.CrossProduct(xAxis, yAxis); zAxis.Normalize(); origin = new Vector4((float)(end.X + start.X) / 2, (float)(end.Y + start.Y) / 2, (float)(end.Z + start.Z) / 2); } return(new Matrix4(xAxis, yAxis, zAxis, origin)); }
/// <summary> /// Get a matrix which can transform points to 2D /// </summary> /// <returns>matrix which can transform points to 2D</returns> public override Matrix4 GetTo2DMatrix() { //get transform used to transform points to plane whose normal is Zaxis of beam Vector4 xAxis = new Vector4(m_data.HandOrientation); xAxis.Normalize(); //Because Y axis in windows UI is downward, so we should Multiply(-1) here Vector4 yAxis = new Vector4(m_data.FacingOrientation.Multiply(-1)); yAxis.Normalize(); Vector4 zAxis = yAxis.CrossProduct(xAxis); zAxis.Normalize(); Vector4 vOrigin = new Vector4(m_points[0][0]); Matrix4 result = new Matrix4(xAxis, yAxis, zAxis, vOrigin); m_MatrixZaxis = result; //get transform used to transform points to plane whose normal is Yaxis of beam xAxis = new Vector4(m_data.HandOrientation); xAxis.Normalize(); zAxis = new Vector4(m_data.FacingOrientation); zAxis.Normalize(); yAxis = (xAxis.CrossProduct(zAxis)) * (-1); yAxis.Normalize(); result = new Matrix4(xAxis, yAxis, zAxis, vOrigin); m_MatrixYaxis = result; return m_MatrixZaxis; }