Dear forum,
I have a problem with Brep.IsPointInside that I cannot solve on my own. I am checking if the points in a list of three lies within a closed Brep and it tells me that two points are inside and one point is outside the Brep, but in reality is the oposite. The Brep that I am checking with is generated in a C# component one step earlier and interestingly enough, when I first bake that Brep and referece it back to GH, Brep.IsPointInside generates the correct results.
This is giving the two points that are actually lying outside the closed brep.
To me it seams like there is something fuzzy going on with the brep, but I can’t figure it out. Could someone please help me troubleshoot this problem?
In your previous c# script, the method Brep.CreateOffsetBrep is returning you a flipped out brep. That is the problem.
In this cases, if you expect the brep to be closed and you are not sure if the solid is “positive” or “negative”, do a .Flip() ; if the brep is already ok, nothing will happens, if the brep is negative, it will be corrected.
In your previous c# script, add a “solid.Flip();” at line 90.
Thank you @maje90 and @PeterFotiadis for your replys, that one I would’ve never found myself. But why is that, why is it generating a negative volume? If I use any of your suggested methods, would that be a work around or is that a common workflow?
But @maje90, this still feels like a work around. It would be better to just define the solid correctly to begin with. What am I doing wrong in my first code?
Well … given the fact that any real-life C# worth the name may contain dozens of lines (and Methods) … one more is nothing (plus: better safe than sorry).
That said the lines required for checking the validity of your input … blah, blah
However now I have troubles implementing the solution in my code. I tried the following code
If(brep.SolidOrientation==-1){
brep.Flip();
}
which does not work and generates the following error message
Error (CS0019): Operator ‘==’ cannot be applied to operands of type ‘Rhino.Geometry.BrepSolidOrientation’ and ‘int’ (line 93)
However, I made it work like this
If(brep.SolidOrientation < 0)
which to me seams strange, now it suddenly works with integers. Is there a logic here that I am missing, could you please explain this @maje90@PeterFotiadis ?
is doing. But can you please explain why it is important? If I would feed a curve and not a brep, it will anyways not work, why is it important to include a check like this?
Always check your input … most notably if there’s several C#'s/Methods around (Real-life: meaning …output from one/some is input to an other).
Obviously check(s) are related with the Type expected: so if we are talking, say, GeometryBase (see SDK for the supported Types) … ask more questions and act accodringly. (i.e. if this is Curve > …, if that is Brep > … , if is a Mesh > …) .
Tip: NEVER assume that your input is correct/valid. As we say in motorcycle racing: if you fail to prepare prepare to fail.