algorithmic modeling for Rhino
Hello,
I've been trying to use IsPlanar to test for planarity in a duplicated brep face but am having trouble implementing it. The SDK description at Rhino common is too abstract for me (as a beginner) can anyone assist with some sample code?
Note: A related topic here: http://www.grasshopper3d.com/forum/topics/brep-face-to-surface-c
Tags:
BrepFace face = don't know where this comes from, but you have a BrepFace somewhere;
bool planar = face.IsPlanar(1e-3);
Planarity ideally uses a tolerance to determine whether or not a face really is planar. It is entirely possible that a transformed nurbs surface gains a tiny amount of noise, which would mean it is technically no longer planar, even though the deviation would be 100 times smaller than the planck length. You should decide what tolerance makes sense for your algorithm.
Note that the IsPlanar method is inherited by the BrepFace class from the Surface class. It will therefor not pay attention to trims. So IsPlanar doesn't really tell you whether a BrepFace is planar, it tells you whether the underlying surface is planar. If you really want to test a BrepFace for planarity, I think the easiest approach is to mesh it and then test the mesh.
--
David Rutten
david@mcneel.com
David,
Thanks for the above, it's very useful. I'm running into another problem now. The output is informing me that the faces which were produced were breps. I've placed the code below:
List<Brep> brepFaces = new List<Brep>();
int countFaces = 0;
foreach(BrepFace surf in x.Faces) //x is brep incoming from canvas
{
Brep faceTemp = surf.DuplicateFace(false);
brepFaces.Add(faceTemp);
}
countFaces = brepFaces.Count;
bool[] planar = new bool[countFaces];
for (int i = 0; i < countFaces; i++)
{
planar[i] = brepFaces[i].IsPlanar(1e-3);
}
A = planar;
I'm sure you'll see the change from list vs array. I'm trying to get my head around that... I like arrays but am not a fan of lists and haven't worked out how to move between them yet.
Lists are much easier in my opinion and unless the code is absolutely performance critical I typically always opt for Lists. The problem is that lists do not autocomplete correctly in the code editor, which makes them very cumbersome to use. However I do most of my development in Visual Studio where this problem doesn't exist.
I like how easy it is to append, insert and remove items (and ranges of items) from and to lists as opposed to arrays.
It's quite easy to go from lists to arrays and back. The List<T> constructor accepts an array as input and List also has a ToArray() method for going the other way. It is a personal preference though, and if you're happier with arrays then by all means stick to them.
As to your first question, a BrepFace must always be part of a parent Brep. When you duplicate a BrepFace, it cannot become part of the same brep as that would result in coincident faces. Thus, what actually happens is you get a completely new Brep which has a single face that is just like the original face.
Are you sure you need to duplicate the faces though? The code snippet you posted doesn't require this. If that code is all you want to do, then it can be written as such:
List<bool> planar = new List<bool>();
foreach(BrepFace face in x.Faces)
{
planar.Add(face.IsPlanar(1e-3));
}
A = planar;
--
David Rutten
david@mcneel.com
David,
I'm working between VS and the c# component which proves to be a very fast way to test portions of code before wrapping them into VS -- so I like both regardless of the clearing issue mentioned.
Could you do me a big favor and re-write the list code provided as an array so that I can be certain of the difference? I've not been lucky finding comparisons but your example will help. My guess would be something like the following. I'm unfortunately still uncertain of the difference between a face and a surface which is another issue I'm having in the code.
bool[] planar = new bool[previouslyDeterminedCount];
for (int i = 0; i < previouslyDeterminedCount; i++)
{
planar[i] = x.Faces.IsPlanar(1e-3);
}
x.Faces is a list sou you can access it's items by index just as you do with an array.
bool[] planar = new bool[x.Faces.Count];
for (int i = 0; i < x.Faces.Count; i++)
{
planar[i] = x.Faces[i].IsPlanar(1e-3);
}
A Surface is an untrimmed NURBS surface. A Face contains a Surface and trim curves.
One correction, in RhinoCommon a Surface is an abstract class representing a certain surface type without any trimming information. It could be a NurbsSurface, but it could equally well be a Revolution or Sum or Plane surface.
--
David Rutten
david@mcneel.com
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by