4 Replies Latest reply on Dec 14, 2012 7:54 PM by Rothrock

# Anybody good at trig identities?

var d:Number = // a distance

var h:Number = // a height (I know it should be hypotenuse, but it isn't really)

var n:Number = // a number running from 0 to 1 in various small increments

var newX:Number = -h + d*Math.tan(Math.atan(h/d) + 2*n*Math.asin(1/(2*Math.sqrt(d*d + h*h))

I know I can make it look cleaner by breaking it out into some other variables. And it works just fine. I'm not trying to optimize it for speed or anything. It was way messier yesterday and I did figure out some stuff to make it nicer,  but I'm just wondering if there is some trig identity genius out there who sees an even tidier way of formatting this.

In case you're wondering…I'm working on how to do anamorphic projections and this is the formula for projecting the x part.

• ###### 1. Re: Anybody good at trig identities?

that's not a valid expression.  there are mismatched parantheses.

• ###### 2. Re: Anybody good at trig identities?

var len:Number=Math.sqrt(d*d+h*h);

var angle:Number=Math.asin(1/(2*len))

var newX:Number = -h + d*Math.tan(Math.atan(h/d) + 2*n*angle)

So I only got one extra there. I need two more at the end.

var newX:Number = -h + d*Math.tan(Math.atan(h/d) + 2*n*Math.asin(1/(2*Math.sqrt(d*d + h*h))))

• ###### 3. Re: Anybody good at trig identities?

i don't think much can be done with that though this can be used:

var newX:Number=-h+(h+Math.tan(2*n*angle))/(d-h*Math.tan(2*n*angle))

if angle were Math.asin(d/Math.sqrt(d*d+h*h)) or Math.asin(h/Math.sqrt(d*d+h*h)) much more could be done.