1

I am creating a program to generate a path for a CNC machine laser/plasma cutting. In it, the user should be able to cut shapes in the base element and be able to acquire the points and vectors of those cuts. I added the possibility to draw arrows (points and vectors) on selected walls according to which the tool should travel. This is based on obtaining the normal vector of the selected wall, which is used to determine the angle of cut.

Looks like this

Unfortunately, I do not know how to get the same effect on walls with a variable normal vector. An example of such an edge is the inclined cylinder. When I apply arrows to such an edge they all have the same vector.

It shouldn't look like this

Code sample:

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;
    }

What type should I best use for Boolean operations? I also have a part of the code prepared where the arrows are drawn based on the common part of the basic element and the cut shape. Both of these shapes are BREPs. Unfortunately, this uses a lot of memory and takes some time.

Connor Low
  • 5,900
  • 3
  • 31
  • 52
Reszczyk
  • 11
  • 2
  • What is inside `CreateArrow()` and `CalculatePerpenticularToNormalVector()`? Also it seems you need to calculate the normal vector for each segment of the curve, not just one for each face. – John Alexiou Apr 13 '21 at 12:10
  • I added the missing code to the main post. The problem is that I don't know how to extract the normal vector for any point on the edge. – Reszczyk Apr 13 '21 at 12:32
  • Welcome to SO. I suggest splitting this question into two posts since you actually have two questions here. – Connor Low Apr 13 '21 at 14:25
  • @Reszczyk. Not sure if it is an option but Breps always seem much more computationally and memory expensive. I have had much better luck with Boolean operations on Solid type instead. – Daniel Lord Apr 13 '21 at 14:52

1 Answers1

0

You can convert the yellow face to a Surface using Brep.Faces[i].ConvertToSurface() and generating U or V isocurves of the resulting surface at equally spaced parameters using Surface.IsocurveU(t) or Surface.IsocurveU(t).

abenci
  • 8,422
  • 19
  • 69
  • 134