Re: submarine commander project
- Posted by don cole <doncole at pacbell??et> Dec 10, 2007
- 521 views
David Money wrote: [snip] > > I would include the conversions in the functions, so you could use your > 0~3600 angle directly. Something like this: > > <code> > constant PI=3.1415926535893238 --or include misc.e > > function p2xy(atom r,atom sec) > --r is distance, sec is angle (seconds after hour, measured from 12 o'clock) > atom a > a=sec*PI/1800 --convert to radians > return {r*sin(a),-r*cos(a)} > end function > > function vector(sequence pt1,sequence pt2) > --distance and angle from pt1 to pt2 > integer dx,dy > atom r,a > dx=floor(pt2[1]-pt1[1]) > dy=floor(pt2[2]-pt1[2]) > r=sqrt(dx*dx+dy*dy) > if r=0 then > return {0,0} > end if > if dy<0 then > if dx<0 then > a=2*PI-arctan(dx/dy) > else > a=-arctan(dx/dy) > end if > elsif dy>0 then > a=PI-arctan(dx/dy) > else --dy=0 (one point above the other); can't use arctan formula > if dx<0 then > a=3*PI/2 > else > a=PI/2 > end if > end if > return {r,1800*a/PI} --convert radians to decidegrees > end function > </code> > > The arctan function just works for -pi/2 to pi/2, so you have to figure > out which quadrant you are in, and offset it. Also, you have to avoid > dividing by zero. If r=0, the points are the same; the function will return > 0 for the angle, too, but it's really undefined. > You had two minus signs in your function--was that a typo? That would work > for conventional angle measurements (counterclockwise), but it would make > your clock run backwards. > --David Thank you David for responding, That sould about do it. I'll try it soon. That was not a typo I got it from chessclock in the archives. I corrected the problem with: for x=3600 to 1 by -1 do Don Cole