public override void GetSlopeAndDia(Vector3d vec, out double[] slope, out double[] dia) { slope = new double[2]; dia = new double[2]; slope[0] = slope[1] = UMathUtils.Angle(vec, Data.Dir); dia[0] = dia[1] = 0; }
protected bool IsPassThrough(AbstractCylinderBody ab, double start, double end) { double anlge = UMathUtils.Angle(analysis.Matr.GetZAxis(), ab.Direction); Point3d startPt = ab.StratPt; Point3d endPt = ab.EndPt; this.analysis.Matr.ApplyPos(ref startPt); this.analysis.Matr.ApplyPos(ref endPt); if (UMathUtils.IsEqual(anlge, 0)) { if (startPt.Z > start && endPt.Z < end) { return(true); } } if (UMathUtils.IsEqual(anlge, Math.PI)) { if (startPt.Z < start && endPt.Z > end) { return(true); } } return(false); }
public override void SetDimForFace(ref LinearDimension ld, Vector3d vec) { foreach (Face face in this.ToolingBox.GetBodies()[0].GetFaces()) { if (face.SolidFaceType == Face.FaceType.Cylindrical) { Point3d originPt = new Point3d(0, 0, 0); Vector3d normal = new Vector3d(0, 0, 0); FaceUtils.AskFaceOriginAndNormal(face, out originPt, out normal); double angle1 = UMathUtils.Angle(vec, new Vector3d(1, 1, 1)); if (UMathUtils.IsEqual(angle1, 0)) { ld.HandleOrientation = normal; ld.HandleOrigin = originPt; } } else { FaceData fd = FaceUtils.AskFaceData(face); Vector3d temp = fd.Dir; this.Matr.ApplyVec(ref temp); double angle = UMathUtils.Angle(vec, temp); if (UMathUtils.IsEqual(angle, 0)) { ld.HandleOrientation = fd.Dir; ld.HandleOrigin = fd.Point; } } } }
/// <summary> /// 设置圆柱的属性点 /// </summary> private void GetFacePoint() { Part workPart = Session.GetSession().Parts.Work; Matrix3x3 mat3 = workPart.WCS.CoordinateSystem.Orientation.Element; Point3d centerPt = new Point3d(); Point3d disPt = new Point3d(); Point3d start = new Point3d(); Point3d end = new Point3d(); Matrix4 inve = this.Matr.GetInversMatrix(); double angleX = UMathUtils.Angle(this.Direction, new Vector3d(mat3.Xx, mat3.Xy, mat3.Xz)); double angleY = UMathUtils.Angle(this.Direction, new Vector3d(mat3.Yx, mat3.Yy, mat3.Yz)); double angleZ = UMathUtils.Angle(this.Direction, new Vector3d(mat3.Zx, mat3.Zy, mat3.Zz)); if ((UMathUtils.IsEqual(angleX, 0) || UMathUtils.IsEqual(angleX, Math.PI)) || (UMathUtils.IsEqual(angleY, 0) || UMathUtils.IsEqual(angleY, Math.PI)) || (UMathUtils.IsEqual(angleZ, 0) || UMathUtils.IsEqual(angleZ, Math.PI))) { this.GetCenterAndDisForData(out centerPt, out disPt); } else { this.GetFaceBoundingBox(out centerPt, out disPt); } start.Z = centerPt.Z - disPt.Z; end.Z = centerPt.Z + disPt.Z; inve.ApplyPos(ref centerPt); inve.ApplyPos(ref start); inve.ApplyPos(ref end); this.CenterPt = centerPt; this.StartPt = start; this.EndPt = end; this.Length = disPt.Z * 2; }
/// <summary> /// 判断是否是一个孔 /// </summary> /// <param name="other"></param> /// <returns></returns> public bool IsTheSameHole(AbstractCircleFace other) { double angle = UMathUtils.Angle(this.Data.Dir, other.Data.Dir); if (UMathUtils.IsEqual(angle, 0) == false && UMathUtils.IsEqual(angle, Math.PI) == false) { return(false); } Vector3d vec1 = new Vector3d(); Vector3d vec2 = new Vector3d(); if (UMathUtils.IsEqual(this.CenterPt, other.CenterPt)) { vec1 = this.Data.Dir; vec2 = new Vector3d(-vec1.X, -vec1.Y, -vec1.Z); } else { vec1 = UMathUtils.GetVector(this.CenterPt, other.CenterPt); vec2 = UMathUtils.GetVector(other.CenterPt, this.CenterPt); } angle = UMathUtils.Angle(this.Data.Dir, vec1); if (UMathUtils.IsEqual(angle, 0) == false && UMathUtils.IsEqual(angle, Math.PI) == false) { return(false); } if (TraceARay.AskTraceARay(this.Data.Face.GetBody(), this.CenterPt, vec1) > 1 && TraceARay.AskTraceARay(other.Data.Face.GetBody(), other.CenterPt, vec2) > 1) { return(false); } return(true); }
public override List <StandardPartsName> GetGuidePillar() { List <MoldBaseModel> dowFace = this.FaceEiectorPlates.FindAll(a => a.CenterPt.Z < 0); List <MoldBaseModel> dow = this.DowEiectorPlates.FindAll(a => a.CenterPt.Z < 0); List <AbstractCylinderBody> pillars = new List <AbstractCylinderBody>(); List <AbstractCylinderBody> pillar = this.cylinderBody.FindAll(a => a.Radius >= 7 && a.IsGuidePillar()); foreach (AbstractCylinderBody ab in pin) { AbstractCylinderBody pi = pillar.Find(a => UMathUtils.IsEqual(a.StratPt.X, ab.StratPt.X) && UMathUtils.IsEqual(a.StratPt.Y, ab.StratPt.Y)); //if (!pillars.Exists(a => a.Equals(pi))) //{ // pillars.Add(pi); //} if (pi != null) { pi.Name = "导柱"; pillars.Add(pi); pillar.Remove(pi); } } if (this.SupportPlate != null && dowFace.Count != 0 && dow.Count != 0) { foreach (AbstractCylinderBody ab in pillar) { Point3d start = ab.StratPt; Point3d end = ab.EndPt; this.analysis.Matr.ApplyPos(ref start); this.analysis.Matr.ApplyPos(ref end); Vector3d vec = UMathUtils.GetVector(this.DowEiectorPlates[0].CenterPt, this.SupportPlate.CenterPt); if (UMathUtils.IsEqual(UMathUtils.Angle(vec, ab.Direction), 0) && UMathUtils.IsEqual(start.Z, dow[0].CenterPt.Z + dow[0].DisPt.Z) && end.Z > this.SupportPlate.CenterPt.Z - this.SupportPlate.DisPt.Z) { ab.Name = "回针"; pillars.Add(ab); } } } else if (this.SupportPlate == null && dowFace.Count != 0 && dow.Count != 0) { foreach (AbstractCylinderBody ab in pillar) { Point3d start = ab.StratPt; Point3d end = ab.EndPt; this.analysis.Matr.ApplyPos(ref start); this.analysis.Matr.ApplyPos(ref end); Vector3d vec = UMathUtils.GetVector(this.DowEiectorPlates[0].CenterPt, this.BMoldBase.CenterPt); if (UMathUtils.IsEqual(UMathUtils.Angle(vec, ab.Direction), 0) && UMathUtils.IsEqual(start.Z, dow[0].CenterPt.Z + dow[0].DisPt.Z) && end.Z > this.BMoldBase.CenterPt.Z - this.BMoldBase.DisPt.Z) { ab.Name = "回针"; pillars.Add(ab); } } } return(GetCyliderName(pillars)); }
/// <summary> /// 分析面 /// </summary> /// <param name="vec"></param> public void AnalyzeFace(Vector3d vec) { this.FaceData = FaceUtils.AskFaceData(this.face); this.ResultsNum = TraceARay.AskTraceARayForFaceData(face, vec); this.Vec = vec; if (this.face.SolidFaceType == Face.FaceType.Planar) //平面 { this.MaxRadius = 0; this.MinRadius = 0; double angle = Math.Round(UMathUtils.Angle(vec, this.FaceData.Dir), 3); this.MaxSlope = angle; this.MinSlope = angle; return; } if (this.face.SolidFaceType == Face.FaceType.Cylindrical) { this.MaxRadius = Math.Round(this.FaceData.Radius, 3) * this.FaceData.IntNorm; this.MinRadius = Math.Round(this.FaceData.Radius, 3) * this.FaceData.IntNorm; AskFace(vec); return; } if (this.face.SolidFaceType == Face.FaceType.Conical) { this.MaxRadius = Math.Round(this.FaceData.Radius, 3) * this.FaceData.IntNorm; this.MinRadius = Math.Round(this.FaceData.RadData, 3) * this.FaceData.IntNorm; AskFace(vec); return; } else { double[] slope; double[] rad; FaceUtils.GetSweptSlope(this.face, vec, out slope, out rad); foreach (double temp in slope) { if (this.MaxSlope > temp) { this.MaxSlope = Math.Round(temp, 3); } if (this.MinSlope < temp) { this.MinSlope = Math.Round(temp, 3); } } foreach (double temp in rad) { if (this.MaxRadius > temp) { this.MaxRadius = Math.Round(temp, 3); } if (this.MinRadius < temp) { this.MinRadius = Math.Round(temp, 3); } } } }
public override void SetDimForFace(ref LinearDimension ld, Vector3d vec) { foreach (Face face in this.ToolingBox.GetBodies()[0].GetFaces()) { FaceData fd = FaceUtils.AskFaceData(face); Vector3d temp = fd.Dir; this.Matr.ApplyVec(ref temp); double angle = UMathUtils.Angle(vec, temp); if (UMathUtils.IsEqual(angle, 0)) { ld.HandleOrientation = fd.Dir; ld.HandleOrigin = fd.Point; } } }
/// <summary> /// 获取(圆锥,R面,球面)最大最小斜率 /// </summary> /// <param name="vec"></param> private void AskFace(Vector3d vec) { Vector3d[] vecs = FaceUtils.AskFaceNormals(this.face); foreach (Vector3d temp in vecs) { double angle = Math.Round(UMathUtils.Angle(vec, temp), 3); if (this.MaxSlope <= angle) { this.MaxSlope = angle; } if (this.MinSlope >= angle) { this.MinSlope = angle; } } }
/// <summary> /// 设置PICH控件显示 /// </summary> private void SetPichContrShow() { double anleX = UMathUtils.Angle(this.model.Work.Matr.GetXAxis(), this.model.Vec); double anleY = UMathUtils.Angle(this.model.Work.Matr.GetYAxis(), this.model.Vec); if (UMathUtils.IsEqual(anleX, 0) || UMathUtils.IsEqual(anleX, Math.PI)) { this.textBox_pitchX.Enabled = false; this.textBox_pitchXNum.Enabled = false; } if (UMathUtils.IsEqual(anleY, 0) || UMathUtils.IsEqual(anleY, Math.PI)) { this.textBox_pitchY.Enabled = false; this.textBox_pitchYNum.Enabled = false; } }
public override void GetSlopeAndDia(Vector3d vec, out double[] slope, out double[] dia) { slope = new double[2]; dia = new double[2]; double anlge = UMathUtils.Angle(vec, Data.Dir); dia[0] = dia[1] = 2 * Data.Radius; if (UMathUtils.IsEqual(anlge, 0) || UMathUtils.IsEqual(anlge, Math.PI)) { slope[0] = slope[1] = Math.PI / 2; } else { double[] rid; FaceUtils.GetSweptSlope(this.Data.Face, vec, out slope, out rid); } }
/// <summary> /// 圆形凸台 /// </summary> /// <param name="other"></param> /// <returns></returns> public bool IsCircleStep(AbstractCircleFace other) { double angle = UMathUtils.Angle(this.Data.Dir, other.Data.Dir); if (UMathUtils.IsEqual(angle, 0) == false && UMathUtils.IsEqual(angle, Math.PI) == false) { return(false); } Vector3d vec1 = UMathUtils.GetVector(this.CenterPt, other.CenterPt); angle = UMathUtils.Angle(this.Data.Dir, vec1); if (UMathUtils.IsEqual(angle, 0) == false && UMathUtils.IsEqual(angle, Math.PI) == false) { return(false); } return(true); }
/// <summary> /// 获得基准面 /// </summary> /// <returns></returns> private FaceData GetDatumFace() { string er = AttributeUtils.GetAttrForString(analysisBody.AnaFaces[1].Face, "DatumFace"); if (er.Equals("Datum", StringComparison.CurrentCultureIgnoreCase)) { return(analysisBody.AnaFaces[1].Data); } foreach (AnalysisFaceSlopeAndDia fe in analysisBody.AnaFaces) { string da = AttributeUtils.GetAttrForString(fe.Face, "DatumFace"); if (da.Equals("Datum", StringComparison.CurrentCultureIgnoreCase)) { return(fe.Data); } } FaceLoopUtils.LoopList[] loops = FaceLoopUtils.AskFaceLoops(analysisBody.AnaFaces[0].Face.Tag); foreach (FaceLoopUtils.LoopList lt in FaceLoopUtils.AskFaceLoops(analysisBody.AnaFaces[0].Face.Tag)) //找到竖直面 { if (lt.Type == 2) { Edge edg = NXObjectManager.Get(lt.EdgeList[0]) as Edge; foreach (Face fe in edg.GetFaces()) { if (!fe.Equals(analysisBody.AnaFaces[0].Face)) { foreach (Edge eg in fe.GetEdges()) { foreach (Face fc in eg.GetFaces()) { FaceData fd = FaceUtils.AskFaceData(fc); double angle = UMathUtils.Angle(fd.Dir, new Vector3d(0, 0, 1)); if (UMathUtils.IsEqual(angle, 0)) { return(fd); } } } } } } } return(null); }
/// <summary> /// 获取模板和圆柱形 /// </summary> /// <returns></returns> public void GetBase(out List <MoldBaseModel> moldBase, out List <AbstractCylinderBody> cylinder) { moldBase = new List <MoldBaseModel>(); cylinder = new List <AbstractCylinderBody>(); foreach (Body by in workPart.Bodies) { MoldBaseModel mm = new MoldBaseModel(by, this.Matr, csys); if ((UMathUtils.IsEqual(mm.CenterPt.X, 0) && UMathUtils.IsEqual(mm.CenterPt.Y, 0)) && ((Math.Round(mm.DisPt.X, 4) >= Math.Round(AMoldBase.DisPt.X, 4) && Math.Round(mm.DisPt.Y, 4) >= Math.Round(AMoldBase.DisPt.Y, 4)))) { moldBase.Add(mm); } else { StepBuilder builder; if (mm.DisPt.Z > mm.DisPt.X && mm.DisPt.Z > mm.DisPt.Y) { BodyCircleFeater bf = new BodyCircleFeater(by); if (bf.IsCylinderBody(out builder)) { AbstractCylinderBody ab = CylinderBodyFactory.Create(builder); if (ab != null) { double angle = UMathUtils.Angle(ab.Direction, this.Matr.GetZAxis()); if (UMathUtils.IsEqual(angle, 0) || UMathUtils.IsEqual(angle, Math.PI)) { cylinder.Add(ab); } } } } else if ((UMathUtils.IsEqual(mm.CenterPt.X, 0) || UMathUtils.IsEqual(mm.CenterPt.Y, 0)) && ((Math.Round(mm.DisPt.X, 4) >= Math.Round(AMoldBase.DisPt.X, 4) || Math.Round(mm.DisPt.Y, 4) >= Math.Round(AMoldBase.DisPt.Y, 4)))) { moldBase.Add(mm); } } } }
public override void GetSlopeAndDia(Vector3d vec, out double[] slope, out double[] dia) { slope = new double[2] { 99999, -99999 }; dia = new double[2] { 99999, -99999 }; double anlge = UMathUtils.Angle(vec, Data.Dir); if (UMathUtils.IsEqual(anlge, 0) || UMathUtils.IsEqual(anlge, Math.PI)) { slope[0] = slope[1] = UMathUtils.Angle(vec, FaceUtils.AskFaceNormal(this.Data.Face)); foreach (Edge edge in this.Data.Face.GetEdges()) { if (edge.SolidEdgeType == Edge.EdgeType.Circular) { double radius = EdgeUtils.GetArcRadius(edge); if (2 * radius > dia[1]) { dia[1] = 2 * radius; } if (2 * radius < dia[0]) { dia[0] = 2 * radius; } } } if (dia[0] == 99999) { dia[0] = 0; } } else { double[] rid; FaceUtils.GetSweptSlope(this.Data.Face, vec, out slope, out rid); dia[0] = 2 * rid[0]; dia[1] = 2 * rid[1]; } }
public bool Equals(AbstractHoleFeater other) { double angle = UMathUtils.Angle(this.Direction, other.Direction); if (this.Type == other.Type && this.ToString().Equals(other.ToString(), StringComparison.CurrentCultureIgnoreCase) && UMathUtils.IsEqual(angle, 0)) { Matrix4 mat = new Matrix4(); mat.Identity(); mat.TransformToZAxis(this.StratPt, this.Direction); Point3d strat = this.StratPt; Point3d otherStrat = other.StratPt; mat.ApplyPos(ref strat); mat.ApplyPos(ref otherStrat); if (UMathUtils.IsEqual(strat.Z, otherStrat.Z)) { return(true); } } return(false); }
/// <summary> /// 设置轴线方向相反 /// </summary> /// <param name="dir"></param> public void SetReverseDirection(Vector3d dir) { double angle = UMathUtils.Angle(this.dir, dir); if (UMathUtils.IsEqual(angle, 0)) { return; } else if (UMathUtils.IsEqual(angle, Math.PI)) { this.dir = dir; this.matr.TransformToZAxis(this.CenterPt, dir); Point3d temp = this.StartPt; this.StartPt = this.EndPt; this.EndPt = temp; } else { LogMgr.WriteLog("面反向错误!"); } }
/// <summary> /// 获取电极矩阵 /// </summary> /// <returns></returns> public Matrix4 GetEleMatr() { double anle = UMathUtils.Angle(this.conditionModel.Work.WorkMatr.GetZAxis(), this.conditionModel.Vec); Matrix4 mat; if (UMathUtils.IsEqual(anle, 0)) { mat = new Matrix4(this.conditionModel.Work.WorkMatr); mat.RolateWithX(Math.PI); return(mat); } else { UVector zVec = new UVector(-this.conditionModel.Vec.X, -this.conditionModel.Vec.Y, -this.conditionModel.Vec.Z); UVector xVec = new UVector(); UVector yVec = new UVector(); Matrix4 inver = this.conditionModel.Work.WorkMatr.GetInversMatrix(); UVector orinig = new UVector(CenterPt.X, CenterPt.Y, CenterPt.Z); inver.ApplyPos(ref orinig); double anle1 = UMathUtils.Angle(this.conditionModel.Work.WorkMatr.GetXAxis(), this.conditionModel.Vec); if (UMathUtils.IsEqual(anle1, 0) || UMathUtils.IsEqual(anle1, Math.PI)) { this.conditionModel.Work.WorkMatr.GetYAxis(ref yVec); xVec = yVec ^ zVec; } else { this.conditionModel.Work.WorkMatr.GetXAxis(ref xVec); yVec = xVec ^ zVec; } mat = new Matrix4(); mat.Identity(); mat.TransformToZAxis(orinig, xVec, yVec); return(mat); } }
/// <summary> /// 获取螺栓 /// </summary> /// <returns></returns> public List <AbstractCylinderBody> GetBolt(List <AbstractCylinderBody> cylinder, MoldBaseModel other) { Vector3d vec = UMathUtils.GetVector(new Point3d(0, 0, this.CenterPt.Z), new Point3d(0, 0, other.CenterPt.Z)); List <AbstractCylinderBody> temp = cylinder.FindAll(a => UMathUtils.IsEqual(UMathUtils.Angle(vec, a.Direction), 0)); List <AbstractCylinderBody> bolt = new List <AbstractCylinderBody>(); foreach (AbstractCylinderBody ab in temp) { Point3d start = ab.StratPt; Point3d end = ab.EndPt; this.matr.ApplyPos(ref start); this.matr.ApplyPos(ref end); if ((start.Z > this.CenterPt.Z - this.DisPt.Z && start.Z < this.CenterPt.Z + this.DisPt.Z) && (end.Z > other.CenterPt.Z - other.DisPt.Z && end.Z <= other.CenterPt.Z + other.DisPt.Z)) { // ab.Name = "M" + Math.Ceiling(ab.Radius * 2).ToString(); ab.Name = "螺丝"; bolt.Add(ab); continue; } } return(bolt); }
/// <summary> ///检查体 /// </summary> /// <returns></returns> public BodyInfo GetBodyInfoForInterference(bool extract, out List <string> err) { err = new List <string>(); List <Face> dischargeFace = new List <Face>(); List <Face> temp = new List <Face>(); List <Body> bodys = new List <Body>(); try { AnalysisUtils.SetInterferenceOutFace(this.eleBody, this.toolBody, out temp, out bodys); } catch (NXException ex) { err.Add("干涉检查错误!" + ex.Message); } if (bodys.Count > 0) { LayerUtils.MoveDisplayableObject(252, bodys.ToArray()); if (extract) { this.eleBody.Color = 186; } err.Add("电极头有过切,请检查!"); } dischargeFace = temp.Where(a => a.GetBody().Equals((this.eleBody))).Distinct().ToList(); //过滤电极面 List <Face> tt = temp.Where(a => a.GetBody().Equals((this.toolBody))).Distinct().ToList(); List <Face> faces = new List <Face>(); foreach (Face fe in dischargeFace) { FaceData data1 = FaceUtils.AskFaceData(fe); foreach (Face fa in tt) { FaceData fd = FaceUtils.AskFaceData(fa); if (UMathUtils.SelfDis(data1.Dir) == 0) { if (data1.FaceType == fd.FaceType && data1.IntNorm == -fd.IntNorm) { faces.Add(fe); break; } } else { double anlge = UMathUtils.Angle(data1.Dir, fd.Dir); if (data1.FaceType == fd.FaceType && data1.IntNorm == -fd.IntNorm && UMathUtils.IsEqual(anlge, Math.PI)) { faces.Add(fe); break; } } } } if (extract) { ExtractFace(this.toolBody, faces.ToArray()); } BodyInfo info = new BodyInfo(eleBody, faces); info.SetAttribute(csys, matr); return(info); }