# Trig help on unit square

1. Jul 8, 2013

### JazzMasterKC

0. The app does not have the template built in so ill do my best, sorry i dont have a computer right now.

1. This is a personal project, and there is a lot to it but I'm cutting out down to where i need help.

Imagine a 2x2 grid of squares (2d for now). The center vector is at (0,0), and the length of one side of a square is 1m (or just think of one, distance doesnt matter right now). So essentially the grid is 2m by 2m. Now a arrow/line is abstract so it can help us meassure the distance from the center to a point on the outer rim of the grid.. in otherwords think of this like the unit circle (trig) but in a square... This is actually the direction where an object will be projected but thats unrelated to my question.

2. So what i wanted was to obtain that length of arrow/line and actually the cordinates on the grid.. i can figure that out easily because im given the angle of the arrow.. and yes so if the arrow is at the cordinate (0,1) that is a 90 degree angle. I can use a triangle for reference but since its a square i cant seem to figure out how to write a function that can pull this off from 0 degrees to 360.. every 45 degrees i have to switch which function it will use.. and I been using the tool of sin(A)/a=sin(B)/b.. as well as soh-cah-toa because i use the right angle to help me find the distance of the arrow.

3. So my question is how can i make this into one function rather then 8 different ones that switch after x amount of degrees. This is also a computer program so id like to keep it optimal.. my math course is entering calc 1 this fall so pre-calc.. I wonder if I'm not seeing something or is there other tools avaliable to help me figure this out?

Thanks

2. Jul 8, 2013

### BucketOfFish

This should return the length for any angle:

sec[{(1-2*floor[(x%90)/45])*x}%90],

where x is your angle in degrees, % is the modulus function, floor returns the next lowest integer, and sec is the secant function.

I would have a hard time explaining this without drawing a picture, but here goes... The distance to the edge of the unit square can always be expressed as 1/cos(q)=sec(q), where q is an angle between 0 and 45. This value should rise from 0-45 as x goes from 0-45, fall from 45-0 as x goes from 45-90, and so on. Can you see this? A picture would help. Anyway, the expression (1-2*floor[(x%90)/45]) is equal to 1 when x is from 0-45, 90-135, etc. and equal to -1 when x is from 45-90, 135-180, etc. Then {(1-2*floor[(x%90)/45])*x}%90 ends up creating the required graph for q.

Last edited: Jul 8, 2013
3. Jul 9, 2013

### JazzMasterKC

Wow good idea thanks a lot!