Re: Help please: VFP function to calculate direction in degrees by MichelRoy
MichelRoy
Tue Nov 29 22:29:03 CST 2005
Actually, i'm suprised you did not point out that the degrees were not
calculated in the right direction. looking at a compass, and different
internet sites, 0 degree is supposed to be north, and goes up clockwise. so
the adjusted code that displays degree and cardinal point is:
SET DECIMALS TO 15
oo = CREATEOBJECT("oForm")
oo.SHOW(1)
DEFINE CLASS oForm AS FORM
WINDOWSTATE = 2
nx1 = 0
ny1 = 0
ADD OBJECT oHorzLine AS LINE
ADD OBJECT oVertLine AS LINE
ADD OBJECT oconnectline AS LINE
ADD OBJECT oLabel AS LABEL WITH ;
CAPTION="" ,;
AUTOSIZE = .T.
PROCEDURE ACTIVATE
THIS.nx1 = INT(THIS.WIDTH / 2)
THIS.ny1 = INT(THIS.HEIGHT / 2)
THIS.oHorzLine.MOVE(0,THIS.ny1,THIS.WIDTH,0)
THIS.oVertLine.MOVE(THIS.nx1,0,0,THIS.HEIGHT)
ENDPROC
PROCEDURE MOUSEMOVE(a,b,nx2,ny2)
THISFORM.LOCKSCREEN=.T.
WITH THIS.oconnectline
.LINESLANT = IIF(SIGN((nx2-THIS.nx1)/(ny2-THIS.ny1)) > 0,"\","/")
.MOVE(MIN(THIS.nx1,nx2),MIN(THIS.ny1,ny2),ABS(nx2-THIS.nx1),ABS(ny2-THIS.ny1))
ENDWITH
nDegree =
ROUND(MOD(270+RTOD(ATN2((THIS.ny1-ny2),(THIS.nx1-nx2))),360),1)
nQuadrant = INT(MOD((nDegree+(360/16/2)),360)/(360/16)+1)
cDir =
STREXTRACT(",N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW,",",",",",nQuadrant)
WITH THIS.oLabel
.CAPTION = TRANSFORM(nDegree) + " " + cDir
.MOVE(nx2+IIF(nx2<THIS.nx1,-(.WIDTH+5),+10),ny2,.HEIGHT,.WIDTH)
ENDWITH
THISFORM.LOCKSCREEN=.F.
DOEVENTS
ENDPROC
ENDDEFINE
"Gene Wirchenko" wrote:
> [reordered to chronological]
>
> On Tue, 29 Nov 2005 15:17:02 -0800, "Michel Roy"
> <MichelRoy@discussions.microsoft.com> wrote:
>
> >"Gene Wirchenko" wrote:
> >
> >> On Tue, 29 Nov 2005 20:27:55 GMT, "Ben" <nospam@nospam.com> wrote:
> >>
> >> >Yeah I see that, very nice and clean. Thanks Michel.
> >>
> >> It is *not* clean if i18n has to be done.
> >>
> >> [snip]
>
> >???? what is i18n? did i miss something?
>
> "internationalisation" or "internationalization". It is much
> easier to translate if the strings do not have coding dependencies.
> The code would break in another language if the abbreviations were
> shorter or longer in that language.
>
> Sincerely,
>
> Gene Wirchenko
>
>