Re: trig

new topic     » goto parent     » topic index » view thread      » older message » newer message

Lewis Townsend wrote:
> 
> 
> 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.

Lewis,
I imagine that you could do this:
1 - take random x,y vector and convert to an angle
2 - normalize that angle so 0 to 360 deg becomes 0.0 to 1.0
3 - multiply this result by the length of the angle list (in this case 16)
4 - maybe do some bounds checking, blah blah, blah...

Regards,
Mike

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu