Friday, January 8, 2010

How do I get a normal Vector from a gradient?

I am making wavy water for my game and i need a function that will get the direction that a point is facing as a Vector3(x, y, z)?





I have a function for dY/dX, and dY/dZ, and i just need to get the normal from that.How do I get a normal Vector from a gradient?
If you have a surface parametrized as S(x,z) and you know the partial derivatives (未/未x,未/未z)S(x,z) on that surface, then you have created the tangent vector space at points (x,z). The partial derivatives form your basis that span the space like (1,1,1) unit vectors do in R^3. Hence, to form a normal vector, you take the cross-product of your basis vectors to get a vector orthogonal. Specifically,





n := [未S(x,z)/未x X 未S(x,z)/未z)] / ||未S(x,z)/未x x 未S(x,z)/未z)||





Your unit normal will be in the -j direction since iXk = -j.

No comments:

Post a Comment