public static Plane getPlaneFromPosition(IfcPlacement pos) { Point3D org = getPoint3DFromIfcCartesianPoint(pos.Location); Vector3D xAxis = null, yAxis = null, zAxis = null; if (pos is IfcAxis1Placement) { throw new Exception("IfcAxis1Placement"); } else if (pos is IfcAxis2Placement2D) { IfcAxis2Placement2D pos2D = (IfcAxis2Placement2D)pos; if (pos2D.RefDirection != null) { xAxis = new Vector3D(pos2D.RefDirection.DirectionRatioX, pos2D.RefDirection.DirectionRatioY, pos2D.RefDirection.DirectionRatioZ); } else { xAxis = new Vector3D(1, 0, 0); } yAxis = Vector3D.Cross(Plane.XY.AxisZ, xAxis); } else if (pos is IfcAxis2Placement3D) { IfcAxis2Placement3D pos3D = (IfcAxis2Placement3D)pos; if (pos3D.RefDirection != null) { xAxis = new Vector3D(pos3D.RefDirection.DirectionRatioX, pos3D.RefDirection.DirectionRatioY, pos3D.RefDirection.DirectionRatioZ); } else { xAxis = new Vector3D(1, 0, 0); } if (pos3D.Axis != null) { zAxis = new Vector3D(pos3D.Axis.DirectionRatioX, pos3D.Axis.DirectionRatioY, pos3D.Axis.DirectionRatioZ); } else { zAxis = new Vector3D(0, 0, 1); } if (xAxis.IsZero) //rivedere { xAxis = new Vector3D(1, 0, 0); } yAxis = Vector3D.Cross(zAxis, xAxis); } return(new Plane(org, xAxis, yAxis)); }
/// <summary> /// Converts a placement to a Matrix3D /// </summary> /// <param name="placement"></param> /// <returns></returns> public static XbimMatrix3D ToMatrix3D(this IfcPlacement placement) { IfcAxis2Placement3D ax3 = placement as IfcAxis2Placement3D; IfcAxis2Placement2D ax2 = placement as IfcAxis2Placement2D; if (ax3 != null) { return(ax3.ToMatrix3D()); } else if (ax2 != null) { return(ax2.ToMatrix3D()); } else { return(XbimMatrix3D.Identity); } }