Scaling the normal vector of a triangle

331 Views Asked by At

I have opened a STL file including many facets.

Each facet is made of 3 vertices v1, v2, v3 and a normal vector n.

I would like to scale the CAD model. So, I scale each vertex by

$$v'_{1x}=k_x v_{1x},\quad v'_{1y}=k_y v_{1y},\quad v'_{1z}=k_z v_{1z}$$ $$v'_{2x}=k_x v_{2x},\quad v'_{2y}=k_y v_{2y},\quad v'_{2z}=k_z v_{2z}$$ $$v'_{3x}=k_x v_{3x},\quad v'_{3y}=k_y v_{3y},\quad v'_{3z}=k_z v_{3z}$$

However, I do not know how to update the members of $n'$ from n based on $k_x$, $k_y$ and $k_z$.

Can I just directly scale the normals and then normalize them?

1

There are 1 best solutions below

0
On BEST ANSWER

Each facet is the intersection of a (unique) plane with the convex set, and are solutions to an equation in $x$ of the form, $$n \cdot x = \alpha$$ where $\alpha \in \mathbb{R}$ and $n$ is the normal vector. You're trying to apply a transformation $T$ with a standard matrix $$M(T) = \begin{pmatrix}k_x & 0 & 0 \\ 0 & k_y & 0 \\ 0 & 0 & k_z\end{pmatrix}$$ To apply $T$ to the hyperplane above, substitute $T^{-1}x$ with $x$, to get, $$n \cdot (T^{-1}x) = \alpha \iff ((T^{-1})^*n)\cdot x = \alpha,$$ where $^*$ refers to the adjoint (in this case, the transpose). (Note that given $x$ that satisfies the first equation, then $Tx$ satisfies this equation.)

From this, we read out a vector normal to our new facet:

$$(T^{-1})^* n = (k_x^{-1} n_1, k_y^{-1} n_2, k_z^{-1}n_3)$$

While this vector is normal to the facet, this normal is not necessarily a unit vector, and orientation may not have been preserved (in the sense that the vector may not point away from the convex set any more). To fix the length, we divide this vector by its length. To fix the orientation, we multiply the vector by $-1$ if the determinant of $T$ is negative. In this case, the determinant is $k_x k_y k_z$. Thus, our normal vector becomes, $$\left( \frac{\operatorname{sign}(k_xk_yk_z) k_x^{-1} n_1}{\sqrt{k_x^{-2} n_1^2 + k_y^{-2} n_2^2 + k_z^{-2}n_3^2}}, \frac{\operatorname{sign}(k_xk_yk_z) k_y^{-1} n_2}{\sqrt{k_x^{-2} n_1^2 + k_y^{-2} n_2^2 + k_z^{-2}n_3^2}}, \frac{\operatorname{sign}(k_xk_yk_z) k_z^{-1}n_3}{\sqrt{k_x^{-2} n_1^2 + k_y^{-2} n_2^2 + k_z^{-2}n_3^2}} \right),$$ where $\operatorname{sign}(x)$ returns $1$ if $x > 0$ and $-1$ if $x < 0$.

More generally, when $T$ is not a diagonal operator, the normal vector becomes $$\operatorname{sign}(\operatorname{det}(T))\frac{(T^{-1})^* n}{\|(T^{-1})^* n\|}.$$