[ncl-talk] understanding function gc_pnt2gc
Mary Haley
haley at ucar.edu
Fri Aug 11 13:51:12 MDT 2017
I've been looking into this too, and I've come to the tentative conclusion
that this function is doing the correct thing.
Joe, I think you're right that gc_pnt2gc uses the entire great circle
around the globe, and not just the shortest section between the points. If
you imagine slicing the globe at the great circle between the two lat,lon
pairs that you gave, then the distance will be the length of the line drawn
from your base point and perpendicular to the slice you just made.
On Thu, Aug 10, 2017 at 12:09 PM, Rick Brownrigg <brownrig at ucar.edu> wrote:
> I was looking at the source as well -- not easy to understand. The
> function gives the correct answer for some simple test cases (eg, GC along
> prime meridian and a test point equator 90-degrees away). But clearly a
> wrong answer for your case, and seems wrong if the routine is using the
> entire great circle (?)
>
>
>
> On Thu, Aug 10, 2017 at 10:41 AM, Joe Grim <grim at ucar.edu> wrote:
>
>> I wonder if gc_pnt2gc uses the entire great circle around the globe, and
>> not just the shortest section between the two points defining the great
>> circle, in calculating the distance.
>>
>> On Thu, Aug 10, 2017 at 10:39 AM, Joe Grim <grim at ucar.edu> wrote:
>>
>>> Alan,
>>>
>>> That is a great workaround for this problem! I'll try your approach
>>> unless I can find a way to get gc_pnt2gc to work the way I want it to.
>>>
>>> I looked up the source code, which is located at
>>> ncl/ni/src/lib/nfpfort/sg_tools.f, under FORTRAN function XDPGCDP, and
>>> was written by David Kennison. It would take me a while to figure it all
>>> out, so hopefully your workaround is fast enough for my purposes.
>>>
>>> Thanks again!
>>>
>>> Joe
>>>
>>> On Thu, Aug 10, 2017 at 9:55 AM, Alan Brammer <abrammer at albany.edu>
>>> wrote:
>>>
>>>> As another person who uses gc_latlon extensively but didn't know
>>>> gc_pnt2gc existed.
>>>>
>>>> You could use gc_latlon to recreate gc_pnt2gc(). Definitely seems like
>>>> that function is doing some weird stuff.
>>>> Though this wouldn't be directional but that could be worked out
>>>> relatively easily.
>>>>
>>>>
>>>>
>>>> p_lat = 41.6
>>>> p_lon = -76.84
>>>>
>>>> lat = (/52.9921,55.3543/)
>>>> lon = (/-168.693,-160.346/)
>>>> dist = gc_pnt2gc(p_lat,p_lon,lat,lon)
>>>>
>>>> line = gc_latlon( lat(0), lon(0), lat(1), lon(1), 1000, 2)
>>>> ;; create the GC path
>>>> distances = gc_latlon(p_lat, p_lon, line at gclat, line at gclon, 0, 2) ;;
>>>> find distances to GC path
>>>> shortest = minind(distances)
>>>>
>>>> print ("The gc_pnt2gc distance is: " + dist)
>>>> print ("The gc_latlon distance is: " + distances(shortest) )
>>>>
>>>> ; The gc_pnt2gc distance is: -0.105952
>>>> ; The gc_latlon distance is: 53.5385
>>>>
>>>> On Thu, Aug 10, 2017 at 10:46 AM, Joe Grim <grim at ucar.edu> wrote:
>>>>
>>>>> Thank you, Dennis. Yes, I have used the gc_latlon function many
>>>>> times; it is very useful!
>>>>>
>>>>> But, I am hoping to use a function that finds the distance between a
>>>>> point, and where it is closest to a line. If I can't, I'll just have to
>>>>> write my own function in FORTRAN instead to do that.
>>>>>
>>>>> Hopefully someone else is familiar with the *gc_pnt2gc* function.
>>>>>
>>>>> Joe
>>>>>
>>>>> On Thu, Aug 10, 2017 at 8:12 AM, Dennis Shea <shea at ucar.edu> wrote:
>>>>>
>>>>>> Hi Joe,
>>>>>>
>>>>>> I have never used the '*gc_pnt2gc*' function. Hopefully, somebody
>>>>>> will address that function.
>>>>>>
>>>>>> There us an alternative:
>>>>>> https://www.ncl.ucar.edu/Document/Functions/Built-in/gc_latl
>>>>>> on.shtml
>>>>>>
>>>>>> Try the following interactively
>>>>>>
>>>>>> %> ncl <return>
>>>>>> Then enter the following
>>>>>>
>>>>>> p_lat = 41.6
>>>>>> p_lon = -76.84
>>>>>> lat = (/52.9921,55.3543/)
>>>>>> lon = (/-168.693,-160.346/)
>>>>>> dist = gc_latlon(p_lat,p_lon,lat,lon,10,2)
>>>>>> print(dist)
>>>>>>
>>>>>> Variable: dist
>>>>>> Type: float
>>>>>> Total Size: 8 bytes
>>>>>> 2 values
>>>>>> Number of Dimensions: 1
>>>>>> Dimensions and sizes: [2]
>>>>>> Coordinates:
>>>>>> Number Of Attributes: 4
>>>>>> units : degrees
>>>>>> gclon : <ARRAY of 20 elements>
>>>>>> gclat : <ARRAY of 20 elements>
>>>>>> spacing : ( 6.551194, 5.948726 )
>>>>>>
>>>>>> (0) 58.96074
>>>>>> (1) 53.53853
>>>>>>
>>>>>> ===
>>>>>> Cheers
>>>>>> D
>>>>>>
>>>>>>
>>>>>> On Wed, Aug 9, 2017 at 1:21 PM, Joe Grim <grim at ucar.edu> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have used the function gc_pnt2gc, but it doesn't appear to be
>>>>>>> doing what I think it should be doing. I assume this is because I am
>>>>>>> misunderstanding it. What I think it does is give the distance in degrees
>>>>>>> between a lat/lon point (p_lat, p_lon), and its closest approach to the
>>>>>>> great circle line between two other lat/lon pairs (lat[2], lon[2]: and I
>>>>>>> assume that this great circle line is the shortest greatest circle line
>>>>>>> between these lat/lon pairs.) Here is an example snippet of what I am
>>>>>>> trying to do:
>>>>>>>
>>>>>>> p_lat = 41.6
>>>>>>> p_lon = -76.84
>>>>>>> lat = (/52.9921,55.3543/)
>>>>>>> lon = (/-168.693,-160.346/)
>>>>>>> dist = gc_pnt2gc(p_lat,p_lon,lat,lon)
>>>>>>> print ("The distance is: " + dist)
>>>>>>>
>>>>>>> Here is the output:
>>>>>>> (0) The distance is: 0.105952
>>>>>>>
>>>>>>> I would expect the distance to be something around 53 degrees.
>>>>>>>
>>>>>>> Could someone please explain to me what I am misunderstanding about
>>>>>>> this function? And, do you know of another function that does what I am
>>>>>>> trying to do? (That is, find the shortest distance between a point and a
>>>>>>> line on the Earth.)
>>>>>>>
>>>>>>> Thank you!
>>>>>>>
>>>>>>> Joe Grim
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk at ucar.edu
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>
>>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170811/dedfe2c9/attachment.html
More information about the ncl-talk
mailing list