Grasshopper

algorithmic modeling for Rhino

Hi all,

My goal is to retrieve the centroid of any face of my brep in my C# component.

(Ideally, I would like to retrieve the same point same computed by the area component -- Surface > area the C output). 

After searching the forum I found that AreaMassProperties is the guy I need.

I wrote a simple function like so:

private void RunScript(Brep B, ref object Surface, ref object Center)
{
List<Point3d> centers = new List<Point3d>();
foreach(BrepFace face in B.Faces) {
centers.Add(centerOf(face));
}
Center = centers;
Surface = B.Surfaces;
}

// <Custom additional code>
private Point3d centerOf(BrepFace face) {
AreaMassProperties amp = AreaMassProperties.Compute(face.ToBrep());
return amp.Centroid;
}

But it seems that the centroid returned by this way is the one of the underlying surface of my brep face.

when I display the surfaces of the brep (Brep.Surfaces property) I see that returned centroids are the center of each surface.

attached images show difference between my code and the regular Area component.

How can I compute the centroid point in order to be the same as the one given by the Area component?

Thanks in advance

Jerome

Views: 2634

Attachments:

Replies to This Discussion

You need to convert each BrepFace into a whole new Brep. I think you need BrepFace.DuplicateFace().

Indeed.

Anyway have some fun with this attached

Attachments:

Thanks for your replies.

Documentation was self explaining

BrepFace.ToBrep method: Converts the surface into a Brep.

So the result is the surface of the brep face.

As David said, BrepFace.DuplicateFace() returns a new Brep for the single face (doc says: "Duplicate a face from the brep to create new single face brep. ")

So my code becomes:

// <Custom additional code>
private Point3d centerOf(BrepFace face) {
AreaMassProperties amp = AreaMassProperties.Compute(face.DuplicateFace());
return amp.Centroid;
}

It works perfectly.

Thanks again.

Jerome

It's important to know the difference between these geometry types. Surface is a base class for several types of surface geometry, including PlaneSurface, Revolution, NurbsSurface and SumSurface. A surface never has trimming data so whenever you treat some geometry as a surface you always end up considering the entire shape.

BrepFace inherits from Surface, but it is always part of a Brep. At no point can you have an individual BrepFace. BrepFaces do have trimming data, but they require the rest of the Brep to make that work. Actually I feel now it was a mistake to make BrepFaces inherit from Surface, it has caused much confusion.

Breps are collections of all sorts of geometry. One or more BrepFaces, a bunch of edge curves, all sorts of trimming curves (both in 3D space and face UV space), loops (closed collections of edges+trims), vertices, etc.

td;dr

Surfaces are simple types. Breps are the most complex type in Rhino, they can do almost everything but they can be slow. BrepFaces inherit from Surface, but are always part of a Brep. Calling methods on a BrepFace is like calling methods on the underlying (untrimmed) surface.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service