Search code examples
c#vector3dquaternions

How to recalculate a 3d normal when the model is scaled?


I have a 3d model and I want to recalculate the normal when the model is scaled (non uniformly). For example, I have a 3d model and when i scale non uniformly, the normal should be affected

1) Figure 1, the model is not scaled. 2) Figure 2, the model is scaled and the normal is affected. (N is the normal).

normals


Solution

  •     public Vector ModifyNormal(Vector v)
        {
            var re = new Vector();
            re.x = v.x  * xScale; 
            re.y = v.y  * yScale; 
            re.z = v.z * zScale;
            double magnitude =Math.Sqrt(re.x * re.x + re.y * re.y + re.z * re.z);
            // normalizing
            re.x = re.x / magnitude;
            re.y = re.y / magnitude;
            re.z = re.z / magnitude;
            return re;
        }