0

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 :-)

thalitus
  • 47
  • 5
  • There will be multiple solutions to your problem - for example the entire triangle could be flipped upside down. What you need to do is find the plane (lets call it P) that defines your triangle. Then you need to find the angle between the z-axis and the normal vector of P (lets call this n). You also need to find the axis of rotation (called u) which will be perpendicular to both the z-axis and n. Then perform an axis-angle rotation about u with theta. This rotation should be applied to all the points. – Stephen Mylabathula Dec 16 '20 at 16:51

1 Answers1

1

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.

aerobiomat
  • 2,883
  • 1
  • 16
  • 19
  • Yep that's the easiest way, I think. You can also compute the quaternion that rotate normal N to align with vector Z (see https://stackoverflow.com/questions/1171849/finding-quaternion-representing-the-rotation-from-one-vector-to-another) then apply that quaternion to all points – Mauricio Cele Lopez Belon Dec 21 '20 at 20:02