<p>The answer in the screenshot is wrong on two counts. First, you're correct that in the middle matrix the −1 should be on the third row, not the second. The other error is that the $u, v$ basis vectors are normalized, but not orthogonalized, so $M$ is not in general a rotation matrix; therefore its inverse is not simply its transpose. (The reflection doesn't actually need an orthonormal basis, so you could fix the answer either way: by using the full inverse for $M$, or by fully orthonormalizing $u$ and $v$.)</p>

<p>The rule of thumb for setting up a local coordinate system (I assume orthonormal) for a given object is to set some of the axes to be lined up with the object, then choose arbitrary perpendicular vectors for any remaining axes.</p>

<ul>
<li>For a point, there's nothing to line up with, so you can use any arbitrary axes.</li>
<li>For a line, you line up the $u$ axis with the line, then there's nothing to constrain the $v$ axis, so you can choose any arbitrary vector perpendicular to $u$. That's what the $v=u\times(0,0,1)^T$ thing was getting at: it's a convenient formula to get <em>some</em> vector perpendicular to $u$ if you don't otherwise care what direction it is. Except that this won't work if $u$ happens to be parallel to the z-axis (the cross product returns zero then), so you actually need to detect that and switch to a different formula, such as $v=u\times(1,0,0)^T$, in that case.</li>
<li>For a plane, you line up the $u$ and $v$ axes with the plane. So, you can pick any arbitrary $u$ that lies in the plane, then find a $v$ that lies in the plane and is perpendicular to $u$.</li>
</ul>

<h3>Addendum on orthonormalization</h3>

<p>Suppose you have a couple of 3D vectors $u, v$ that are non-parallel (linearly independent) but otherwise arbitrary, and you want to generate a 3D orthonormal basis $u', v', w'$ from them. There are two equivalent ways to do it.</p>

<ol>
<li><p>Use the <a href="https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process" rel="nofollow">Gram–Schmidt process</a>. This works as follows: first, normalize $u$. Then, for each additional vector, subtract off its projection onto the previous vectors, and normalize what's left over. For the 3D case this looks like:
$$ \begin{aligned}
u' &amp;= \text{normalize}(u) = \frac{u}{|u|} \\
v' &amp;= \text{normalize} \bigl( v - (u' \cdot v)u' \bigr) \\
w' &amp;= u' \times v'
\end{aligned} $$
Note that the notation $(u' \cdot v)u'$ means take the dot product of $u'$ with $v$ (giving a scalar), then multiply that scalar by $u'$. This gives the vector component of $v$ that is parallel to $u'$. When this is subtracted from $v$, the remaining component is perpendicular to $u'$.</p>

<p>Finally, $w'$ is set to the cross product of $u'$ and $v'$ to ensure the basis is right-handed. Since $u', v'$ are already orthonormal, we don't need to normalize $w'$—it comes out already normalized. (This isn't strictly part of the Gram–Schmidt process.)</p>

<p>By the way, the Gram–Schmidt process works for making an orthonormal basis in any number of dimensions, not just two or three.</p></li>
<li><p>The other way, which only works in 3D, is to use cross products.
$$ \begin{aligned}
u' &amp;= \text{normalize}(u) \\
w' &amp;= \text{normalize}(u' \times v) \\
v' &amp;= w' \times u'
\end{aligned} $$
Here, $w'$ has to be normalized because $u'$ and $v$ are not orthonormal. But then $u'$ and $w'$ are orthonormal, so we can calculate $v'$ from them without a normalize. This gives the same results as the previous process, so it's up to you which you prefer to use.</p></li>
</ol>

