I'm calculating surface normal for my analytical surface. Some parts of normal i'm getting are correct but not all. Code is :
SurfaceVertices3f[pos] = i;
SurfaceVertices3f[pos+1] = j;
SurfaceVertices3f[pos+2] = (cos(i)*sin(j));
/*a and b hold the poutput of partial differentiation of vertices from above three lines.a is wrt i and b is wrt j */
a[0]=1;
a[1]=0;
a[2]=-sin(i)*sin(j);
b[0]=0;
b[1]=1;
b[2]=cos(i)*cos(j);
normal_var=Vec3Df::crossProduct( a, b);
normal_var.normalize();
My output looks like this, right image is mine and left one i'm using as refrence . http://tinypic.com/view.php?pic=73l9co&s=5
Could anyone tell me what mistake i'm doing?
Your normal calculation is correct. The reference image has just a different way to map normals to colors.
If you have a look at the green ground color, you will see that the color's norm is not 1. But normals should have a norm of 1. If we assume another common mapping from normal to color like this one:
color.rgb = normal.xyz / 2 + 0.5
We see that this is no unit vector either. So either they used yet a different mapping or they just don't have unit length normals.