>Hi Ashley, > >There is one zero-division problem in your implementation:- >Indeed, if SL# is almost 0 (ie, if the mosquito is near the tip of the >teepee) >then your calculation of phi# overflows. >(SC# is not nearly zero by assumption, I presume.) > >The quickest fix is to replace your phi# calculation by: > >eps#=.00001 ''(adjust this) > >LONG IF (SL# * SC#) > eps# > phi# = acos(SLSC# / (SL# * SC#)) ''<== there was a missing paren here?? >XELSE > phi# = pi# ''<== cooked to say mosquito outside >END IF > >For a faster cleaner program, I would entirely avoid >angles and trig as follows. Let costheta# be given (= cos(theta#)). > >SLcosphi# = SLSC# / SC# >SLcostheta# = SL# * costheta# > >long if (SLcosphi# > 0) and (SLcosphi# <= SC#) and (SLcosphi# > SLcostheta#) > '' explain the last condition! >inCone = _zTrue >xelse >inCone = _false >end if > >You might now run a test by having NASA create mosquitos a random >and use the above to plot mosquitos appearing in the teepee. >Use a projection to screen to get visuals that we can all enjoy... > >Cheers > >ls Laurent and others, I have now tried a lot of your suggestions and none of them seem to be working. Below is the entire function. For the purposes of this function the locateSatBlock record has within it two records, position which has three fields X#,Y#,Z# and location which has three fields latitude#,longitude# and altitude#. although the later currently isn't used. gLocation is a record containing three fields latitude#,longitude# and altitude#. Some sample data might be for instance gLocation is Sydney, latitude = -33.55,longitude = 151.1 and altitude of 0 and the satellite is at latitude = -27.072696959,longitude = 150.930585575 and altitude = 21822.514906482 and X# = -170590.3929, Y# = 94830.15463 and Z# = -99759.49368 (please note that this X,Y and Z were calculated on my calculator from this lat,long and alt). By the way the earth radius used is 6371 and all measures are in kilometers ie X# = -170590.3929 is that many kilometers from the center of the earth. local fn locationInSatCone(locatePBlk as ptr to locateSatBlock,objAngle#) //Get Stations Latitude, Longitude and Altitude from var longitude# = gLocation.longitude# latitude# = gLocation.latitude# altitude# = gLocation.altitude# //Convert station data to correct quantaties ie degs to rads latitude# = latitude# * pi#/180 longitude# = longitude# * pi#/180 //Get the correct radius for the sphere (earth + altitude) lrad# = _earthRadius + altitude# //Get the X,Y,Z Coordinates of the station lZ# = lrad# * sin(latitude#) nrad# = lrad# * cos(latitude#) lX# = nrad# * cos(longitude#) lY# = nrad# * sin(longitude#) longitude# = fn XYZ2Lon#(lX#,lY#,lZ#) latitude# = fn XYZ2Lat#(lX#,lY#,lZ#) altitude# = fn XYZ2Alt#(lX#,lY#,lZ#) //Get the Satellites XYZ sX# = locatePBlk.position.X# sY# = locatePBlk.position.Y# sZ# = locatePBlk.position.Z# //Convert the params to correct quantities ie degs to rads theta# = (objAngle#/2) * pi#/180 //Get the vectors between the points SLX# = lX#-sX# : SLY# = lY#-sY# : SLZ# = lZ#-sZ# SL# = sqr(SLX#^2 + SLY#^2 +SLZ#^2) SC# = sqr(sX#^2 + sY#^2 + sZ#^2) SLSC# = SLX#*sX# + SLY#*sY# + SLZ#*sZ# costheta# = cos(theta#) SLcosphi# = SLSC# / SC# SLcostheta# = SL# * costheta# long if (SLcosphi# > 0) and (SLcosphi# <= SC#) and (SLcosphi# > SLcostheta#) '' explain the last condition! inCone = _zTrue xelse inCone = _false end if end fn = inCone Thanks for the help, Regards, Ashley ~)~ ============================================================= Ashley Butterworth Email: macbse@... ============================================================= _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com