thalitus
thalitus

Reputation: 47

Rotation and translation of 3D points based on a triangle in Python

I'm sure that this has been answer already but I'm still confused with the post I already found on stackoverflow, that's why I decided to post my question.

I'm not super familiar with geometry transformation (except translation but this one is easy), and I need to transform a set of 3D points based on a selection of 3 points as describe in the picture

enter image description here

Here's my plan so far :

  1. Create a triangle based on 3 points (let's call it tri) -> This is OK
  2. Calculate the centroid of the triangle formed by my 3 points -> This is this is OK
  3. translate all the points to the origin (0,0,0) -> This is OK as well
  4. Rotate every points so that tri's points Z coordinates are equal to 0 -> This is were I'm lost and unsure how to process (without any errors...)

I know it's not an hard issues, but if anyone knows how to process with numpy for example, I'm open :-)

Thank you for your help :-)

Upvotes: 0

Views: 998

Answers (1)

aerobiomat
aerobiomat

Reputation: 3437

In step 4 what you want is to rotate the triangle so that its normal is vertical.

You need to calculate the triangle's normal first. You can do so by using the cross product between two vectors (a and b) along two sides of the triangle: N = a x b.

Then you can calculate an axis of rotation A using the cross product between the triangle's normal and the Z axis: A = N x Z.

Then you can rotate the points using axis A.

As pointed out elsewhere, the solution is not unique.

Upvotes: 1

Related Questions