Advertisement

How to solve this trig function?

Started by August 14, 2018 07:10 PM
20 comments, last by lawnjelly 6 years, 5 months ago
1 hour ago, fmatak said:

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..

There are still 2 braces at the end which i've had to remove: 

    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 ("(4) lhs %f != rhs %f", proofLHS, proofRHS);


But the output is still wrong:

(4) lhs 0.514684 != rhs 0.410760

 

6 hours ago, lawnjelly said:

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

This makes no sense because sin(a*t)/sin(a*(1-t)) more looks like output of tan() with some scale, offsets and power, but it's nowhere close to a sine curve.

 

Also no luck with what i got from Wolfram Alpha.

 

I give up. I tried an iterative method, but the solver converged worse than the one i already have. I guess math guys would call my problem nonlinear and nonconvex. It solves for optimal UV map with angular constraints to force isotropy and matching scale / rotation at seams. My idea was to have a simpler solver working on just edges instead on the complex problem of a whole triangle ring around a vertex, but probably the more primitives you solve at once, the better.

So my working solver jitters and does not converge to an exact solution, but it is good enough and i use a second less constrained solver to fix the remaining inaccuracy. It's not elegant but it works and i'll have to stick at it.

Thanks anyways, guys! (I may revisit the problem if a solution comes up... :) )

 

 

 

Kinda tired, but I got the following:

t = (arcsin(e/d)) / (1 + arcsin(e/d))

Hello to all my stalkers.

Advertisement

I gave this a quick look. To avoid typing I just solved the simpler problem sin(t) = sin(1-t). The basic solving strategy should be the same hopefully. Here is what I came up with: 


// Solve
sin(t) = sin(1-t) 

// Angle sum identies sin(a-b) = sin(a) * sin(b) - cos(a) * sin(b)
sin(t) = sin(1) * cos(t) - cos(1) * sin(t) 

// Add cos(1) * sin(t) on both side
sin(t) + cos(1) * sin(t) = sin(1) * cos(t) 

// Factor sin(t) 
sin(t) * [1 + cos(1)] = sin(1) * cos(t) 

// Divide by cos(t)
tan(t) * [1 + cos(1)] = sin(1) *and* cos(t) != 0

// Divide by [1 + cos(1)]
tan(t) = sin(1) / [1 + cos(1)]

// Solve for t
t = atan( sin(1) / [1 + cos(1)] )

// Calculator 
t = 0.5

Obviously this is indeed the correct solution as sin( 0.5 ) = sin( 1 - 0.5 )

HTH,

-Dirk

4 hours ago, lawnjelly said:

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

 

 

Well, let me try:


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

d/e = sin(at) / sin(a-at)

expand sin(a-at) to sin(a) * cos(at) - cos(a) * sin(at)


e/d = ( sin(a) * cos(at) - cos(a) * sin(at) ) / sin(at)

simplify:


e/d = sin(a)* tan(at) - cos(a)

we know a,d and e so sin/cos of them are also constant. we need to put everything on one side except t.


( e/d + cos(a) ) / sin(a) = tan(at)

use atan to get rid of tan and move a to the other side.


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

if we expand inside of atan, we get 


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

I hope this is same as what I wrote earlier :)

only thing that worries me is, the units in trig functions. Radians etc. you may need to multiply/divide with PI or something...

For completeness:


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

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

// Substitute b = d/e
b * sin(at) = sin(a - at)

// Trig identity
b * sin(at) = sin(a) * cos(at) - cos(a) * sin(at)

// Add cos(a) * sin(at) on both sides
b * sin(at) + cos(a) * sin(at) = sin(a) * cos(at) 

// Factor sin(at) 
sin(at) * [b + cos(a)] = sin(a) * cos(at) 

// Divide by cos(at) and use tan(at) = sin(at) / cos(at)
tan(at) * [b + cos(a)] = sin(a) *and* cos(at) != 0

// Divide by [b + cos(a)]
tan(at) = sin(a) / [b + cos(a)]

// Solve for at
at = atan( sin(a) / [b + cos(a)] )

// Divide by a 
t = atan( sin(a) / [b + cos(a)] ) / a

 

Awesome help! This really helps learning how to work with trig equations... :)

Dirk wins the 1st price:

(Dirk) lhs 0.474447 == rhs 0.474447 
(fmatak) lhs 0.547245 != rhs 0.352537 
(Lactose) lhs -nan(ind) != rhs -nan(ind) 

Thanks!


	{
    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 b = d/e;
        float t = atan( sin(a) / (b + cos(a)) ) / a;
        float proofLHS = sin(a*t) * d;
        float proofRHS = sin(a*(1-t)) * e;
        SystemTools::Log ("(Dirk) lhs %f == rhs %f \n", proofLHS, proofRHS);
    }
    {
        float t = 1/a * (atan( ( e + cos(a) * d ) / ( e * sin( a ) )  ) );
        float proofLHS = sin(a*t) * d;
        float proofRHS = sin(a*(1-t)) * e;
        SystemTools::Log ("(fmatak) lhs %f != rhs %f \n", proofLHS, proofRHS);
    }
    {
        float t = (asin(e/d)) / (1 + asin(e/d));
        float proofLHS = sin(a*t) * d;
        float proofRHS = sin(a*(1-t)) * e;
        SystemTools::Log ("(Lactose) lhs %f != rhs %f \n", proofLHS, proofRHS);
    }
	}
	

 

 

Advertisement

Thanks guys, this has been really useful for me to remember how to solve equations. I've tracked down the error in fmatak's version I think:

Quote

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

e/d = sin(at) / sin (a - at)

fmatak has this as being d/e. If you reverse the 'polarity', it all works:

Here is my code showing it working, I hope (been wrong so many times in this lol): :)


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

	float b = d/e;
	float brack = CoSinF(a) / (b + CoCosF(a));
	float t = CoATanF(brack);
	t /= a;

	OutFloat("t is ", t);

	float proofLHS = CoSinF(a*t) * d;
	float proofRHS = CoSinF(a*(1.0f-t)) * e;

	OutFloat("LHS ", proofLHS);
	OutFloat("RHS ", proofRHS);

t is 0.573

LHS is 0.474

RHS is 0.474

Wow ... just seen mine has ended up exact same as Dirk's!! All this maths stuff does work lol. :)

I'll try and put up how I got to it.


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

// Divide both sides by e
// Divide both by sin(at)
d/e = sin(a - at) / sin (at)

// Let b = d/e
b = sin(a - at) / sin (at)
  
// Expand sin(a-at) to sin(a)*cos(at) - cos(a)*sin(at)
b = (sin(a) * cos(at) - cos(a) * sin(at)) / sin(at)

// Cotangent(x) = cos(x) / sin(x)
b = sin(a) * cot(at) - cos(a)

// Rearrange to get at on one side
cot(at) = (b + cos(a)) / sin(a)

// Cotangent is defined as: cot = 1 / tan(x)
1/tan(at) = (b + cos(a)) / sin(a)

// Multiply both sides by tan(at)
1 = ((b + cos(a)) / sin(a)) * tan(at)

// Divide by (b + cos(a)) / sin(a)
tan(at) = 1 / ((b + cos(a)) / sin(a))

// 1 / something / sin(a) same as sin(a) / something
tan(at) = sin(a) / (b + cos(a))
  
// Remove the tan
at = atan (sin(a) / (b + cos(a)))

// Divide by a
t = (atan(sin(a) / (b + cos(a)))) / a

 

To bring t in the [0,1] range:

k = atan( sin(a) / (d/e + cos(a)) )
if (k<0) k += PI
t = k / a

This topic is closed to new replies.

Advertisement