c# - 提取点和边缘向量
问题描述
我正在创建一个程序来为 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。不幸的是,这会占用大量内存并且需要一些时间。
解决方案
您可以使用 或 将黄色面转换为Surface
使用Brep.Faces[i].ConvertToSurface()
和生成所得曲面的等间距参数的 U 或 V 等值Surface.IsocurveU(t)
曲线Surface.IsocurveU(t)
。
推荐阅读
- c# - 读取 /proc/stat 值以获取 cpu 使用率会引发 DivideByZeroException
- opengl - 来自物体的 Opengl 闪电
- c++ - 使用 std::function 存储继承类 c++ 的方法
- asp.net-core - 目录中的 HttpPost 文件
- javascript - 根据 URL 路径使用不同的 CSS 文件
- javascript - 在 websocket 事件中,我试图在对象的关联数组中切片一个数组,但它不起作用
- google-cloud-dataprep - Dataprep:运行作业到excel文件后数组类型无效
- r - 在 R 中转换日期
- ios - 如何在 Swift iOS 的 UITextField 中格式化粗体/斜体等文本?
- typescript - 扩展有区别的工会