🌶️ Creating a BRep entity from scratch

In this article, we create a BRep entity by defining its vertices, edges, faces and shells.

const double radius = 10, height = 20, centreToCentre = 20, offset = 3;

Point3D[] vertices = new Brep.Vertex[8];

vertices[0] = new Brep.Vertex(0, -radius);
vertices[1] = new Brep.Vertex(centreToCentre, -radius);
vertices[2] = new Brep.Vertex(centreToCentre, +radius);
vertices[3] = new Brep.Vertex(0, +radius);
vertices[4] = new Brep.Vertex(0, -radius, height);
vertices[5] = new Brep.Vertex(0, +radius, height);

Brep.Edge[] edges = new Brep.Edge[13];

// Base oval profile
Line l1 = new Line((Point3D)vertices[0].Clone(), (Point3D)vertices[1].Clone());
edges[0] = new Brep.Edge(l1, 0, 1);

Arc a1 = new Arc(new Point3D(centreToCentre, 0), radius, devDept.Geometry.Utility.DegToRad(270), devDept.Geometry.Utility.DegToRad(360 + 90));
edges[1] = new Brep.Edge(a1, 1, 2);

Line l2 = new Line((Point3D)vertices[2].Clone(), (Point3D)vertices[3].Clone());
edges[2] = new Brep.Edge(l2, 2, 3);

Arc a2 = new Arc(new Point3D(0, 0), radius, devDept.Geometry.Utility.DegToRad(90), devDept.Geometry.Utility.DegToRad(270));
edges[3] = new Brep.Edge(a2, 3, 0);

// Front face
Line l3 = new Line((Point3D)vertices[0].Clone(), (Point3D)vertices[4].Clone());
edges[4] = new Brep.Edge(l3, 0, 4);

Line l4 = new Line((Point3D)vertices[1].Clone(), (Point3D)vertices[4].Clone());
edges[5] = new Brep.Edge(l4, 1, 4);

// Rear face
Line l5 = new Line((Point3D)vertices[2].Clone(), (Point3D)vertices[5].Clone());
edges[6] = new Brep.Edge(l5, 2, 5);

Line l6 = new Line((Point3D)vertices[3].Clone(), (Point3D)vertices[5].Clone());
edges[7] = new Brep.Edge(l6, 3, 5);

// Top circular profile
Arc a3 = new Arc(new Point3D(0, 0, height), radius, devDept.Geometry.Utility.DegToRad(90), devDept.Geometry.Utility.DegToRad(270));
edges[8] = new Brep.Edge(a3, 5, 4);

Arc a4 = new Arc(new Point3D(0, 0, height), radius, devDept.Geometry.Utility.DegToRad(270), devDept.Geometry.Utility.DegToRad(360 + 90));
edges[9] = new Brep.Edge(a4, 4, 5);

Brep.OrientedEdge[] bottomLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(0),
    new Brep.OrientedEdge(1),
    new Brep.OrientedEdge(2),
    new Brep.OrientedEdge(3)
};

Brep.OrientedEdge[] rightLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(1),
    new Brep.OrientedEdge(6),
    new Brep.OrientedEdge(9, false),
    new Brep.OrientedEdge(5, false)
};

Brep.OrientedEdge[] rearLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(2, false),
    new Brep.OrientedEdge(6),
    new Brep.OrientedEdge(7, false)
};

Brep.OrientedEdge[] leftLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(3),
    new Brep.OrientedEdge(4),
    new Brep.OrientedEdge(8, false),
    new Brep.OrientedEdge(7, false)
};

Brep.OrientedEdge[] frontLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(0),
    new Brep.OrientedEdge(5),
    new Brep.OrientedEdge(4, false)
};

Brep.OrientedEdge[] topLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(9),
    new Brep.OrientedEdge(8)
};

PlanarSurf bottom = new PlanarSurf(vertices[0], Vector3D.AxisZ, Vector3D.AxisX);
TabulatedSurf right = new TabulatedSurf((ICurve)a1.Clone(), new Vector3D(l4.StartPoint, l4.EndPoint));
PlanarSurf rear = new PlanarSurf(vertices[3], Vector3D.AxisY, Vector3D.AxisX);
CylindricalSurf left = new CylindricalSurf(Point3D.Origin, Vector3D.AxisZ, Vector3D.AxisX, radius);
PlanarSurf front = new PlanarSurf(vertices[0], Vector3D.AxisY, Vector3D.AxisX);
PlanarSurf top = new PlanarSurf(vertices[4], Vector3D.AxisZ, Vector3D.AxisX);

Brep.Face[] faces = new Brep.Face[]
{
    new Brep.Face(bottom, new Brep.Loop(bottomLoop, false), false),
    new Brep.Face(right, new Brep.Loop(rightLoop), true),
    new Brep.Face(rear, new Brep.Loop(rearLoop, false), true),
    new Brep.Face(left, new Brep.Loop(leftLoop), true),
    new Brep.Face(front, new Brep.Loop(frontLoop), false),
    new Brep.Face(top, new Brep.Loop(topLoop), true)
};

// Inner void
vertices[6] = new Brep.Vertex(radius - offset, 0, offset);
vertices[7] = new Brep.Vertex(radius - offset, 0, height - offset);

Circle c1 = new Circle(new Point3D(0, 0, offset), radius - offset);
edges[10] = new Brep.Edge(c1, 6, 6);

Circle c2 = new Circle(new Point3D(0, 0, height - offset), radius - offset);
edges[11] = new Brep.Edge(c2, 7, 7);

Line l7 = new Line((Point3D)vertices[6].Clone(), (Point3D)vertices[7].Clone());
edges[12] = new Brep.Edge(l7, 6, 7);

// Data for standard cylinder reversed down below
Brep.OrientedEdge[] voidBottomLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(10, false)
};

Brep.OrientedEdge[] voidSideLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(10), // bottom circle
    new Brep.OrientedEdge(12), // upward line
    new Brep.OrientedEdge(11, false), // reversed top circle
    new Brep.OrientedEdge(12, false)  // reversed upward line
};

Brep.OrientedEdge[] voidTopLoop = new Brep.OrientedEdge[]
{
    new Brep.OrientedEdge(11)
};

PlanarSurf voidBottom = new PlanarSurf(vertices[6], Vector3D.AxisZ, Vector3D.AxisX);
CylindricalSurf voidSide = new CylindricalSurf((Point3D) c1.Center.Clone(), Vector3D.AxisZ, Vector3D.AxisX, radius - offset);
PlanarSurf voidTop = new PlanarSurf(vertices[7], Vector3D.AxisZ, Vector3D.AxisX);

// Reversed face and loop because we need a void
Brep.Face[] innerVoid = new Brep.Face[]
{
    new Brep.Face(voidBottom, new Brep.Loop(voidBottomLoop, false)),
    new Brep.Face(voidSide, new Brep.Loop(voidSideLoop, false), false),
    new Brep.Face(voidTop, new Brep.Loop(voidTopLoop, false), false)
};

Brep wedge = new Brep(vertices, edges, faces, new Brep.Face[][] { innerVoid });

design.Entities.Add(wedge, Color.MediumVioletRed);
Was this article helpful?
1 out of 1 found this helpful

Comments

2 comments
Date Votes
  • Hi Alberto.
    What exactly is the "Sense" field you use in both the Brep.Loop and Brep.Face constructors? Unfortunately there is limited description in the documentation.

    0
  • Hello Eyüp,

    Curves and surfaces have a natural direction/orientation, with sense = false you request the opposite direction/orientation.

    0

Please sign in to leave a comment.

Articles in this section

See more