/// <summary> /// 求两个面的夹角 /// </summary> /// <param name="face1"></param> /// <param name="face2"></param> /// <returns></returns> public static double Angle(Face face1, Face face2) { Vector3d vec1 = FaceUtils.AskFaceNormal(face1); Vector3d vec2 = FaceUtils.AskFaceNormal(face2); return(UMathUtils.Angle(vec1, vec2)); }
/// <summary> /// 面上任意一点做射线 /// </summary> /// <param name="face"></param> /// <param name="vec"></param> /// <returns></returns> public static int AskTraceARayForFaceData(Face face, Vector3d vec) { UFSession theUFSession = UFSession.GetUFSession(); Tag[] bodyTag = { face.GetBody().Tag }; UFModl.RayHitPointInfo[] info; Point3d originPt = GetFacePoint(face); double[] origin = { originPt.X, originPt.Y, originPt.Z }; double[] dir = { vec.X, vec.Y, vec.Z }; double[] mat = new double[16]; theUFSession.Mtx4.Identity(mat); int res = 0; int count = 0; theUFSession.Modl.TraceARay(1, bodyTag, origin, dir, mat, 0, out res, out info); foreach (UFModl.RayHitPointInfo ray in info) { Point3d temp = new Point3d(ray.hit_point[0], ray.hit_point[1], ray.hit_point[2]); double dis = UMathUtils.GetDis(originPt, temp); if (ray.hit_face != face.Tag && !UMathUtils.IsEqual(dis, 0)) { int statusPt = 0; theUFSession.Modl.AskPointContainment(ray.hit_point, face.Tag, out statusPt); if (statusPt != 3) { count++; } } } return(count); }
/// <summary> /// 按点到点移动工件 /// </summary> /// <param name="startPt"></param> /// <param name="endPt"></param> /// <param name="objs"></param> /// <returns></returns> public static NXObject MoveObjectOfPointToPoint(Point3d startPt, Point3d endPt, params NXObject[] objs) { Vector3d direction = UMathUtils.GetVector(endPt, startPt); double value = UMathUtils.GetDis(startPt, endPt); Part workPart = Session.GetSession().Parts.Work; NXOpen.Features.MoveObject nullMoveObject = null; NXOpen.Features.MoveObjectBuilder moveObjectBuilder = workPart.BaseFeatures.CreateMoveObjectBuilder(nullMoveObject); bool added = moveObjectBuilder.ObjectToMoveObject.Add(objs); moveObjectBuilder.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Distance; Direction distance = workPart.Directions.CreateDirection(startPt, direction, SmartObject.UpdateOption.WithinModeling); moveObjectBuilder.TransformMotion.DistanceVector = distance; moveObjectBuilder.TransformMotion.DistanceValue.Value = value; try { return(moveObjectBuilder.Commit()); } catch (Exception ex) { LogMgr.WriteLog("Basic.MoveObject.MoveObjectOfCsys:错误:" + ex.Message); } return(null); }
/// <summary> /// 比较两面是否是求差面 /// </summary> /// <param name="other"></param> /// <returns></returns> public bool EqualsForSutract(FaceData other) { double anlge = UMathUtils.Angle(this.Dir, other.Dir); if (this.FaceType == other.FaceType && UMathUtils.IsEqual(anlge, Math.PI) && this.IntNorm == -other.IntNorm) { double[] ptOnObj1 = new double[3]; double[] ptOnObj2 = new double[3]; double minDis = AnalysisUtils.AskMinimumDist(this.Face.Tag, other.Face.Tag, out ptOnObj1, out ptOnObj2); Point3d pt1 = new Point3d(ptOnObj1[0], ptOnObj1[1], ptOnObj1[2]); Point3d pt2 = new Point3d(ptOnObj2[0], ptOnObj2[1], ptOnObj2[2]); List <Edge> edges1 = GetPointOnEdge(this.Face, ptOnObj1); List <Edge> edges2 = GetPointOnEdge(other.Face, ptOnObj2); bool edgeBool = false; if (edges1.Count > 0 && edges2.Count > 0) { foreach (Edge ed in edges1) { foreach (Edge ed1 in edges2) { if (ed.Tag == ed1.Tag) { edgeBool = true; } } } } if (UMathUtils.IsEqual(minDis, 0) && UMathUtils.IsEqual(pt1, pt2) && !edgeBool) { return(true); } } return(false); }
/// <summary> /// 求曲面斜率 /// </summary> /// <param name="sweptFace"></param> /// <param name="vec"></param> /// <param name="slope"></param> /// <param name="rad"></param> public static void GetSweptSlope(Face sweptFace, Vector3d vec, out double[] slope, out double[] rad) { rad = new double[2] { 99999, -99999 }; slope = new double[2] { 99999, -99999 }; double faceArae = GetFaceArea(sweptFace); int accuracy = Convert.ToInt32(faceArae) * 100; UFSession theUFSession = UFSession.GetUFSession(); Tag faceTag = sweptFace.Tag; //输入面特征 double[] uvs = new double[4]; theUFSession.Modl.AskFaceUvMinmax(faceTag, uvs); //获得面u,v参数空间(u,v最小,最大值) double[] param = new double[2]; //输入U,V方向值 for (int i = 0; i < accuracy; i++) { param[0] = i * (uvs[1] - uvs[0]) / accuracy + uvs[0]; param[1] = i * (uvs[3] - uvs[2]) / accuracy + uvs[2]; double[] point = new double[3]; //输出点坐标 double[] u1 = new double[3]; //输出 输出一阶导数在U位置 double[] v1 = new double[3]; //输出 输出一阶导数在V位置 double[] u2 = new double[3]; //输出 输出二阶导数在U位置 double[] v2 = new double[3]; //输出 输出二阶导数在V位置 double[] unit_norm = new double[3]; //输出面上该点的矢量方向 double[] radii = new double[2]; //输出,双半径,输出主曲率半径 theUFSession.Modl.AskFaceProps(sweptFace.Tag, param, point, u1, v1, u2, v2, unit_norm, radii); double angle = UMathUtils.Angle(vec, new Vector3d(unit_norm[0], unit_norm[1], unit_norm[2])); if (slope[0] >= angle) { slope[0] = angle; } if (slope[1] < angle) { slope[1] = angle; } if (rad[0] >= radii[0]) { rad[0] = radii[0]; } if (rad[1] < radii[1]) { rad[1] = radii[1]; } } }
public int CompareTo(ArcEdgeData other) { if (UMathUtils.Equals(this.Center.Z, other.Center.Z)) { if (this.Radius > other.Radius) { return(-1); } else { return(1); } } else if (this.Center.Z > other.Center.Z) { return(1); } return(-1); }
public static ArcEdgeData GetArcData(Edge edge, ref string errorMsg) { if (edge.SolidEdgeType != Edge.EdgeType.Circular) { errorMsg = errorMsg + "该边不是圆弧"; return(null); } NXOpen.UF.UFSession theUfSession = NXOpen.UF.UFSession.GetUFSession(); IntPtr eval; theUfSession.Eval.Initialize(edge.Tag, out eval); NXOpen.UF.UFEval.Arc arc; try { theUfSession.Eval.AskArc(eval, out arc); ArcEdgeData arcData = new ArcEdgeData(edge); arcData.Center = new Point3d(arc.center[0], arc.center[1], arc.center[2]); arcData.Radius = arc.radius; arcData.IsWholeCircle = UMathUtils.IsEqual(Math.PI * 2, Math.Abs(arc.limits[1] - arc.limits[0])); arcData.Angle = Math.Abs(arc.limits[1] - arc.limits[0]); return(arcData); } catch (Exception ex) { errorMsg += ex.Message; LogMgr.WriteLog("EdgeUtils:GetArcData1:" + edge.Tag.ToString() + ex.Message); throw ex; } finally { theUfSession.Eval.Free(eval); } }