Re: trig
- Posted by Lewis Townsend <keroltarr at hotmail.com> Apr 18, 2004
- 653 views
Okay, Maybe I need to explain myself better: I have broken up the circle (360 deg) into 16 equal angles; each 22.5 degrees. I have a sequence of these angles: {0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5} >From that I have evaluated 16 {x,y} vectors with the following formula: { sin (angle), cos (angle) } The above is simplified for readability; degree/radian conversion is done separately. This produces the following sequence <approximately> {{0,1},{0.383,0.924},{0.707,0.707},{0.924,0.383},{1,0},{0.924,-0.383},{0.707,-0.707},{0.383,-0.924},{0,-1},{-0.383,-0.924},{-0.707,-0.707},{-0.924,-0.383},{-1,0},{-0.924,0.383},{-0.707,0.707},{-0.383,0.924}} I want to recognize any random {x,y} vector as its closest match in the list. I can scale any vector to a distance of 1 with the following code: dir = random_vector --{x,y} dist = sqrt(power(dir[1],2)+power(dir[2],2)) if dist != 1 then dir[1] = dir[1] * 1 / dist dir[2] = dir[2] * 1 / dist end if The question is how do I find its closest match in either the vector list or the angle list. All I need is an element number.