Showing results for 
Search instead for 
Do you mean 
Reply

Orientation matrix for inserting fastener into a hole

Hello everyone!

 

I'm trying to insert fasteners into holes using NX Open. As far as the base point is concerned, it is fine. But I'm struggling with orienting fasteners correctly to insert them into randomly oriented holes. I understand that one way is  to calculate the orientation matrix from two vectors - fastener axis vector and hole axis vector. But I discovered that I quite forgot all those maths topics. Man Frustrated Is there any ready C# (or maybe VB) algorithm that does exactly that?

6 REPLIES

Re: Orientation matrix for inserting fastener into a hole

Best option is to find the seating faces on the hole as well as the fastener, get their face normals and orient your fastener normal opposite to the hole seating face normal.

 

I guess you would want to create assembly constraints between the hole and fastener.  I would suggest you record a journal and modify the code to suit your requirement.

Re: Orientation matrix for inserting fastener into a hole

[ Edited ]

"and orient your fastener normal opposite to the hole seating face normal."

That's exactly the question - how is the orientation matrix computed? The journal won't give you the answer. This is the maths problem.

 

I can create assembly constraints, but it's optional in the application that I'm making. Also, that is the extra operation that has cairries overhead. I believe it's quite costly in terms of time to use assembly contraints - and then delete them -  merely to orient components. In this case orientation matrix must be used.

 

Or correct me if I am wrong. I'm not 100% getting NX Open orientation matrix at the moment. Is there more info on it somewhere in the docs?

Re: Orientation matrix for inserting fastener into a hole

[ Edited ]

I have some python code that does something similar. I made another post on how to set up numpy with NX Open. Feel free to pm me if there is anything unclear.

 

check here for the methods/attributes that will give you your fastener/hole vectors. It's likely that NX will return the vectors in a list or a tuple

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

 

 

#use numpy to turn your vectors into matrices
fastener_array=numpy.array(fastener_vector)
hole_array=numpy.array(hole_vector)

dot_product=numpy.dot(fastener_array,hole_array) #assuming that fastener_array and hole_array are unit vectors of length 1 if dot_product==1.0: #insert whatever you want your code to do below

 

alternatively, you could use the cross product

 

cross_product=numpy.cross(fastener_array,hole_array)
cross_norm=la.norm(cross_product)

#if normalized cross product =0, then vectors are parallel
if cross_norm==0.0:
                    
    

 

Re: Orientation matrix for inserting fastener into a hole

There is a function in Snap.Orientation that constucts an orientation matrix from a given axis vector. But, if you don't have SNAP, it's not too hard to do this from first principles. The given fastener axis becomes the axisZ vector. To get axisX, calculate the cross product of axisZ and one of the coordinate axes, like (0,0,1), and then unitize. To get the axisY vector, take the cross product of axisZ and axisX. Assemble the three vectors axisX, axisY, axisZ into a 3x3 matrix.
山田
yamada

Re: Orientation matrix for inserting fastener into a hole

Thanks everyone for suggestions! I was really busy, but I'll soon check everything out and get back to you with the result.

Re: Orientation matrix for inserting fastener into a hole

I finally got round to having another go at this task and finally solved it. I obtained matrix from the cylindrical hole face using the theUFSession.Csys.AskMatrixOfObject. It was of the wrong orientation for my purpose - components were upside down - so I had to find a way to rotate it in a correct position. The solution came from the example called "rotate selected component about its own x axis" in the Solution center. So this problem is solved for me.