vector normal to face problem direction inside or outside of the body

vector normal to face problem direction inside or outside of the body

daniele_spagli
Enthusiast Enthusiast
1,179 Views
4 Replies
Message 1 of 5

vector normal to face problem direction inside or outside of the body

daniele_spagli
Enthusiast
Enthusiast

Hi, I'm trying to extract a normal vector to a face that is constantly oriented with direction outside the body. If I don't understand wrong the data that I obtain from .normal is not consistent but depend if the face is generated by a tool (boolean operation) instead by normal operations on the face.

Someone know how to make this vector all the times pointing out or at least get a true/false variable that say to me if is oriented inside or outside?

 

def searchFaceAligned(bodies,vector):
    for body in bodies:
        facesModel=body.faces

        searchEdge=True
        rak=0
        rakMax=facesModel.count
        while searchEdge and rak<=rakMax:
                            
            faceModel=[]
            faceModel=facesModel.item(rak)
            rak+=1
            facePlane=faceModel.geometry
            if facePlane.objectType=="adsk::core::Plane":
                
                faceNormal=facePlane.normal
                
                if vector.isParallelTo(faceNormal):
                    searchEdge=False
                    isrev=faceModel.isParamReversed


        angleZ=abs(vector.angleTo(faceNormal))
        if angleZ<1:
            if isrev:
                inverse=True
            else:
                inverse=False
        else:
            if isrev:
                inverse=False
            else:
                inverse=True


        return faceModel, inverse

 

0 Likes
Accepted solutions (1)
1,180 Views
4 Replies
Replies (4)
Message 2 of 5

daniele_spagli
Enthusiast
Enthusiast

It seems that is an easy solution, need only to add the line

faceNormal.normalize()

after the acquisition of the vector.

Daniele

0 Likes
Message 3 of 5

BrianEkins
Mentor
Mentor
Accepted solution

I think you still have a problem and just got lucky in your test because normalizing the vector shouldn't change anything. The vector you are getting should already be normalized. To ensure you get a normal pointing out of the face, you need to use the functionality on the SurfaceEvaluator object that you get from the BRepFace object. Here's a modified version of your code that does that. I didn't test it, so there might be a typo or two, but it illustrates the idea.

 

def searchFaceAligned(bodies, vector):
    for body in bodies:
        facesModel=body.faces

        searchEdge=True
        rak=0
        rakMax=facesModel.count
        while searchEdge and rak<=rakMax:                           
            faceModel=[]
            faceModel=facesModel.item(rak)
            rak+=1
            eval = faceModel.evaluator
            (_, faceNormal) = eval.getNormalAtPoint(faceModel.pointOnFace)

        return faceModel, faceNormal

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 5

daniele_spagli
Enthusiast
Enthusiast

Yes, I guess this was the thing.

 

I already made the surface evaluator and add normalize the vector. It worked well so I thought it was because the normalize function but later I delete the surface evaluator and it stop to work consistently again.

 

So maybe my memory worked bad when I thought to still have problems with the surface evaluator.

 

I will try again and I will confirm it.

 

thanks

Daniele

0 Likes
Message 5 of 5

daniele_spagli
Enthusiast
Enthusiast

Thank you alot Brian, you save my sunday. 🙂

 

I notice that you changed the return function, but this is not what I need: I want to set the checkbox or not in the set new Z for the tool in the CAM section. I have a cnc with side drills and setting manually the Z for it was quite annoying. But don't worry, I keep only the 2 lines that I needed and it works like a charm. 🙂

0 Likes