CNC激光/等离子切割路径开发:逐点向量计算及布尔运算选型问题
点与边向量提取相关问题
- 开发场景:面向CNC机床激光/等离子切割的路径生成程序,核心需求为支持用户在基础实体上生成切割轮廓,同步提取切割轮廓对应的点位与方向向量。
- 已实现能力:可根据刀具走行要求,在选中的壁面上绘制与点位匹配的方向箭头(建立点位与切割方向的映射关系),功能基于所选壁面的法向量确定切割角度,平面类壁面上的运行效果符合加工预期。
- 现存故障:在法向量随点位动态变化的壁面(如斜圆柱的轮廓边)上,生成的所有箭头统一采用固定方向向量,完全不匹配实际加工要求。
现有实现代码
public List<Mesh> DrawArrowsOnSelectedFace(Entity entity) { List<Mesh> arrowList = new List<Mesh>(); Brep ent = (Brep)entity; for (int i = 0; i < ent.Faces.Length; i++) { if (ent.GetFaceSelection(i)) { Surface[] sf = ent.Faces[i].ConvertToSurface(ent); foreach (Surface surf in sf) { ICurve[] extractedEdges = surf.ExtractEdges(); Vector3D rotation = CalculatePerpenticularToNormalVector(surf); foreach (ICurve curve in extractedEdges) { Point3D[] segmented = curve.GetPointsByLengthPerSegment(5); for (int j = 1; j <= segmented.Length - 1; j++) { Point3D point1 = segmented[j - 1]; Mesh arrow = CreateArrow(point1, rotation); arrowList.Add(arrow); } } } } } return arrowList; } private Vector3D CalculatePerpenticularToNormalVector(Surface surface) { Point3D point3D1 = new Point3D(surface.ControlPoints[0, 0].X, surface.ControlPoints[0, 0].Y, surface.ControlPoints[0, 0].Z); Point3D point3D2 = new Point3D(surface.ControlPoints[0, 1].X, surface.ControlPoints[0, 1].Y, surface.ControlPoints[0, 1].Z); Point3D point3D3 = new Point3D(surface.ControlPoints[1, 0].X, surface.ControlPoints[1, 0].Y, surface.ControlPoints[1, 0].Z); Plane plane = new Plane(point3D1, point3D2, point3D3); Vector3D equation = new Vector3D(plane.Equation.X, plane.Equation.Y, plane.Equation.Z); Vector3D vectorZ = new Vector3D(); vectorZ.PerpendicularTo(Vector3D.AxisMinusY); Vector3D result = CalculateRotation(vectorZ, equation); result.Normalize(); return result; } private Mesh CreateArrow(Point3D point3D, Vector3D rotation) { if (point3D.Z >= -0.5) { return Mesh.CreateArrow(point3D, rotation, 0.3, 5, 0.35, 2, 36, Mesh.natureType.Smooth, Mesh.edgeStyleType.Sharp); } else return null; } private Vector3D CalculateRotation(Vector3D vector, Vector3D equation) { return vector - Vector3D.Dot(vector, equation) * equation; }
布尔运算选型相关问题
- 当前实现逻辑:基于基础实体与切割形状的公共交集区域绘制箭头,两类实体均采用Brep结构。
- 现存痛点:现有方案内存占用高、运算耗时长,需要选型适配当前切割路径生成场景的最优布尔运算实现类型,完成性能优化。
内容的提问来源于stack exchange,提问作者Reszczyk
相关产品推荐
相关产品推荐

