Atrix256 540 Posted October 26, 2009 hey guys does anyone know how to find the normal of a point on a sine wave? i know that the slope (tangent) of a sine wave is the cosine wave, so i can use that to calculate the tangent at a point on a sine wave. However that is y/x and i don't know how to get the individual x and y components out of that. I figure once i have the x and the y components i can swap them and negate one to get the normal. Anyone know how to calculate this? Thank you! (PS im trying to find this out so i can use the normal to do lighting on a height map im manipulating in a vertex shader) 0 Share this post Link to post Share on other sites

Dave Eberly 1175 Posted October 26, 2009 Sine curve is parameterized as (x,sin(x)). A unit-length tangent is (1,cos(x))/sqrt(1+(cos(x))^2) = (tx,ty). A unit-length normal is (ty,-tx). 3 Share this post Link to post Share on other sites

Atrix256 540 Posted October 26, 2009 Dave!Thank you!(rating++ for you) 1 Share this post Link to post Share on other sites

Atrix256 540 Posted October 27, 2009 Darn i have a follow up question.since a sine wave itself doesn't look like realistic waves, i multiple the output of sin by 0.125 to make it 1/8th as tall of a wave.in the formula you gave, it works great for a full sized sine wave but not with the shrunken sine wave of course.I tried replacing cos(x) with (cos(x)*.125) in the equation you gave but that didn't give the right results.do you know how to take this into account?Thank you again you have been an amazing help 0 Share this post Link to post Share on other sites

SPuntte 158 Posted October 27, 2009 I'm not sure whether Dave's formula is right. It might be, then i just misunderstood it.Here's how I do that:We have a scaled sine function, t sin xNow we differentiate it with respect to x so we get:D(t sin x) = t D(sin x) = t cos xFrom analytic geometry we know that slope of a tangent of a function (derivative) and it's direction angle a satisfy the relation: tan a = kSo we have: tan a = t cos xSolving for a: a = arctan(t cos x)Now we have the direction angle which unambigiously defines an unit length tangent vector s:s = i cos a + j sin aKnowing the tangent it's easy to get the normal:n = -i sin a + j cos aSo the normal parametrizes as (-sin a, cos a) where a = arctan(t cos x)Someone correct me if I did something wrong :) 0 Share this post Link to post Share on other sites

alvaro 21295 Posted October 27, 2009 You can follow the same process Dave used for (x,sin(x)) to find the normal to any curve. Your new curve is (x, sin(x)/8), so a tangent vector is (1, cos(x)/8). Now you need to normalize it, which gives you (1,cos(x)/8)/sqrt(1+cos(x)^2/64). You finally flip the coordinates and change the sign to one of them to get a normal vector. 0 Share this post Link to post Share on other sites

knighty 313 Posted October 27, 2009 Let:y=f(x)the derivative is:dy/dx=f'(x)A tangent's direction vector to f at x is:(dx,dy)=(dx,f'(x)*dx)=dx(1,f'(x))(1,f'(x)) is also a tangent's direction of f at x.a normal vector to f at x is:(f'(x),-1)Now if I've understood well you have: f(x)=sin(a*x)so:f'(x)=a*cos(a*x)A normal vector would be:(a*cos(a*x),-1)its norm is:sqrt(1+a^2*cos^2(a*x))So the normalised normal vector is:(a*cos(a*x),-1)*1/sqrt(1+a^2*cos^2(a*x))If we take a=1 the normalised normal vector will be:(cos(x),-1)*1/sqrt(1+cos^2(x))Which is what Dave Eberly gave. 0 Share this post Link to post Share on other sites

SPuntte 158 Posted October 27, 2009 Oh, I accidentally read the parentheses wrong. Dave's formula is alright.However, I understood that only the amplitude of sin was modified, not it's periodQuote:Original post by Atrix256since a sine wave itself doesn't look like realistic waves, i multiple the output of sin by 0.125 to make it 1/8th as tall of a wave.So knighty's formula is calculated right but unfortunately it's not the one we're looking for hereQuote:Original post by knightyNow if I've understood well you have: f(x)=sin(a*x)Substituting the correct(?) fuction to knighty's formula yields:whete t is the scaling multiplier (= 1/8 ?)#EDIT:It seems that the formula above calculates the right-hand normal that points "inside" the wawes. To calculate the left-hand normal vector (which has positive y-component) you should just multiply the components by -1. 0 Share this post Link to post Share on other sites

knighty 313 Posted October 27, 2009 I didn't understand you well :)You have y=f(x)=a*sin(x)f'(x)=a*cos(x)Which gives for the normalized normal vector (that's exactly what alvaro have given):(a*cos(x),-1)*1/sqrt(a^2*cos^2(x)+1)substitute a by 1/8 gives:(cos(x)/8,-1)/sqrt(1+(cos(x))^2/64)( cos^2(x)==(cos(x))^2. just to be clear )SPuntte:I can't read your formulas :)Quote:#EDIT:It seems that the formula above calculates the right-hand normal that points "inside" the wawes. To calculate the left-hand normal vector (which has positive y-component) you should just multiply the components by -1.You'r right. 0 Share this post Link to post Share on other sites

Atrix256 540 Posted October 27, 2009 Thank you guys, that seems to have done the trick (: 0 Share this post Link to post Share on other sites

jasonburton 100 Posted November 3 I was coping with a similar problem A sine wave with amplitude A and frequency F, would result in the derivative d/dx A * sin(F * x) = A * F * cos(F * x) 0 Share this post Link to post Share on other sites

swiftcoder 18462 Posted November 7 Let's try not to resurrect 8 year-old threads in the future. 0 Share this post Link to post Share on other sites