title: 3D Vectors - Align a vector's coordinate system to a normal
body: <p>I'm trying to align a coordinate system to a normal direction, in a way I only input X,Y,Z and the direction of the normal and the Y-rotation of the coordinate, to get the new X,Y,Z from the new aligned coordinate system.</p>
  <p>A function that would look like this:</p>
  <pre><code>func transform(coordinate: XYZposition, to: XYZnormal, withY:Radians){
      //missing mathematic
      //rotate coordinates        
      return XYZpositionOfNewSystem
  }
  </code></pre>
  <p>Here is an image representing visualize what I want to achieve. The axis are the representation of the coordinate system. First coordinate system is the original one, and the 2 on the right are the rotated ones.</p>
  <p><a href="https://i.stack.imgur.com/TXNby.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TXNby.jpg" alt="enter image description here" /></a></p>
  <p><strong>Why 2 examples on the right?</strong></p>
  <p>As you can see, when aligning it to a face-normal, there is one free axis. The Y axis can take any rotation and still be aligned to the face.</p>
  <p>That's why a rotation needs to be given to the function so it applies this Y-rotation as well.</p>
  <p>I've found some maths on the Mathematics Stack Exchange site (<a href="https://math.stackexchange.com/questions/542801/rotate-3d-coordinate-system-such-that-z-axis-is-parallel-to-a-given-vector">Rotate 3D coordinate system such that z-axis is parallel to a given vector</a>), but I'm lost if this is what I need, and I'm kind of lost on the maths applied and the symbols used.</p>