CC BY-SA 3.0
2016-08-27T08:46:44.857Z
I was thinking about the mirror row and it is possible that we are seeing a slightly malformed version of the original question. In which case it could be correct.
joojaa
CC BY-SA 3.0
2016-08-27T10:06:08.440Z
@joojaa Why do you think the question is a malformed version?
Jjang
CC BY-SA 3.0
2016-08-27T10:16:20.233Z
@Nathan, Thanks alot. Although I'm left with several questions:
1. Can you clarify "You could fix the answer either way.. fully orthonormalizing u and v.") ? How do I fully orthonormalize u and v? That is also a question regarding bullet #3 of your answer. Would leaving $u$ as it is and setting $v=u\times|B-A|$ satisfies the requirement? If not, can you please show me explicitly?
2. So for a point I can use anything, even $(1,0,0),(0,1,0),(1,0,0)$?
3. Regarding the normalization with $|AC|$, so is it correct? or it should be $|C-A|$? Because I'm not sure the first one is a shorthand.
Jjang
CC BY-SA 3.0
2016-08-27T11:15:51.780Z
@jiang because its a trivial error and depends on exact wording of the problem it is eady to construct a sentence where the 2 solutions would ony differ by a two letter preposition. $|AC|$ is perfectly normal shorthand in literature.
joojaa
CC BY-SA 3.0
2016-08-27T17:45:28.297Z
@Jjang For orthonormalization, look at the [Gram–Schmidt process](https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process). Briefly, you'd start with $v = B - A$, then set $v' = v - (u \cdot v)u$. This subtracts off the component of $v$ that's parallel to $u$, leaving only the perpendicular component. Then you normalize $v'$. And joojaa is right, $|AC|$ is common shorthand for the distance between $A$ and $C$.
Nathan Reed
CC BY-SA 3.0
2016-08-27T19:03:18.123Z
Ok, and just to clarify, $u=\dfrac{B-A}{|AB|}$, $v'=u-((C-A)*u)(C-A))$ and then $v=\dfrac{v'}{|v|}$, $w=u\times v$? I'm just verifying this because I've never seen this way before (the way you created $v'$).
Jjang
CC BY-SA 3.0
2016-08-27T21:41:38.830Z
By the way, I've just seen this solution (to finding $u,v,w$), what do you say? $u=\dfrac{AB}{|AB|}$, $v=u\times w$, $w=\dfrac{AB\times AC}{|AB\times AC|}$? Is it correct? So there are 2 questions here: 1. Was I right in the previous answer? 2. Is the answer given here correct?
Jjang
CC BY-SA 3.0
2016-08-28T01:22:23.257Z
@Jjang I added more to the answer that will hopefully clarify it. Yes, your second approach is fine too and gives the same results as the Gram–Schmidt process I outlined.
Nathan Reed
CC BY-SA 3.0
2016-08-27T07:40:09.907Z
2016-08-28T01:21:12.287Z
2016-08-28T01:21:12.287Z
Nathan Reed
<p>Consider the following problem and its answer:</p>

<blockquote>
  <p>Given 3 points in 3D: $A=(A_x,A_y,A_z);   B=(B_x,B_y,B_z)  ;    C=(C_x,C_y,C_z)$</p>
  
  <p>Find the transformation matrix (in homogeneous coordinates) that performs a reflection around the plane spanned by the given 3 points.</p>
  
  <p>Answer:</p>
  
  <p><a href="https://i.sstatic.net/WhjIw.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WhjIw.jpg" alt="enter image description here"></a></p>
</blockquote>

<ol>
<li>Can anyone explain why this answer is correct?</li>
<li>Shouldn't normalization be performed by dividing by $|C-A|$ and $|B-A|$ instead of $|AC|$ and $|AB|$?</li>
<li>Wouldn't we want to reflect on $uv$ plane (and then the -1 would be one row below)?</li>
<li>I saw a similar question where you had to rotate around a vector and not a surface, and then we created $v$ with $v=u\times(0,0,1)^T$ (the vector was $P_1-P_0$ and $u=\dfrac{P_1-P_0}{|P_1-P_0|}$. What's the difference?</li>
<li>In general, what is the rule of thumb when finding the $u,v,z$ cartesian system of a given object (plane, line, point etc)?</li>
</ol>

CC BY-SA 3.0
2016-08-27T05:49:59.210Z
Seems to me that $|AC|$ is just shorthand for length of vector A to C which is $|C-A|$ or $|A-C|$ which is your second question. If so then this does work. For you to uderstand why you would need to draw the images of the vectors but im not able to do that on mobile phone.
joojaa
<3d><transformations>
Transformation Matrices
Jjang
# Transformation Matrices

(Asked by: username_0 on 2016-08-26)

Consider the following problem and its answer:

> Given 3 points in 3D: $A=(A\_x,A\_y,A\_z); B=(B\_x,B\_y,B\_z) ; C=(C\_x,C\_y,C\_z)$
>
> Find the transformation matrix (in homogeneous coordinates) that performs a reflection around the plane spanned by the given 3 points.
>
> Answer:
>
> [![enter image description here](https://i.sstatic.net/WhjIw.jpg)](https://i.sstatic.net/WhjIw.jpg)

1. Can anyone explain why this answer is correct?
2. Shouldn't normalization be performed by dividing by $|C-A|$ and $|B-A|$ instead of $|AC|$ and $|AB|$?
3. Wouldn't we want to reflect on $uv$ plane (and then the -1 would be one row below)?
4. I saw a similar question where you had to rotate around a vector and not a surface, and then we created $v$ with $v=u\times(0,0,1)^T$ (the vector was $P\_1-P\_0$ and $u=\dfrac{P\_1-P\_0}{|P\_1-P\_0|}$. What's the difference?
5. In general, what is the rule of thumb when finding the $u,v,z$ cartesian system of a given object (plane, line, point etc)?

**Tags:** 3d, transformations

> **Comments:**
> **username_1**: Seems to me that $|AC|$ is just shorthand for length of vector A to C which is $|C-A|$ or $|A-C|$ which is your second question. If so then this does work. For you to uderstand why you would need to draw the images of the vectors but im not able to do that on mobile phone.  

---

## 1 answers

### Answer by username_2 on 2016-08-27. Score: 4 | Accepted answer

The answer in the screenshot is wrong on two counts. First, you're correct that in the middle matrix the −1 should be on the third row, not the second. The other error is that the $u, v$ basis vectors are normalized, but not orthogonalized, so $M$ is not in general a rotation matrix; therefore its inverse is not simply its transpose. (The reflection doesn't actually need an orthonormal basis, so you could fix the answer either way: by using the full inverse for $M$, or by fully orthonormalizing $u$ and $v$.)

The rule of thumb for setting up a local coordinate system (I assume orthonormal) for a given object is to set some of the axes to be lined up with the object, then choose arbitrary perpendicular vectors for any remaining axes.

* For a point, there's nothing to line up with, so you can use any arbitrary axes.
* For a line, you line up the $u$ axis with the line, then there's nothing to constrain the $v$ axis, so you can choose any arbitrary vector perpendicular to $u$. That's what the $v=u\times(0,0,1)^T$ thing was getting at: it's a convenient formula to get *some* vector perpendicular to $u$ if you don't otherwise care what direction it is. Except that this won't work if $u$ happens to be parallel to the z-axis (the cross product returns zero then), so you actually need to detect that and switch to a different formula, such as $v=u\times(1,0,0)^T$, in that case.
* For a plane, you line up the $u$ and $v$ axes with the plane. So, you can pick any arbitrary $u$ that lies in the plane, then find a $v$ that lies in the plane and is perpendicular to $u$.

### Addendum on orthonormalization

Suppose you have a couple of 3D vectors $u, v$ that are non-parallel (linearly independent) but otherwise arbitrary, and you want to generate a 3D orthonormal basis $u', v', w'$ from them. There are two equivalent ways to do it.

1. Use the [Gram–Schmidt process](https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process). This works as follows: first, normalize $u$. Then, for each additional vector, subtract off its projection onto the previous vectors, and normalize what's left over. For the 3D case this looks like:
   $$ \begin{aligned}
   u' &= \text{normalize}(u) = \frac{u}{|u|} \\
   v' &= \text{normalize} \bigl( v - (u' \cdot v)u' \bigr) \\
   w' &= u' \times v'
   \end{aligned} $$
   Note that the notation $(u' \cdot v)u'$ means take the dot product of $u'$ with $v$ (giving a scalar), then multiply that scalar by $u'$. This gives the vector component of $v$ that is parallel to $u'$. When this is subtracted from $v$, the remaining component is perpendicular to $u'$.

   Finally, $w'$ is set to the cross product of $u'$ and $v'$ to ensure the basis is right-handed. Since $u', v'$ are already orthonormal, we don't need to normalize $w'$—it comes out already normalized. (This isn't strictly part of the Gram–Schmidt process.)

   By the way, the Gram–Schmidt process works for making an orthonormal basis in any number of dimensions, not just two or three.
2. The other way, which only works in 3D, is to use cross products.
   $$ \begin{aligned}
   u' &= \text{normalize}(u) \\
   w' &= \text{normalize}(u' \times v) \\
   v' &= w' \times u'
   \end{aligned} $$
   Here, $w'$ has to be normalized because $u'$ and $v$ are not orthonormal. But then $u'$ and $w'$ are orthonormal, so we can calculate $v'$ from them without a normalize. This gives the same results as the previous process, so it's up to you which you prefer to use.

> **Comments:**
> **username_1**: I was thinking about the mirror row and it is possible that we are seeing a slightly malformed version of the original question. In which case it could be correct.  
> **username_0**: @username_1 Why do you think the question is a malformed version?  
> **username_0**: @username_2, Thanks alot. Although I'm left with several questions: 1. Can you clarify "You could fix the answer either way.. fully orthonormalizing u and v.") ? How do I fully orthonormalize u and v? That is also a question regarding bullet #3 of your answer. Would leaving $u$ as it is and setting $v=u\times|B-A|$ satisfies the requirement? If not, can you please show me explicitly? 2. So for a point I can use anything, even $(1,0,0),(0,1,0),(1,0,0)$? 3. Regarding the normalization with $|AC|$, so is it correct? or it should be $|C-A|$? Because I'm not sure the first one is a shorthand.  
> **username_1**: @jiang because its a trivial error and depends on exact wording of the problem it is eady to construct a sentence where the 2 solutions would ony differ by a two letter preposition. $|AC|$ is perfectly normal shorthand in literature.  
> **username_2**: @username_0 For orthonormalization, look at the [Gram–Schmidt process](https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process). Briefly, you'd start with $v = B - A$, then set $v' = v - (u \cdot v)u$. This subtracts off the component of $v$ that's parallel to $u$, leaving only the perpendicular component. Then you normalize $v'$. And username_1 is right, $|AC|$ is common shorthand for the distance between $A$ and $C$.  
> **username_0**: Ok, and just to clarify, $u=\dfrac{B-A}{|AB|}$, $v'=u-((C-A)*u)(C-A))$ and then $v=\dfrac{v'}{|v|}$, $w=u\times v$? I'm just verifying this because I've never seen this way before (the way you created $v'$).  
> **username_0**: By the way, I've just seen this solution (to finding $u,v,w$), what do you say? $u=\dfrac{AB}{|AB|}$, $v=u\times w$, $w=\dfrac{AB\times AC}{|AB\times AC|}$? Is it correct? So there are 2 questions here: 1. Was I right in the previous answer? 2. Is the answer given here correct?  
> **username_2**: @username_0 I added more to the answer that will hopefully clarify it. Yes, your second approach is fine too and gives the same results as the Gram–Schmidt process I outlined.  

---

