public EdgeInfo(TopoShape edge, int idx, int faceIdx, double length) { Curve = new GeomCurve(); Curve.Initialize(edge); Index = idx; FaceIndex = faceIdx; var start = Curve.Value(Curve.FirstParameter()); var end = Curve.Value(Curve.LastParameter()); Direction = end - start; Direction.Normalize(); Length = length; var pts = GlobalInstance.TopoExplor.ExplorVertices(edge); for (int ii = 0; ii < pts.Size(); ++ii) { GeomPoint gp = new GeomPoint(); gp.Initialize(pts.GetAt(ii)); Vertices.Add(new VertexInfo(gp.GetPoint(), ii, idx, faceIdx)); } }
private void circleToolStripMenuItem_Click(object sender, EventArgs e) { SelectedShapeQuery query = new SelectedShapeQuery(); renderView.QuerySelection(query); var shape = query.GetSubGeometry(); if (shape == null) { return; } GeomCurve curve = new GeomCurve(); if (!curve.Initialize(shape)) { return; } if (curve.GetCurveType() != EnumCurveType.CurveType_Circle) { var xx = curve.FirstParameter() + curve.LastParameter(); Vector3 pt1 = curve.Value(curve.FirstParameter()); Vector3 pt2 = curve.Value(xx * 0.3); Vector3 pt3 = curve.Value(xx * 0.6); var arc = GlobalInstance.BrepTools.MakeArc3Pts(pt1, pt3, pt2); if (arc != null) { GeomCircle circle = new GeomCircle(); circle.Initialize(arc); var center = circle.GetCenter(); MessageBox.Show(String.Format("Center: {0}, {1}, {2}", center.X, center.Y, center.Z)); } } }
public override bool Run(FeatureContext context) { LineStyle lineStyle = new LineStyle(); lineStyle.SetLineWidth(0.5f); lineStyle.SetColor(ColorValue.BLUE); lineStyle.SetLineWidth(1.5f); LineStyle lineStyle2 = new LineStyle(); lineStyle2.SetLineWidth(0.5f); lineStyle2.SetColor(ColorValue.GREEN); lineStyle2.SetLineWidth(2); TopoShape arc = GlobalInstance.BrepTools.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z); context.ShowGeometry(arc); { GeomCurve curve = new GeomCurve(); curve.Initialize(arc); double paramStart = curve.FirstParameter(); double paramEnd = curve.LastParameter(); double step = (paramEnd - paramStart) * 0.1; for (double uu = paramStart; uu <= paramEnd; uu += step) { Vector3 dir = curve.DN(uu, 1); Vector3 pos = curve.Value(uu); // 切线 { TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir); SceneNode node = context.ShowGeometry(line); node.SetLineStyle(lineStyle); } // 法线 { Vector3 dirN = dir.CrossProduct(Vector3.UNIT_Z); TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dirN); SceneNode node = context.ShowGeometry(line); node.SetLineStyle(lineStyle2); } } } return(true); }
private void curveToolStripMenuItem_Click(object sender, EventArgs e) { renderView.SetStandardView(EnumStandardView.SV_Top); Platform.LineStyle lineStyle = new Platform.LineStyle(); lineStyle.SetLineWidth(0.5f); lineStyle.SetColor(ColorValue.BLUE); Platform.LineStyle lineStyle2 = new Platform.LineStyle(); lineStyle2.SetLineWidth(0.5f); lineStyle2.SetColor(ColorValue.GREEN); Platform.TopoShape arc = GlobalInstance.BrepTools.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z); renderView.ShowGeometry(arc, 100); { GeomCurve curve = new GeomCurve(); curve.Initialize(arc); float paramStart = curve.FirstParameter(); float paramEnd = curve.LastParameter(); float step = (paramEnd - paramStart) * 0.1f; for (float uu = paramStart; uu <= paramEnd; uu += step) { Vector3 dir = curve.DN(uu, 1); Vector3 pos = curve.Value(uu); // 切线 { Platform.TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir); Platform.SceneNode node = renderView.ShowGeometry(line, 101); node.SetLineStyle(lineStyle); } // 法线 { Vector3 dirN = dir.CrossProduct(Vector3.UNIT_Z); Platform.TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dirN); Platform.SceneNode node = renderView.ShowGeometry(line, 101); node.SetLineStyle(lineStyle2); } } } TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(arc); float len = property.EdgeLength(); TextNode text = new TextNode(); text.SetText(String.Format("Arc Length: {0}", len)); text.SetPosition(new Vector3(100, 100, 0)); renderView.SceneManager.ClearNodes2d(); renderView.SceneManager.AddNode2d(text); renderView.RequestDraw(); }
private BendHelper BendDown(TopoShape face, TopoShape line, Bending bending) { #region 计算平面法向量 GeomSurface surface = new GeomSurface(); surface.Initialize(face); //参数域UV范围 double uFirst = surface.FirstUParameter(); double uLast = surface.LastUParameter(); double vFirst = surface.FirstVParameter(); double vLast = surface.LastVParameter(); //取中点 double umid = uFirst + (uLast - uFirst) * 0.5f; double vmid = vFirst + (vLast - vFirst) * 0.5f; //计算法向量 var data = surface.D1(umid, vmid); Vector3 dirU = data[1]; Vector3 dirV = data[2]; Vector3 dirF = dirV.CrossProduct(dirU); dirF.Normalize(); #endregion #region 计算边线参数 GeomCurve curve = new GeomCurve(); curve.Initialize(line); Vector3 dirL = curve.DN(curve.FirstParameter(), 1); Vector3 stPt = curve.Value(curve.FirstParameter()); //起点 Vector3 edPt = curve.Value(curve.LastParameter()); //终点 #endregion #region 绘制草图 TopoShapeGroup lineGroup = new TopoShapeGroup(); Vector3 center = stPt + dirF * bending.Radius; //圆心 Vector3 radius = stPt - center; //半径 double theta = bending.Angle * (Math.PI / 180.0); Vector3 radius2 = radius * Math.Cos(theta) + dirL.CrossProduct(radius) * Math.Sin(theta); Vector3 edArc = center + radius2; //圆弧终点 TopoShape arc = GlobalInstance.BrepTools.MakeArc(stPt, edArc, center, dirL); //绘制圆弧 if (arc != null) { lineGroup.Add(arc); } Vector3 edLine = dirL.CrossProduct(radius2) * (bending.Length / bending.Radius) + edArc; arc = GlobalInstance.BrepTools.MakeLine(edArc, edLine); lineGroup.Add(arc); //扫描生成折弯 TopoShape wireSketch = GlobalInstance.BrepTools.MakeWire(lineGroup); TopoShape sweep; if (wireSketch != null) { sweep = GlobalInstance.BrepTools.Sweep(wireSketch, line, true); } else { sweep = GlobalInstance.BrepTools.Sweep(arc, line, true); } TopoShape oFace = GlobalInstance.BrepTools.Sweep(arc, line, true).GetSubShape(0, 1); TopoShape oEdge = GlobalInstance.BrepTools.MakeLine(edLine, edLine + edPt - stPt); #endregion BendHelper bend = new BendHelper() { Sweep = sweep, EdFace = oFace, EdLine = oEdge }; return(bend); }