Cancel
Showing results for
Did you mean:

# Orientation matrix for inserting fastener into a hole

Solution Partner Genius

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.  Is there any ready C# (or maybe VB) algorithm that does exactly that?

6 REPLIES

# Re: Orientation matrix for inserting fastener into a hole

Phenom

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.

Suresh

# Re: Orientation matrix for inserting fastener into a hole

Solution Partner Genius

"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

Genius

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 matricesfastener_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

Siemens Phenom
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.