Trigonometry: tangent finding

A place where you can chat about anything that isn't to do with games!
Post Reply
User avatar
louisg
Posts: 2897
Joined: Wed Jul 20, 2005 7:27 pm
Location: outer richmond
Contact:

Trigonometry: tangent finding

Post by louisg »

Hey, so I was working on a graphics trick, and I found this:

Tangent is undefined at pi/2.. ok, that's obvious; cos is 0, so it's undefined

But:
tan((pi/2) - (1/128)) =~ 128
tan((pi/2) - (1/64)) =~ 64
tan((pi/2) - (1/200)) =~ 200
tan((pi/2) - (1/1010)) =~ 1010

.. and so on

This is really useful, but.. why does it happen? It's been years for me since a math class, so I'm hoping one of you science people on the forum can help :)
Humans, think about what you have done
User avatar
austere
Posts: 680
Joined: Mon Mar 22, 2010 10:50 am
Location: USA

Re: Trigonometry: tangent finding

Post by austere »

While I'm still waiting for breakfast to be prepared:

tan(pi/2 + x) = sin(pi/2 + x)/cos(pi/2 + x)
However, sin(pi/2 + x) = cos(x) and cos(pi/2 + x) = -sin(x)
i.e. tan(pi/2 + x) = - cos(x)/sin(x)

Let x be small. Then a first order approximation for cos(x) is just 1, while a first order approximation for sin(x) is x. i.e.

tan(pi/2 + x) = -1/x => tan(pi/2 - x) = 1/x => (EDIT: sub 1/x into x, i.e. x large) tan(pi/2 - 1/x) = x

Nothing to it. The real question is, how is this useful?
<RegalSin> It does not matter, which programming language you use, you will be up your neck in math.
User avatar
RNGmaster
Posts: 2388
Joined: Mon Aug 02, 2010 9:08 pm
Location: Seattle, WA

Re: Trigonometry: tangent finding

Post by RNGmaster »

It's an identity function - it can be used to find reciprocals without taking 1/x. And it's also freaking cool.
Identity functions can be used for all sorts of proofs, so yeah.
User avatar
austere
Posts: 680
Joined: Mon Mar 22, 2010 10:50 am
Location: USA

Re: Trigonometry: tangent finding

Post by austere »

This is an approximation not a trigonometric identity. An identity function maps every value in its range to the same value.

-- So, yeah.
<RegalSin> It does not matter, which programming language you use, you will be up your neck in math.
User avatar
louisg
Posts: 2897
Joined: Wed Jul 20, 2005 7:27 pm
Location: outer richmond
Contact:

Re: Trigonometry: tangent finding

Post by louisg »

austere wrote: Nothing to it. The real question is, how is this useful?
Hopefully this makes sense (been recovering from a cold)...

I was playing with mode 7 style perspective.. assuming that each row of the screen is a different viewing angle (ala raycasting), tana = z/h (where z=distance "into" the screen and h is the height the camera is above the ground) => h*tana = z. From there, I needed to figure out the maximum viewing distance. If angle=0 is straight down at the ground and 90-degrees is the horizon, the maximum distance viewable would be just-under-90-degrees. If I know by how much, that same value can also double as the maximum viewing distance without any (or too much) additional calculation.
Humans, think about what you have done
User avatar
austere
Posts: 680
Joined: Mon Mar 22, 2010 10:50 am
Location: USA

Re: Trigonometry: tangent finding

Post by austere »

I see. You could just use cotan, btw.
<RegalSin> It does not matter, which programming language you use, you will be up your neck in math.
User avatar
louisg
Posts: 2897
Joined: Wed Jul 20, 2005 7:27 pm
Location: outer richmond
Contact:

Re: Trigonometry: tangent finding

Post by louisg »

austere wrote:I see. You could just use cotan, btw.
Yeah, I don't think I'll have to do it dynamically. It just relates directly to the table size. For example, if you have a tangent table with 256 entries, then it's handy to know that the highest value in the table under the horizon (90 degrees) is 256!
Humans, think about what you have done
Post Reply