1. Re: Help with "facing" routine Oops

Hi
The first attempt at this didn't work very well.
This one works better.

>>>Start code
atom theta
constant PI=3.141592654
constant X=1
constant Y=2

function sangle(atom dx, atom dy)
    if dx=0 then
                 if dy<0 then
                             theta=3*PI/2
                         else
                             theta=PI/2
                 end if
             else theta = arctan(dy/dx)
     end if
     if (dx<0 and dy>0) then theta=PI+theta end if
     if (dx<0 and dy<0) then theta=PI+theta end if
     if (dx>0 and dy<0) then theta=2*PI+theta end if
return theta
end function

function Int(object x) return(x-remainder(x,1)) end function


function determine_facing(sequence char_pos, sequence point)
    -- find the closest match of the 24 possibilites
    integer numfacings
    atom facing
    atom angle
    facing=0
    numfacings=24
          angle =
          sangle((point[X]-char_pos[X]),(point[Y]-char_pos[Y])) if
          angle != 0 then facing = (angle/(2*PI))*numfacings end if
    return (Int(facing)+1) -- 1 to 24
end function

for x = 0 to 2*PI by PI/12 do
     ?determine_facing({cos(x),sin(x)},{0,0})
end for


>>>End Code
Bye
Martin

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu