I need help putting together a function where I pass four coordinates X1,
Y1, X2, Y2 and have it return direction in degree of angle from 0 to 360.
Didn't do too well in geometry!! Assume a flat X/Y plane. I need to know
what direction zero is (left, right, up, down).

Example of what I was thinking:

function WhatDirection(nX1, nY1, nX2, nY2)
nDegrees=0

*!* Geometry code to fill nDegrees here!

return nDegrees

Thanks for any help.

Re: Help please: VFP function to calculate direction in degrees by Olaf

Olaf
Mon Nov 28 17:01:27 CST 2005

? RToD(ATn2((nY2-nY1),(nX2-nX1)))

Disappointed that there is no PI() in it?

Deactivate IE security instead and have some
cookies ;-)

Bye, Olaf.



Re: Help please: VFP function to calculate direction in degrees by Ben

Ben
Mon Nov 28 17:45:46 CST 2005

thanks! I fished around some macth sites and found this if you want to take
a look. And....yep its lat/long so the circle thing has to be considered :)

This look correct to you?

y = sin(lon2-lon1)*cos(lat2)
x = cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)
if y > 0
if x > 0
tc1 = tan(y/x)
endif
if x < 0
tc1 = 180 - tan(-y/x)
endif
if x = 0
tc1 = 90
endif
endif
if y < 0
if x > 0
tc1 = - tan(-y/x)
endif
if x < 0
tc1 = tan(y/x)-180
endif
if x = 0
tc1 = 270
endif
endif
if y = 0
if x > 0
tc1 = 0
endif
if x < 0
tc1 = 180
endif
if x = 0
tc1 = 0 && [the 2 points are the same]
endif
endif




"Olaf Doschke" <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14
<T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14> wrote in message
news:e96Gb%23G9FHA.1276@TK2MSFTNGP09.phx.gbl...
>? RToD(ATn2((nY2-nY1),(nX2-nX1)))
>
> Disappointed that there is no PI() in it?
>
> Deactivate IE security instead and have some
> cookies ;-)
>
> Bye, Olaf.
>



Re: Help please: VFP function to calculate direction in degrees by Ben

Ben
Mon Nov 28 17:50:22 CST 2005

or this maybe??

tc1=rtod(atn2(sin(lon2-lon1)*cos(lat2),cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)))


"Ben" <nospam@nospam.com> wrote in message
news:KEMif.16$Dk.7@tornado.rdc-kc.rr.com...
> thanks! I fished around some macth sites and found this if you want to
> take a look. And....yep its lat/long so the circle thing has to be
> considered :)
>
> This look correct to you?
>
> y = sin(lon2-lon1)*cos(lat2)
> x = cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)
> if y > 0
> if x > 0
> tc1 = tan(y/x)
> endif
> if x < 0
> tc1 = 180 - tan(-y/x)
> endif
> if x = 0
> tc1 = 90
> endif
> endif
> if y < 0
> if x > 0
> tc1 = - tan(-y/x)
> endif
> if x < 0
> tc1 = tan(y/x)-180
> endif
> if x = 0
> tc1 = 270
> endif
> endif
> if y = 0
> if x > 0
> tc1 = 0
> endif
> if x < 0
> tc1 = 180
> endif
> if x = 0
> tc1 = 0 && [the 2 points are the same]
> endif
> endif
>
>
>
>
> "Olaf Doschke" <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14
> <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14> wrote in message
> news:e96Gb%23G9FHA.1276@TK2MSFTNGP09.phx.gbl...
>>? RToD(ATn2((nY2-nY1),(nX2-nX1)))
>>
>> Disappointed that there is no PI() in it?
>>
>> Deactivate IE security instead and have some
>> cookies ;-)
>>
>> Bye, Olaf.
>>
>
>



Re: Help please: VFP function to calculate direction in degrees by MichelRoy

MichelRoy
Mon Nov 28 18:06:02 CST 2005

try this. move the mouse around the screen to display degree

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

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)
WAIT WINDOW TRANSFORM(180-RTOD(ATN2((THIS.ny1-ny2),(THIS.nx1-nx2))))
NOWAIT
ENDPROC

ENDDEFINE


"Ben" wrote:

> or this maybe??
>
> tc1=rtod(atn2(sin(lon2-lon1)*cos(lat2),cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)))
>
>
> "Ben" <nospam@nospam.com> wrote in message
> news:KEMif.16$Dk.7@tornado.rdc-kc.rr.com...
> > thanks! I fished around some macth sites and found this if you want to
> > take a look. And....yep its lat/long so the circle thing has to be
> > considered :)
> >
> > This look correct to you?
> >
> > y = sin(lon2-lon1)*cos(lat2)
> > x = cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)
> > if y > 0
> > if x > 0
> > tc1 = tan(y/x)
> > endif
> > if x < 0
> > tc1 = 180 - tan(-y/x)
> > endif
> > if x = 0
> > tc1 = 90
> > endif
> > endif
> > if y < 0
> > if x > 0
> > tc1 = - tan(-y/x)
> > endif
> > if x < 0
> > tc1 = tan(y/x)-180
> > endif
> > if x = 0
> > tc1 = 270
> > endif
> > endif
> > if y = 0
> > if x > 0
> > tc1 = 0
> > endif
> > if x < 0
> > tc1 = 180
> > endif
> > if x = 0
> > tc1 = 0 && [the 2 points are the same]
> > endif
> > endif
> >
> >
> >
> >
> > "Olaf Doschke" <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14
> > <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14> wrote in message
> > news:e96Gb%23G9FHA.1276@TK2MSFTNGP09.phx.gbl...
> >>? RToD(ATn2((nY2-nY1),(nX2-nX1)))
> >>
> >> Disappointed that there is no PI() in it?
> >>
> >> Deactivate IE security instead and have some
> >> cookies ;-)
> >>
> >> Bye, Olaf.
> >>
> >
> >
>
>
>

Re: Help please: VFP function to calculate direction in degrees by Rick

Rick
Tue Nov 29 09:07:29 CST 2005

Michel,
Nicely done!

Rick

"Michel Roy" <MichelRoy@discussions.microsoft.com> wrote in message
news:9F658EB8-E120-450F-94CE-81A4504EEA00@microsoft.com...
> try this. move the mouse around the screen to display degree
>
> 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
>
> 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)
> WAIT WINDOW TRANSFORM(180-RTOD(ATN2((THIS.ny1-ny2),(THIS.nx1-nx2))))
> NOWAIT
> ENDPROC
>
> ENDDEFINE
>
>
> "Ben" wrote:
>
>> or this maybe??
>>
>> tc1=rtod(atn2(sin(lon2-lon1)*cos(lat2),cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)))
>>
>>
>> "Ben" <nospam@nospam.com> wrote in message
>> news:KEMif.16$Dk.7@tornado.rdc-kc.rr.com...
>> > thanks! I fished around some macth sites and found this if you want to
>> > take a look. And....yep its lat/long so the circle thing has to be
>> > considered :)
>> >
>> > This look correct to you?
>> >
>> > y = sin(lon2-lon1)*cos(lat2)
>> > x = cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)
>> > if y > 0
>> > if x > 0
>> > tc1 = tan(y/x)
>> > endif
>> > if x < 0
>> > tc1 = 180 - tan(-y/x)
>> > endif
>> > if x = 0
>> > tc1 = 90
>> > endif
>> > endif
>> > if y < 0
>> > if x > 0
>> > tc1 = - tan(-y/x)
>> > endif
>> > if x < 0
>> > tc1 = tan(y/x)-180
>> > endif
>> > if x = 0
>> > tc1 = 270
>> > endif
>> > endif
>> > if y = 0
>> > if x > 0
>> > tc1 = 0
>> > endif
>> > if x < 0
>> > tc1 = 180
>> > endif
>> > if x = 0
>> > tc1 = 0 && [the 2 points are the same]
>> > endif
>> > endif
>> >
>> >
>> >
>> >
>> > "Olaf Doschke" <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14
>> > <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14> wrote in message
>> > news:e96Gb%23G9FHA.1276@TK2MSFTNGP09.phx.gbl...
>> >>? RToD(ATn2((nY2-nY1),(nX2-nX1)))
>> >>
>> >> Disappointed that there is no PI() in it?
>> >>
>> >> Deactivate IE security instead and have some
>> >> cookies ;-)
>> >>
>> >> Bye, Olaf.
>> >>
>> >
>> >
>>
>>
>>


Re: Help please: VFP function to calculate direction in degrees by Ben

Ben
Tue Nov 29 11:21:11 CST 2005

Thanks everyone. Here's what I ended up with:

****************************************************************************************************************
function CalcDirection(nX1,nY1,nX2,nY2) &&
cDirection=''
if nx1-nx2=0 and ny1-ny2=0
cDirection='*'
else
nDegrees=rtod(atn2((nY2-nY1),(nX2-nX1)))
do case
case nDegrees>=-22.5 and nDegrees<=22.5
cDirection='E'
case nDegrees>22.5 and nDegrees<=67.5
cDirection='NE'
case nDegrees>67.5 and nDegrees<=112.5
cDirection='N'
case nDegrees>112.5 and nDegrees<=157.5
cDirection='NW'
case nDegrees>157.5 or nDegrees<-157.5
cDirection='W'
case nDegrees<-22.5 and nDegrees>=-67.5
cDirection='SE'
case nDegrees<-67.5 and nDegrees>=-112.5
cDirection='S'
case nDegrees<-112.5 and nDegrees>=-157.5
cDirection='SW'
endcase
endif
return cDirection



"Rick Bean" <rgbean@unrealmelange-inc.com> wrote in message
news:evNmeaP9FHA.1148@tk2msftngp13.phx.gbl...
> Michel,
> Nicely done!
>
> Rick
>
> "Michel Roy" <MichelRoy@discussions.microsoft.com> wrote in message
> news:9F658EB8-E120-450F-94CE-81A4504EEA00@microsoft.com...
>> try this. move the mouse around the screen to display degree
>>
>> 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
>>
>> 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)
>> WAIT WINDOW TRANSFORM(180-RTOD(ATN2((THIS.ny1-ny2),(THIS.nx1-nx2))))
>> NOWAIT
>> ENDPROC
>>
>> ENDDEFINE
>>
>>
>> "Ben" wrote:
>>
>>> or this maybe??
>>>
>>> tc1=rtod(atn2(sin(lon2-lon1)*cos(lat2),cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)))
>>>
>>>
>>> "Ben" <nospam@nospam.com> wrote in message
>>> news:KEMif.16$Dk.7@tornado.rdc-kc.rr.com...
>>> > thanks! I fished around some macth sites and found this if you want
>>> > to
>>> > take a look. And....yep its lat/long so the circle thing has to be
>>> > considered :)
>>> >
>>> > This look correct to you?
>>> >
>>> > y = sin(lon2-lon1)*cos(lat2)
>>> > x = cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)
>>> > if y > 0
>>> > if x > 0
>>> > tc1 = tan(y/x)
>>> > endif
>>> > if x < 0
>>> > tc1 = 180 - tan(-y/x)
>>> > endif
>>> > if x = 0
>>> > tc1 = 90
>>> > endif
>>> > endif
>>> > if y < 0
>>> > if x > 0
>>> > tc1 = - tan(-y/x)
>>> > endif
>>> > if x < 0
>>> > tc1 = tan(y/x)-180
>>> > endif
>>> > if x = 0
>>> > tc1 = 270
>>> > endif
>>> > endif
>>> > if y = 0
>>> > if x > 0
>>> > tc1 = 0
>>> > endif
>>> > if x < 0
>>> > tc1 = 180
>>> > endif
>>> > if x = 0
>>> > tc1 = 0 && [the 2 points are the same]
>>> > endif
>>> > endif
>>> >
>>> >
>>> >
>>> >
>>> > "Olaf Doschke" <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14
>>> > <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14> wrote in message
>>> > news:e96Gb%23G9FHA.1276@TK2MSFTNGP09.phx.gbl...
>>> >>? RToD(ATn2((nY2-nY1),(nX2-nX1)))
>>> >>
>>> >> Disappointed that there is no PI() in it?
>>> >>
>>> >> Deactivate IE security instead and have some
>>> >> cookies ;-)
>>> >>
>>> >> Bye, Olaf.
>>> >>
>>> >
>>> >
>>>
>>>
>>>
>



Re: Help please: VFP function to calculate direction in degrees by Olaf

Olaf
Tue Nov 29 12:42:01 CST 2005

> y = sin(lon2-lon1)*cos(lat2)
> x = cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)
seems okay

> if y > 0
> if x > 0
> tc1 = tan(y/x)
> endif
should be ATan, not Tan. Tan takes a angle as input and returns
the tangent. That is wrong.
...
All this code just prevents the special cases where y/x doesn't work,
because x=0 or y=0

With atn2() you only need to take care of atn(0,0), like you
did in your final solution. That's just fine...

Bye, Olaf.



Re: Help please: VFP function to calculate direction in degrees by MichelRoy

MichelRoy
Tue Nov 29 13:57:04 CST 2005

you could have done this also.
nDegree = ROUND(180-RTOD(ATN2((ny1-ny2),(nx1-nx2))),1)
ddegree = MOD((ndegree+11.25),360) && adjust pie slice
cDir = SUBSTR("E ENE NE NNE N NNW NW WNW W WSW SW SSW S SSE SE
ESE ",INT(dDegree/(360/16)+1)*4-3,4)


"Ben" wrote:

> Thanks everyone. Here's what I ended up with:
>
> ****************************************************************************************************************
> function CalcDirection(nX1,nY1,nX2,nY2) &&
> cDirection=''
> if nx1-nx2=0 and ny1-ny2=0
> cDirection='*'
> else
> nDegrees=rtod(atn2((nY2-nY1),(nX2-nX1)))
> do case
> case nDegrees>=-22.5 and nDegrees<=22.5
> cDirection='E'
> case nDegrees>22.5 and nDegrees<=67.5
> cDirection='NE'
> case nDegrees>67.5 and nDegrees<=112.5
> cDirection='N'
> case nDegrees>112.5 and nDegrees<=157.5
> cDirection='NW'
> case nDegrees>157.5 or nDegrees<-157.5
> cDirection='W'
> case nDegrees<-22.5 and nDegrees>=-67.5
> cDirection='SE'
> case nDegrees<-67.5 and nDegrees>=-112.5
> cDirection='S'
> case nDegrees<-112.5 and nDegrees>=-157.5
> cDirection='SW'
> endcase
> endif
> return cDirection
>
>
>
> "Rick Bean" <rgbean@unrealmelange-inc.com> wrote in message
> news:evNmeaP9FHA.1148@tk2msftngp13.phx.gbl...
> > Michel,
> > Nicely done!
> >
> > Rick
> >
> > "Michel Roy" <MichelRoy@discussions.microsoft.com> wrote in message
> > news:9F658EB8-E120-450F-94CE-81A4504EEA00@microsoft.com...
> >> try this. move the mouse around the screen to display degree
> >>
> >> 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
> >>
> >> 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)
> >> WAIT WINDOW TRANSFORM(180-RTOD(ATN2((THIS.ny1-ny2),(THIS.nx1-nx2))))
> >> NOWAIT
> >> ENDPROC
> >>
> >> ENDDEFINE
> >>
> >>
> >> "Ben" wrote:
> >>
> >>> or this maybe??
> >>>
> >>> tc1=rtod(atn2(sin(lon2-lon1)*cos(lat2),cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)))
> >>>
> >>>
> >>> "Ben" <nospam@nospam.com> wrote in message
> >>> news:KEMif.16$Dk.7@tornado.rdc-kc.rr.com...
> >>> > thanks! I fished around some macth sites and found this if you want
> >>> > to
> >>> > take a look. And....yep its lat/long so the circle thing has to be
> >>> > considered :)
> >>> >
> >>> > This look correct to you?
> >>> >
> >>> > y = sin(lon2-lon1)*cos(lat2)
> >>> > x = cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)
> >>> > if y > 0
> >>> > if x > 0
> >>> > tc1 = tan(y/x)
> >>> > endif
> >>> > if x < 0
> >>> > tc1 = 180 - tan(-y/x)
> >>> > endif
> >>> > if x = 0
> >>> > tc1 = 90
> >>> > endif
> >>> > endif
> >>> > if y < 0
> >>> > if x > 0
> >>> > tc1 = - tan(-y/x)
> >>> > endif
> >>> > if x < 0
> >>> > tc1 = tan(y/x)-180
> >>> > endif
> >>> > if x = 0
> >>> > tc1 = 270
> >>> > endif
> >>> > endif
> >>> > if y = 0
> >>> > if x > 0
> >>> > tc1 = 0
> >>> > endif
> >>> > if x < 0
> >>> > tc1 = 180
> >>> > endif
> >>> > if x = 0
> >>> > tc1 = 0 && [the 2 points are the same]
> >>> > endif
> >>> > endif
> >>> >
> >>> >
> >>> >
> >>> >
> >>> > "Olaf Doschke" <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14
> >>> > <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14> wrote in message
> >>> > news:e96Gb%23G9FHA.1276@TK2MSFTNGP09.phx.gbl...
> >>> >>? RToD(ATn2((nY2-nY1),(nX2-nX1)))
> >>> >>
> >>> >> Disappointed that there is no PI() in it?
> >>> >>
> >>> >> Deactivate IE security instead and have some
> >>> >> cookies ;-)
> >>> >>
> >>> >> Bye, Olaf.
> >>> >>
> >>> >
> >>> >
> >>>
> >>>
> >>>
> >
>
>
>

Re: Help please: VFP function to calculate direction in degrees by Ben

Ben
Tue Nov 29 14:27:55 CST 2005

Yeah I see that, very nice and clean. Thanks Michel.

"Michel Roy" <MichelRoy@discussions.microsoft.com> wrote in message
news:1BAE19F3-B6FC-4512-88E3-B22348020241@microsoft.com...
> you could have done this also.
> nDegree = ROUND(180-RTOD(ATN2((ny1-ny2),(nx1-nx2))),1)
> ddegree = MOD((ndegree+11.25),360) && adjust pie slice
> cDir = SUBSTR("E ENE NE NNE N NNW NW WNW W WSW SW SSW S SSE SE
> ESE ",INT(dDegree/(360/16)+1)*4-3,4)
>
>
> "Ben" wrote:
>
>> Thanks everyone. Here's what I ended up with:
>>
>> ****************************************************************************************************************
>> function CalcDirection(nX1,nY1,nX2,nY2) &&
>> cDirection=''
>> if nx1-nx2=0 and ny1-ny2=0
>> cDirection='*'
>> else
>> nDegrees=rtod(atn2((nY2-nY1),(nX2-nX1)))
>> do case
>> case nDegrees>=-22.5 and nDegrees<=22.5
>> cDirection='E'
>> case nDegrees>22.5 and nDegrees<=67.5
>> cDirection='NE'
>> case nDegrees>67.5 and nDegrees<=112.5
>> cDirection='N'
>> case nDegrees>112.5 and nDegrees<=157.5
>> cDirection='NW'
>> case nDegrees>157.5 or nDegrees<-157.5
>> cDirection='W'
>> case nDegrees<-22.5 and nDegrees>=-67.5
>> cDirection='SE'
>> case nDegrees<-67.5 and nDegrees>=-112.5
>> cDirection='S'
>> case nDegrees<-112.5 and nDegrees>=-157.5
>> cDirection='SW'
>> endcase
>> endif
>> return cDirection
>>
>>
>>
>> "Rick Bean" <rgbean@unrealmelange-inc.com> wrote in message
>> news:evNmeaP9FHA.1148@tk2msftngp13.phx.gbl...
>> > Michel,
>> > Nicely done!
>> >
>> > Rick
>> >
>> > "Michel Roy" <MichelRoy@discussions.microsoft.com> wrote in message
>> > news:9F658EB8-E120-450F-94CE-81A4504EEA00@microsoft.com...
>> >> try this. move the mouse around the screen to display degree
>> >>
>> >> 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
>> >>
>> >> 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)
>> >> WAIT WINDOW
>> >> TRANSFORM(180-RTOD(ATN2((THIS.ny1-ny2),(THIS.nx1-nx2))))
>> >> NOWAIT
>> >> ENDPROC
>> >>
>> >> ENDDEFINE
>> >>
>> >>
>> >> "Ben" wrote:
>> >>
>> >>> or this maybe??
>> >>>
>> >>> tc1=rtod(atn2(sin(lon2-lon1)*cos(lat2),cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)))
>> >>>
>> >>>
>> >>> "Ben" <nospam@nospam.com> wrote in message
>> >>> news:KEMif.16$Dk.7@tornado.rdc-kc.rr.com...
>> >>> > thanks! I fished around some macth sites and found this if you
>> >>> > want
>> >>> > to
>> >>> > take a look. And....yep its lat/long so the circle thing has to be
>> >>> > considered :)
>> >>> >
>> >>> > This look correct to you?
>> >>> >
>> >>> > y = sin(lon2-lon1)*cos(lat2)
>> >>> > x = cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)
>> >>> > if y > 0
>> >>> > if x > 0
>> >>> > tc1 = tan(y/x)
>> >>> > endif
>> >>> > if x < 0
>> >>> > tc1 = 180 - tan(-y/x)
>> >>> > endif
>> >>> > if x = 0
>> >>> > tc1 = 90
>> >>> > endif
>> >>> > endif
>> >>> > if y < 0
>> >>> > if x > 0
>> >>> > tc1 = - tan(-y/x)
>> >>> > endif
>> >>> > if x < 0
>> >>> > tc1 = tan(y/x)-180
>> >>> > endif
>> >>> > if x = 0
>> >>> > tc1 = 270
>> >>> > endif
>> >>> > endif
>> >>> > if y = 0
>> >>> > if x > 0
>> >>> > tc1 = 0
>> >>> > endif
>> >>> > if x < 0
>> >>> > tc1 = 180
>> >>> > endif
>> >>> > if x = 0
>> >>> > tc1 = 0 && [the 2 points are the same]
>> >>> > endif
>> >>> > endif
>> >>> >
>> >>> >
>> >>> >
>> >>> >
>> >>> > "Olaf Doschke" <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14
>> >>> > <T2xhZi5Eb3NjaGtlQFNldG1pY3MuZGU@strconv.14> wrote in message
>> >>> > news:e96Gb%23G9FHA.1276@TK2MSFTNGP09.phx.gbl...
>> >>> >>? RToD(ATn2((nY2-nY1),(nX2-nX1)))
>> >>> >>
>> >>> >> Disappointed that there is no PI() in it?
>> >>> >>
>> >>> >> Deactivate IE security instead and have some
>> >>> >> cookies ;-)
>> >>> >>
>> >>> >> Bye, Olaf.
>> >>> >>
>> >>> >
>> >>> >
>> >>>
>> >>>
>> >>>
>> >
>>
>>
>>



Re: Help please: VFP function to calculate direction in degrees by Gene

Gene
Tue Nov 29 16:37:09 CST 2005

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]

Sincerely,

Gene Wirchenko


Re: Help please: VFP function to calculate direction in degrees by MichelRoy

MichelRoy
Tue Nov 29 17:17:02 CST 2005

???? what is i18n? did i miss something?

"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]
>
> Sincerely,
>
> Gene Wirchenko
>
>

Re: Help please: VFP function to calculate direction in degrees by Gene

Gene
Tue Nov 29 17:30:50 CST 2005

[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


Re: Help please: VFP function to calculate direction in degrees by MichelRoy

MichelRoy
Tue Nov 29 18:59:03 CST 2005

would you prefer:
CardinalPoints = ",E,ENE,NE,NNE,N,NNW,NW,WNW,W,WSW,SW,SSW,S,SSE,SE,ESE,"
...
RETURN STREXTRACT(CardinalPoints,",",",",INT(dDegree/(360/16)+1))

or do i have to also test for double-byte characters?

"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
>
>

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
>
>