
differentiating a sine wave to get a normal
hi,
I''m trying to calculate normals for a sine-wave generated piece of geometry.
the data is effectively a height field where heights are determined by a 3D formula:
h = aSin(bX+c) * dSin(eY+f)
unfortunately, in the 10 months since I did any maths like this I''ve managed to forget it all
I''ve made a few attempts at trying to find the X && Y vectors, but the results haven''t been correct.
any help possible?! plz!!
Jack
DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>
quote:
Original post by jollyjeffers
hi,
I''m trying to calculate normals for a sine-wave generated piece of geometry.
The normalized gradient is what you want.
h = aSin(bX+c) * dSin(eY+f)
normal dir = (dh/dx,dh/dy,dh/dz)
dh/dx = aCos(bX+c) * b * dSin(eY+f)
dh/dy = aSin(bX+c) * dCos(eY+f) * e
dh/dz = 1
so compute that at a point, and normalize it.
April 24, 2003 01:56 PM
I can''t guarantee that this is correct, but here is my stab at it:
Using partial derivatives (treating one variable as a constant), we can calculate slope of the curve in the x-h plane and the y-h plane separately:
<b>@h/@x = abd * cos(bx + c) * sin(ey + f)
@h/@y = ade * sin(bx + c) * cos(ey + f)</b>
From this we get these two vectors:
<b>[ 1, 0, abd * cos(bx + c) * sin(ey + f) ]
[ 0, 1, ade * sin(bx + c) * cos(ey + f) ]</b>
Whose cross product is:
<b>[ -1 * abd * cos(bx + c) * sin(ey + f), -1 * ade * sin(bx + c) * cos(ey + f), 1 ]</b>
That should give you a vector in the direction of the normal at the point (x, y).
-Logan
Using partial derivatives (treating one variable as a constant), we can calculate slope of the curve in the x-h plane and the y-h plane separately:
<b>@h/@x = abd * cos(bx + c) * sin(ey + f)
@h/@y = ade * sin(bx + c) * cos(ey + f)</b>
From this we get these two vectors:
<b>[ 1, 0, abd * cos(bx + c) * sin(ey + f) ]
[ 0, 1, ade * sin(bx + c) * cos(ey + f) ]</b>
Whose cross product is:
<b>[ -1 * abd * cos(bx + c) * sin(ey + f), -1 * ade * sin(bx + c) * cos(ey + f), 1 ]</b>
That should give you a vector in the direction of the normal at the point (x, y).
-Logan
hi,
thanks for the ideas, I''ll give it a go tommorrow... its just turning 2.30am, so dont think I''ll try tonight
Jack
DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.
thanks for the ideas, I''ll give it a go tommorrow... its just turning 2.30am, so dont think I''ll try tonight

Jack
DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>
further to previous post... it seems that the formula proposed by AP above works the best. The other one does seem to work, but not with quite the right results.
However, both seem to have broken my specular lighting
Jack
DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.
However, both seem to have broken my specular lighting

Jack
DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement