Re: Help with "facing" routine

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

Einar Mogen wrote:
>I have a total of 24 facings, the first
>one being directly up, the second 15 degrees to the right,
>the second <third> 30 degrees to the right, and so on.

i see a few things that are problems so far...
since you mention 'the first one being up' i'll assume
you are working in 3d??? no? if you are then 24 facings
isn't enough...what about upAND30 (as opposed to your
current of up OR 15 OR 30 OR 45 ... OR down)
what if the Zaxis only differs by like 1, then
the facing will be up/down when you really want
a facing along X,Y axis per degree rotation.
secondly, 24 facings still isnt enough for 3d.
this is the list of angles as you specified:
15,30,45,60,
75,90,105,120,
135,150,165,180,
195,210,225,240,
255,270,285,300,
315,330,345,360
now if you note, '0' zero, is not included there.
if '0' is up, then so will be 360, since the trig
formulas will say those are equal.
also, suppose the angle comes back as 359. rounding would make
that 360, but that is -down- (supposedly) as opposed to
the desired 345.

now if it is 2d, the routines become easier, rounding will
work, and 0 versus 360 wont matter. :)
(i -say- easier...;) )

function determine_facing(sequence char_pos, sequence point)
   -- find the closest match of the 24 possibilites
   -- format: char_pos = {x,y} point = {x,y}
   --         facing = -pi/2 to pi/2 radians
   constant xi = 1 --X axis index
   constant yi = 2 --Y axis index
   atom facing
   --compute rise/run AKA opposite/adjacent
   facing = (char_pos[yi]-point[yi]) / (char_pos[xi]-point[xi])
   --find angle in radians
   facing = arctan( facing )
   return facing
end function

the above -wont- work for you. it's simply an outline
of what needs to be done. arctan only handles 0 to 180
(actually -pi/2 to pi/2 which is -90 to +90) so it
will only give you 12 of the 24 facings...

happy coding--Hawke'

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

Search



Quick Links

User menu

Not signed in.

Misc Menu