Jump to content
  • Advertisement
JoeJ

How to solve this trig function?

Recommended Posts

sin(a*t) * d = sin(a*(1-t)) * e

 

I want to solve for t, t has to be in range [0,1], and all other values are known.

Using math tools they only spit out special and disallowed cases (I don't know how to use them properly for periodic stuff).

Graphing both sides of the equation, both sides are simple sine waves and any intersection would be my solution. But so far i only know how to add 2 waves, not how to find intersections. Maybe somebody has a quick answer while i try from there...

Share this post


Link to post
Share on other sites
Advertisement

You just need to look up trig identities and apply them to simplify and solve the problem.

Share this post


Link to post
Share on other sites

Harder than i thought and probably too expensive for the inner loop of a solver for UV maps.

I ended up at the same point few days ago but noticed there was a simple geometric solution to get around it. It should work in a similar way too this time i hope...

Share this post


Link to post
Share on other sites

I did some napkin calculations, and found below result. Not 100% sure, so verify before using:

t = 1/a.( atan( ( d + e.cos(a) ) / e.sin(a) ) ) ) 

Assuming you know a, d and e and can calculate arc tan relatively easily. 

Share this post


Link to post
Share on other sites
12 hours ago, fmatak said:

I did some napkin calculations, and found below result. Not 100% sure, so verify before using:


t = 1/a.( atan( ( d + e.cos(a) ) / e.sin(a) ) ) ) 

Assuming you know a, d and e and can calculate arc tan relatively easily. 

Thanks, but seems wrong.

You forgot a brace, i tried those options, but they are both wrong:

float a = 1.3f;
float d = 0.7f;
float e = 0.9f;

// try to solve
// sin(a*t) * d = sin(a*(1-t)) * e
// for t

{
	float t = 1 / a * ( atan( ( d + e*cos(a) ) / e*sin(a) ) );
	float proofLHS = sin(a*t) * d;
	float proofRHS = sin(a*(1-t)) * e;
	ImGui::Text ("(1) lhs %f != rhs %f", proofLHS, proofRHS);
}
{
	float t = 1 / (a * ( atan( ( d + e*cos(a) ) / e*sin(a) ) ) );
	float proofLHS = sin(a*t) * d;
	float proofRHS = sin(a*(1-t)) * e;
	ImGui::Text ("(2) lhs %f != rhs %f", proofLHS, proofRHS);
}
{
	static float t = 0.573;
	ImGui::DragFloat("t", &t, 0.0001f);

	float proofLHS = sin(a*t) * d;
	float proofRHS = sin(a*(1-t)) * e;
	ImGui::Text ("(3) lhs %f != rhs %f", proofLHS, proofRHS);
}

output:

(1) lhs 0.496743 != rhs 0.440162 (small error but with other numbers it's large)
(2) lhs 0.668042 != rhs 0.029278
(3) lhs 0.474529 != rhs 0.474325

 

I've had no luck myself yet either...

 

Share this post


Link to post
Share on other sites

I'm absolutely rubbish at maths but this is as far as I got:

sin(a*t) * d = sin(a*(1-t)) * e

sin(a*t) = (sin(a*(1-t)) * e) / d

sin(a*t) / sin(a*(1-t)) = e / d

Then I went to this site:

http://www.webmath.com/trigsimp.html

and found that

sin(a*t) / sin(a*(1-t)) is the same as sin(ta)

so

sin(ta) = e/d

So in my vast maths ability I've managed to make the equation smaller lol. :D

Share this post


Link to post
Share on other sites
Posted (edited)
Quote

(from the website)

sin(a*t) / sin(a*(1-t)) is the same as sin(ta)

this can't be right, I think that site is confusing, as that's just the numerator... grr!! :( Here's some more gibberish from the site, perhaps it is just trying to say that a*t is the same as ta, wow, I could have guessed that lol.

Quote

The problem to solve is:

sin(a*t) / sin(a*(1-t))

 

Multiply t and a

Multiply the t and a

Multiply t and a

 

The t just gets copied along.

The a just gets copied along.

The answer is ta

ta

a*t evaluates to ta

sin(a*t)/sin(a*(1-t)) evaluates to sin(ta)

If all else fails it looks like you can have a 2d lookup table with a and e/d! :)

Edited by lawnjelly

Share this post


Link to post
Share on other sites
5 hours ago, JoeJ said:

You forgot a brace, i tried those options, but they are both wrong

Sorry, I copied from the napkin and forgot to add correct braces. Here you go:

t = ( 1 / a ) * ( atan( ( d + e * cos(a) ) / ( e * sin(a) ) ) ) ) )

The problem was with the last sin, it should be in the braces as well..

Share this post


Link to post
Share on other sites

I gradually felt like I was getting there with some trig identities but I haven't tried solving equations since school 30 years ago lol

Would you mind showing how you got to that step by step fmatak, for the benefit of us mathematically challenged folk lol... :D

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!